|
rotor posted:You won't be able to write to it, IIRC. http://forum.java.sun.com/thread.jspa?threadID=300557&start=45&tstart=-1 Someone developed a cute hack I use to modify the classpath at runtime for plugin reasons.
|
# ? Mar 4, 2008 08:49 |
|
|
# ? May 11, 2024 12:24 |
|
Alan Greenspan posted:http://forum.java.sun.com/thread.jspa?threadID=300557&start=45&tstart=-1
|
# ? Mar 4, 2008 17:41 |
|
Sweet and simple question about writing your own GUI controls. I have a custom control that prints "Help me COC " by extending JPanel and overwriting code:
When I directly write to g2 the zoomed text looks great. I used this code: code:
code:
Now zooming does not work anymore. I suspect it's because I write to an image in the second case and it's pixels are fixed once written. Any suggestions? Why are there differences between the Graphics context I get passed as the argument to the function and the one I create myself. What are these differences? Where should I draw to offscreen? How do I get a Graphics context that's equal to the one from the argument but doesn't directly write to the screen? Why is the zoomed text fine if directly written to the screen? Just what the hell is going on here, I appreciate any speculation.
|
# ? Mar 4, 2008 20:09 |
|
OK, I'm pretty sure this is what happens. 1. I write my stuff in my BufferedImage 2. I drawImage my BufferedImage to the Graphics context from the argument 3. The zoom kicks in and uses a method like Graphics2D::scale on the context 4. My drawn image pixelates because the scale method only sees the image and not the operations that created the image
|
# ? Mar 4, 2008 20:32 |
|
Alan Greenspan posted:OK, I'm pretty sure this is what happens. right. You have to draw a fresh image every time you zoom. One thing you can try is rendering the maximally zoomed-in image at start-up and rendering scaled-down versions of it as events warrant. There's really no free lunch when it comes to rendering high-quality zoomed-in text, you just shuffle the work around. rotor fucked around with this message at 21:44 on Mar 4, 2008 |
# ? Mar 4, 2008 21:13 |
|
Leehro posted:after a quick look at the features of JCreator Lite, I can point out a few things that NetBeans has that it doesn't:
|
# ? Mar 5, 2008 00:05 |
|
FuzzyBuddha posted:Ok, a bit late but... I want to thank you for this suggestion, if for no other reason than it tags errors as I type. I'm a horrible typer and this has already saved a lot of headache.
|
# ? Mar 5, 2008 00:20 |
|
FuzzyBuddha posted:Ok, a bit late but... I want to thank you for this suggestion, if for no other reason than it tags errors as I type. I'm a horrible typer and this has already saved a lot of headache. Yeah it's a nice set of tracks to keep you on the right path. zootm posted:Using "ctrl-space" you'll probably never have to type anything again. I didn't know about this, and the times when I wanted the autocomplete to kick in, I'd usually backspace over the ., type it again, and wait. Thanks!
|
# ? Mar 5, 2008 01:43 |
If I have an ArrayList of Objects, and I want to sort them by one of the fields (string) in the Object, how would I do that?
|
|
# ? Mar 5, 2008 04:29 |
|
If you can change your objects you can have them implement the Comparator interface. Now you can use the sort the function in java.util.Collections class.
|
# ? Mar 5, 2008 04:35 |
MEAT TREAT posted:If you can change your objects you can have them implement the Comparator interface. Now you can use the sort the function in java.util.Collections class. Ok cool, that led me to this code:
fletcher fucked around with this message at 04:49 on Mar 5, 2008 |
|
# ? Mar 5, 2008 04:46 |
|
compare should return an int, not a String. Try: code:
|
# ? Mar 5, 2008 04:52 |
Hah well I feel like an rear end. Thank you! Works great now.
|
|
# ? Mar 5, 2008 04:56 |
|
fletcher posted:Ok cool, that led me to this What type is name in the Product class? If it's a String already, you don't need those casts to String. It's only a minor issue, but every time I see stuff like that at work I die a little. Along these lines, is all programming in a corporate environment completely soul crushing, or is there hope?
|
# ? Mar 5, 2008 11:43 |
|
triplekungfu posted:What type is name in the Product class? If it's a String already, you don't need those casts to String. It's only a minor issue, but every time I see stuff like that at work I die a little. String is final, so name is either a String or an Object (or CharSequence or Comparable<String>(!)). Brain Candy fucked around with this message at 12:56 on Mar 5, 2008 |
# ? Mar 5, 2008 12:42 |
triplekungfu posted:What type is name in the Product class? If it's a String already, you don't need those casts to String. It's only a minor issue, but every time I see stuff like that at work I die a little. Thanks for the tip. Normally I'd try it both ways, but not when I needed to get that code checked in ASAP. I was just copying the example code from the link up above. fletcher fucked around with this message at 15:21 on Mar 5, 2008 |
|
# ? Mar 5, 2008 15:19 |
|
Ugh, I feel like a retard asking this here, as it seems like a question for Google, but either this is more complicated than I expected or Google's just being stupid. I've got an assignment to write a simple paint program using a Swing panel, where you left-click and drag to paint and right-click and drag to erase. I got the left-click just fine with a MouseDragged event, but now I can't figure out how to do something different for a right-button drag. Once I figure out how to check for the right button in the first place, I should be able to throw some if statements around stuff and get the rest on my own. Any advice? EDIT: Never mind, got it! Was busy messing with some bitwise crap I found on this page, when right above that was an easy set of boolean methods to use. http://www.leepoint.net/notes-java/GUI-lowlevel/mouse/20mousebuttons.html GameCube fucked around with this message at 02:27 on Mar 6, 2008 |
# ? Mar 6, 2008 01:59 |
|
I'd like to Parse an HTML-formatted String (so I can get tables at a certain width, columns either justified or centered, other simple stuff). Once this data is "rendered" I need to pop it back into a plain String (still formatted using absolute spaces and cr/lf) to feed it to a receipt printer. Am I crazy? I have to make a bunch of these receipts, and they have to dynamically adjust their width based on the printer model. The end result would be exactly like what you get if you rendered the HTML in a browser, then copied and pasted it into a non-HTML aware application. So, is this going to be possible with the Java standard library? I'm using javax.swing.text.html.HTMLDocument right this second. Any other ideas ?
|
# ? Mar 9, 2008 00:22 |
|
roadhead posted:I'd like to Parse an HTML-formatted String (so I can get tables at a certain width, columns either justified or centered, other simple stuff). If I understand you correctly (never a safe bet) it seems that html has nothing do do with this. You have some string data you want formatted nicely on fixed-width font printers, and you're trying to abuse an html layout engine to do this. My advice would be to look around for something like a java curses library or just write your own - formatters like this are pretty common homework for programming classes, so I'd be surprised if you can't find some kind of libraries floating around.
|
# ? Mar 9, 2008 01:39 |
|
rotor posted:If I understand you correctly (never a safe bet) it seems that html has nothing do do with this. You have some string data you want formatted nicely on fixed-width font printers, and you're trying to abuse an html layout engine to do this. There is a mature Java curses lib, and it's pretty awesome. A guy at work popped out a tabular pgsql database stats browser with it in a day. I'm curious why roadheads' implementation has to be in java and not something like LaTeX or PS. Those languages are made for type-setting.
|
# ? Mar 9, 2008 05:10 |
|
TRex EaterofCars posted:There is a mature Java curses lib, and it's pretty awesome. A guy at work popped out a tabular pgsql database stats browser with it in a day. It has to be in Java because thats what we use, the whole project is in Java. Seven years in the making, the end-all be-all of hardware store software. AP, AR, GL, PoS, Inventory, Payroll etc. I'm just one person out of many, and this is what I've been stuck with lately Some of the foundation for this area has already been laid and a single "receipt" template completed, but the formatting was all in lots and lots of lines of actual Java code, no template being stored in the database at all. I was hoping to write something that would lay out my template, put it to a formatted string, with several "replaceable" variables for the content that is transmitted from the PoS terminal. That part is already in place in our String utilities, so I don't have to worry about that, just the layout part Since a customer could have any model of printer, the width of the form is defined run-time, which is why I wanted to use HTML and set the width of the table with a resolvable variable. Does this explain it better at all ?
|
# ? Mar 9, 2008 17:31 |
|
roadhead posted:Since a customer could have any model of printer, the width of the form is defined run-time, which is why I wanted to use HTML and set the width of the table with a resolvable variable. yeah. You'll kill yourself trying to make the html layout engine do this properly. Dig up a java curses library, it shouldn't be too hard. Unless your input is HTML ... in which case my advice would be to strip out the html and then find a java curses library. I just don't see how you're going to take an html renderer and get it to spit out fixed-width font layouts in any kind of reasonable way. This is what console-based apps are really good at, so I'd go back and look at the display libraries for those - i.e. curses.
|
# ? Mar 9, 2008 22:45 |
|
I'm writing a program (yes, homework for intro CS) that plays a quick card game between two computer players and then returns who won (player 1 or 2, it's a random game of luck so theoretically I should be able to run it 1000000 times and see 50/50 winning percentages). I believe my code is correct, and I can run it as many times as I want with no exceptions if I actually run it repeatedly by hand -- but if I insert a for loop to get it to run multiple trials, I invariably end up with an array index out of bounds exception. I'm really confused by this because all of the variables (arrays of cards, stuff like that) are declared either in the for loop or the method called from within the for loop. What kinds of things should I be looking for? What could cause the program to screw up when run multiple times within itself, when I can run it so many times from outside with no incidents, so to speak?
|
# ? Mar 10, 2008 06:49 |
|
Emo.fm posted:I'm writing a program (yes, homework for intro CS) that plays a quick card game between two computer players and then returns who won (player 1 or 2, it's a random game of luck so theoretically I should be able to run it 1000000 times and see 50/50 winning percentages). I believe my code is correct, and I can run it as many times as I want with no exceptions if I actually run it repeatedly by hand -- but if I insert a for loop to get it to run multiple trials, I invariably end up with an array index out of bounds exception. I'm really confused by this because all of the variables (arrays of cards, stuff like that) are declared either in the for loop or the method called from within the for loop. What kinds of things should I be looking for? What could cause the program to screw up when run multiple times within itself, when I can run it so many times from outside with no incidents, so to speak? Off the top of my head, make sure you realize that Java (and C and its derivatives) arrays are 0-based, and an array of N elements has valid indices from 0 to N-1 inclusive (and index N will cause an exception). It has nothing to do with your for loop, which I assume is just counting runs and isn't actually doing anything in the body of the loop, except that running it 1 million times makes it more likely that a bug based on random input (and presumably there's random input somewhere in your program) will manifest itself. It may be worth posting your code, or at least posting the exception message.
|
# ? Mar 10, 2008 07:33 |
|
I agree with posting your code. Your problem doesn't make much sense, it should work.
|
# ? Mar 10, 2008 09:10 |
|
MEAT TREAT posted:I agree with posting your code. Your problem doesn't make much sense, it should work.
|
# ? Mar 10, 2008 09:16 |
|
Yeah, either your variables aren't getting reset -or- you're not getting the random number range right. If you have a debugger, you can find this easily.
|
# ? Mar 10, 2008 23:01 |
|
dizzywhip fucked around with this message at 20:16 on Nov 9, 2020 |
# ? Mar 11, 2008 01:36 |
|
You need to create the array first, then initialise its elements:code:
|
# ? Mar 11, 2008 01:41 |
|
dizzywhip fucked around with this message at 20:17 on Nov 9, 2020 |
# ? Mar 11, 2008 01:42 |
|
This is kind of an odd question because it's about my approach and not a bug in the code. I'm trying to do different projects to learn Java and C, and one of my Java projects was to build a very simple fighting RPG from the ground up as I learn. So tonight I was messing around with getting it to let the player choose which class to play and then shows them the stats when they pick. My question is, how terrible did I go about this? I don't want to get in the habit of a bad approach to different problems. code:
code:
|
# ? Mar 11, 2008 03:22 |
|
Well your approach isn't very OO yet. I'll try to critique your Player class first. You are limiting yourself by defining the 2 playerclasses. A much more robust constructor would be this. code:
Your method updateStats should be changed to override the toString method since you are not actually updating any of the stats. I think the only method that is missing from the Player class is a combat method where he can do damage to another Player. I'll let someone else comment on your GameLoop class because I have to run.
|
# ? Mar 11, 2008 04:04 |
|
MEAT TREAT posted:Well your approach isn't very OO yet. I'll try to critique your Player class first. Thanks for the advice, the bit about making a more robust Player object is very helpful. I spent a long time thinking about how to set that up and this clears it up for me This short program was a quick attempt at displaying some information based on user selection using a setup kind of like I would if I was making the actual game. I will be making the game at some point as a larger project, but at the moment I'm just making random pieces to have something to do.
|
# ? Mar 11, 2008 04:11 |
|
Any suggestions for online Java tutorials for a beginning programmer? I've got a good book but a friend of mine who is on deployment in Afganistan would like to try learning Java along with me but he can't exactly go to Barnes & Nobles. Honestly looking through Java tutorials with google I'm not finding anything that equates to 'Java for Dummies' which is probably what he wants.
|
# ? Mar 11, 2008 09:47 |
|
There is Bruce Eckel's Thinking in Java which is available online for free. I've been reading his C++ book and I like it very much. I can't think of any Java tutorials, but frankly you should stay away from them. Tutorials rarely cover any subject in depth so there usefulness is limited.
|
# ? Mar 11, 2008 12:05 |
|
MEAT TREAT posted:There is Bruce Eckel's Thinking in Java which is available online for free. I've been reading his C++ book and I like it very much. I can't think of any Java tutorials, but frankly you should stay away from them. Tutorials rarely cover any subject in depth so there usefulness is limited. That's the book I use and I'm really pleased with it for being free of charge and all.
|
# ? Mar 11, 2008 19:03 |
|
I have an issue with request.getParameter when I am trying to pass in a url encoded parameter. getParameter always assumes that I want the data decoded, but is there any way to get the parameter if I don't want the parameter decoded, rather I would like to decode it myself later? What I have done right now is user getQueryString and parse out the particular parameter I want, but I'd like to know if there is a less hacky way to do this. The particular issue is that I am passing in a path, but sometimes the path may contain the %2F character, which is the \ character, ruining the path. Anyone know?
|
# ? Mar 11, 2008 19:50 |
|
fret logic posted:Thanks for the advice, the bit about making a more robust Player object is very helpful. I spent a long time thinking about how to set that up and this clears it up for me Depending on your game and what it will support in the future, I'd say that Player should be an abstract class and that you should subclass it with a Fighter and an Archer class. The reason (which may not be valid in your case) is that, for instance, you'll want to give all archers a bonus for ranged weapons or restrict so that fighters can't used crossbows (whatever). If you stick to using conditional statements (if, switch) then you will quickly get a headache trying to code all these rules that will be easily avoided if you just go with the subclassing. Also, the constructor for each class will be very simple and you can still keep the toString() method (which you should use) in the abstract Player class. Adding more types of Player will be ridiculously easy too. If you go that route, keep in mind that you need to change all attributes in Player to "protected" for subclasses to access them.
|
# ? Mar 11, 2008 20:10 |
|
ynef posted:Depending on your game and what it will support in the future, I'd say that Player should be an abstract class and that you should subclass it with a Fighter and an Archer class. The reason (which may not be valid in your case) is that, for instance, you'll want to give all archers a bonus for ranged weapons or restrict so that fighters can't used crossbows (whatever). If you stick to using conditional statements (if, switch) then you will quickly get a headache trying to code all these rules that will be easily avoided if you just go with the subclassing. Also, the constructor for each class will be very simple and you can still keep the toString() method (which you should use) in the abstract Player class. Adding more types of Player will be ridiculously easy too. That does make sense but I'm a little ashamed to say I had to look up how to create a subclass, since I haven't learned it yet. Thanks for the help!
|
# ? Mar 11, 2008 20:14 |
|
|
# ? May 11, 2024 12:24 |
|
ynef posted:Depending on your game and what it will support in the future, I'd say that Player should be an abstract class and that you should subclass it with a Fighter and an Archer class. The reason (which may not be valid in your case) is that, for instance, you'll want to give all archers a bonus for ranged weapons or restrict so that fighters can't used crossbows (whatever). If you stick to using conditional statements (if, switch) then you will quickly get a headache trying to code all these rules that will be easily avoided if you just go with the subclassing. Also, the constructor for each class will be very simple and you can still keep the toString() method (which you should use) in the abstract Player class. Adding more types of Player will be ridiculously easy too. Simple parameterization is a good start. One of the pitfalls of using inheritance with this is if you try something like races and classes for dwarven warriors or elven wizards, you end up with DwarfWarrior, ElfWarrior, DwarfWizard and ElfWizard. All this effort writing out almost-identical code makes programming with Java seem staggeringly inefficient. It's even worse if you're doing player-controlled versions and computer-controlled versions. Lots of people do that and then think that inheritance is only useful in a few cases when nothing could be further from the truth. You'll often hear the terms is-a and has-a with classes and inheritance. A Wizard is-a Player or an Archer is-a Player, or a WizardArcher is-a Wizard and is-a Archer (and by extent is-a Player). Inheritance describes is-a relationships. On the other hand, a player has-a equippedWeapon or has-a wornArmor. Fields in a class describe has-a relationships. However, we can also say that a Player has-a Job and has-a Race, and a Wizard is-a Job, Warrior is-a Job, and Elf is-a Race and Dwarf is-a Race. The two can even be simply concrete instances of one parent class using parameters if there's nothing majorly different between the two. code:
|
# ? Mar 11, 2008 21:21 |