|
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 |
|
|
# ¿ Apr 27, 2024 06:27 |
|
Row 16 in the file that the JVM complains about says: "Graphics2D g = (Graphics2D) drawSpace.getGraphics();" -- at that point, however, drawSpace is not initialized to anything and is therefore null.
|
# ¿ Apr 20, 2008 18:41 |
|
fletcher posted:I'm looking to implement some charts on a Java web application. Right now I'm reading about JFreeChart. What are some others worth looking into? I'd prefer to go down either the static images route or possibly flash based for some user interaction, no applet type stuff. Tow questions: what kind of charts, and can you run other programs on your server as well? Such as, for instance, gnuplot? Just asking. Also, since it's web, I'm guessing you want to output at least PNG or something (perhaps have support for PDF and PostScript as well)? More specs, please.
|
# ¿ Apr 26, 2008 17:35 |
|
PianoDragn posted:* IMPORTANT: Performance is very important, please make the method efficient * Read up on VolatileImage, it is supposedly faster and stored in video RAM (according to this). Perhaps that could speed things up for you?
|
# ¿ Apr 26, 2008 18:31 |
|
Emo.fm posted:What's the deal with loading images from the web to display in applets? I'm following the directions from this site, but whenever I try to compile, I'm told that the method "getImage()" doesn't exist. You answered your own question, there. Your code attempts to call a method called getImage() in your small class that is used in the Applet class. If you haven't written a method like that, then it is not going to work. Call the Applet class' getImage() method instead.
|
# ¿ May 8, 2008 21:55 |
|
Emo.fm posted:PS - If what you meant was to call Image myImage = MyApplet.getImage("url"); that doesn't seem to work either. No, that doesn't work because getImage() is not a static method. Do you have a reference to an object of MyApplet? If so, you should be able to call the method that way. Either way, I think you should review your textbook again concerning references and method calls.
|
# ¿ May 10, 2008 15:04 |
|
shodanjr_gr posted:If i go to the command prompt and do a "foo.jpg", the image will open in the default program that ive selected to handle that kind of file. I dont have to use the filename as an argument while running the program...(which seems pretty reasonable, since it would make any sort of search application impossible to develop - which is what i am making). At least in previous versions of Windows, you had the "start" command. I don't run Windows, so I wouldn't be able to check if this is still the case. "start filename.something" would be equivalent to double clicking the file in Explorer. This works (worked?) for folders also. So, all you'd have to do is find out the file name and send that as the argument to "start", and you're done. My guess would be that "filename.something" is simply interpreted as "start filename.something" by the cmd shell. Why is something this Windows-centric developed in Java, though?
|
# ¿ Jun 1, 2008 17:26 |
|
drunkill posted:
This code shouldn't compile. You're missing data types in front of your variables, and you also have a problem with missing + signs in that last System.out.println() row. You need to put it between things that should be glued together (concatenated would be the correct term) to form a new string. The thing about data types as someone mentioned, think of them in database terms since you're comfortable with databases. You wouldn't declare that a column should include integer numbers if you're going to store names in there in a database. Same thing with Java -- figure out the correct type, then store data in there. Good luck, you'll do this stuff easily within a matter of days!
|
# ¿ Aug 9, 2008 07:07 |
|
Startacus posted:Edit: Another thing, is there a good way to write nodes to files, like from a binary tree? The topic you want to Google for is called Serialization. Preferably, serialization to XML. Like someone else said, this sounds like homework, so I'm just going to point you in the right direction.
|
# ¿ Oct 21, 2008 16:20 |
|
Sarah Sherman posted:I'm playing around and messing with some programming homework and I'm getting a little stumped on this. This program basically uses a linked list and lets the user write a polynomial, input a number to be evaluated, and then returns the answer. So far I have all the math working, except I can't figure out a solution to print out the user's polynomial. Here is my code: You will be really annoyed when you find out the answer. From where are you getting the values you are printing?
|
# ¿ Oct 31, 2008 08:15 |
|
Jmcrofts posted:I'm really new to Java, and am learning it for a CS class. I installed the Java SDK on my home computer, and whenever I try to run my compiled code through the command prompt I get an error message that says What you're probably doing is that you type "java MyClass.class", when you should type "java MyClass" (without the ".class" suffix). This of course assumes that you follow your tutorial precisely and have a method like "public static void main(String[] args)", which you may consider the "entry point" of a program.
|
# ¿ Jan 22, 2009 22:06 |
|
Excellent post, 1337JiveTurkey! It should also be noted that there is a nasty consequence to letting just this one thread handle all the events in Swing: if your event handling includes a lengthy operation (say, getting a file from a network location or calculating something that takes a while), that means that you have effectively prohibited the GUI from being responsive during that time. To avoid this problem, you must perform lengthy tasks in the background using another thread. Thankfully, there is a class for making this easy, called SwingWorker. Read up on Concurrency in Swing, and really get comfortable with the concepts presented there. Obeying the rules there is crucial to making usable programs.
|
# ¿ Feb 7, 2009 16:35 |
|
Lord Wexia posted:So my question is, how should I think about this double quote character and can my space-character oriented method still work? Or am I going to have to re-write this? I'm going to assume that you have to do all this stuff on your own and not just rely on some smart other tool or library. Your space-based approach may be rewritten to handle this case as well. There are at least two solutions. One which is more simple but specific to your current problem, and one which is more general. A really simple, but hard to modify and adapt solution would be as follows: simply keep track of whether you are within quotes or not using a Boolean variable. If you are, then all characters you read (until you encounter the closing "-character) should be appended to your current partial result. If you are not within quotes, then continue like you have before with your space-based parser. A nicer approach would look as follows in pseudo code. code:
If you would implement the second solution, you obviously need to perform more error checking and stuff. In particular, you might want to throw the empty string away. ynef fucked around with this message at 18:15 on Feb 11, 2009 |
# ¿ Feb 11, 2009 18:10 |
|
Captain Pike posted:I am very new to Java, and I am attempting to compile a project found on Source Forge:https://sourceforge.net/projects/opensmus/ Absolutely. Check out Maven. [edit] Maven requires that there is a Maven-specific file, but serious projects use it. If this one doesn't, suggest it! ynef fucked around with this message at 07:38 on Feb 19, 2009 |
# ¿ Feb 19, 2009 07:35 |
|
Flamadiddle posted:So I'm trying to make a bouncing ball simulator. I've managed to make a model but want to represent it graphically. So far I've got the model in one class and the GUI in another. Couple of questions: This approach can work. There are alternatives, but let's first study the one you have. In your current approach, you would have one thread that runs the model, and then you'd have another that manages the GUI. When the GUI thread decides it needs to redraw the scene, it should query the position of the ball from your ball model object (create the ball model object first, then feed the GUI object with a reference to it). However, since you have two threads working with the same data (the position of the ball), you should make sure that your inter-thread concurrency is handled well. Read up on thread concurrency in general, and on the "synchronized" keyword especially. Another approach is to have only one thread, the GUI thread. The pseudo code for it would be: code:
Since you already have a working ball simulator, I would suggest that you stick with the first approach, the second one being only for future reference. The more easily you can make use of several threads these days, the better. [edit] If you want to study this topic further, the phrase to search for is "game loop". ynef fucked around with this message at 06:25 on Apr 14, 2009 |
# ¿ Apr 14, 2009 06:14 |
|
StickFigs posted:The only problem is I still don't understand the for-each loop, I found this page which explains it but I still don't understand exactly what is going on, especially where it says the first example should be read as “for each TimerTask t in c.” Say that you have some collection of values: a list, an array, a hash set... any collection (that implements the interface Iterable<T>). It is very common to iterate over every element in this collection and do something with each element. Previously, we had to write code like this: code:
code:
So now we have a new type of for-loop that does just what we want: it allows us to write code that looks the same no matter which underlying data structure is used, because it solves the same basic problem. It basically says: iterate over the entire collection, and give me a reference to the current element so I can do something with it. It looks as follows: code:
|
# ¿ Apr 18, 2009 06:51 |
|
fge posted:I'm having problems with servlets in Ubuntu. I'm trying to add the servlet-api.jar file from Tomcat to Java, so I added this line: 1. You need to write "export" first on that line. 2. That folder name is wrong: your desktop is at "/home/yourUserName/Desktop/". 3. And you don't want to replace your classpath like that (you should probably just append to it, like so: export CLASSPATH="$CLASSPATH:/more/stuff/here:/even/more/stuff"). Also, don't put stuff like this in /etc/environment. Put it in your ~/.bashrc, or make a script that exports such variables for you that you run as a setup before running javac/java.
|
# ¿ Apr 20, 2009 20:09 |
|
UR MR GAY posted:I'm using the scanner class with a line separator as the delimiter to parse an obj file. The scanner won't detect any line separators until i manually open the file in WordPad and add just one. So my question is, how can I circumvent that? Can you explain what you are trying to do (there may be a better way) and also posting a sample OBJ file that you are working with? A possible cause of the problem could be related to Windows and UNIX treating line separators differently, but I think Scanner is smart enough to handle such things on its own.
|
# ¿ Apr 20, 2009 20:12 |
|
Before learning Swing, it might be good for you to learn more about multithreaded (programs that do more than one thing at a time) programming. Not only is it really cool stuff, but you have to know it to make Swing programs. No exception, you need to know threads to do GUI programming.
|
# ¿ May 13, 2009 17:49 |
|
almostkorean posted:Yes, but I'm getting the same issue if I'm trying to run something that's not in a package You have to be at the top level directory, and then specify the Java class you want to run with the whole package information preserved. An example: Say you have the following directory structure for your project: code:
|
# ¿ Jun 9, 2009 17:48 |
|
FateFree posted:In math terms, how do I find the smallest power of 2 thats greater than a given number, in fast java code? In math, you'd probably get away with ceil(log2(given_number)), but Java doesn't have a general logarithm function like that (just the natural logarithm). You'd have to use the Change of Base theorem to compensate.
|
# ¿ Nov 24, 2009 18:17 |
|
Flamadiddle posted:Okay, I have no idea what's going on but I'm all of a sudden having real difficulty with packages and classpaths under Windows 7.
|
# ¿ Dec 9, 2009 19:31 |
|
Kaltag posted:Whats the best way to make java do something every 3 hours then do nothing in between?
|
# ¿ Apr 5, 2010 14:11 |
|
Aleksei Vasiliev posted:Yeah, either save every line of what your client is POSTing and what is returned, or somehow run a packet logger. tcpmon is quite good for this. You start it up, tell it to act as a proxy, it prints out both request and response. Simple and just what is most likely needed here.
|
# ¿ May 24, 2010 06:20 |
|
GravyWPG posted:I ask the teachers about it and they tell me to install version 6. I do that, reinstall Greenfoot, reboot, and it STILL DOESN'T loving WORK. I'm missing assignments because of this loving poo poo. Choose the stand-alone version here: http://www.greenfoot.org/download Once that is done, try to fix things so you have your "real" Java environment up and running, but just take the packaged version first.
|
# ¿ Oct 5, 2011 15:14 |
|
Hot Yellow KoolAid posted:I'm having a problem with an intro java GUI assignment. I'm supposed to implement a mock radar display (similar to marine sonar) with a sweeping arm that spins every second. (The display shows other things, but I think I have those objects figured out). My attempts to implement the sweeping arm have been based off taking the java code for an analog clock's second hand and making it move 60X faster. Are the planes supposed to move as well? Post a link to the actual assignment, please. Hot Yellow KoolAid posted:Also, I need to implement grid lines in this somehow. Is there any way to draw lines using Graphics2D? I'm pretty sure I could solve this problem just by drawing some really slim rectangles.
|
# ¿ Jan 26, 2013 12:33 |
|
|
# ¿ Apr 27, 2024 06:27 |
|
404notfound posted:One more thing you can do to clean up the code. I'm assuming you fixed the code by asking for input both before the while loop and also within the loop at the end. While this works, duplicating code is generally frowned upon.
|
# ¿ Sep 10, 2013 13:55 |