Posted: Wed Oct 05, 2005 4:29 pm Post subject: Graphics Movement?
I was trying to make an applet with graphics, and I know how to draw things, but how do I do movement? You can draw various things, but how do I make it update the screen multiple times? Here is what I was trying so far:
Java:
import java.awt.*; import java.applet.Applet;
publicclass AppletGraphics6 extendsApplet { int i = 1;
publicvoid paint(Graphics g) {
g.drawLine(1, 1, i, i);
i += 1;
paint (g);
delay (500);
}
Posted: Wed Oct 05, 2005 5:38 pm Post subject: (No subject)
Indeed it does! Thanks wtd .
Anyone know where I can find a way to do this for an application?
*edit*
I am trying to set the colour of a drawn object throuhg g.setColor(), like so:
code:
g.setColor(white);
and I get a compile time error message - "cannot find symbol variable white". This happens for any colour I use.
Hikaru79
Posted: Wed Oct 05, 2005 10:21 pm Post subject: (No subject)
[Gandalf] wrote:
*edit*
I am trying to set the colour of a drawn object throuhg g.setColor(), like so:
code:
g.setColor(white);
and I get a compile time error message - "cannot find symbol variable white". This happens for any colour I use.
Well, what is white? It hasn't been defined, right? It's actually a static field of the Color class. So, try g.setColor(Color.white); . Should work ^_^ (You may need to import java.awt.Color if you haven't already)
wtd
Posted: Wed Oct 05, 2005 10:51 pm Post subject: (No subject)
Hikaru79 wrote:
[Gandalf] wrote:
*edit*
I am trying to set the colour of a drawn object throuhg g.setColor(), like so:
code:
g.setColor(white);
and I get a compile time error message - "cannot find symbol variable white". This happens for any colour I use.
Well, what is white? It hasn't been defined, right? It's actually a static field of the Color class. So, try g.setColor(Color.white); . Should work ^_^ (You may need to import java.awt.Color if you haven't already)
Could work if you use:
Java:
import static java.awt.Color.*;
[Gandalf]
Posted: Thu Oct 06, 2005 5:10 pm Post subject: (No subject)
I thought I tried that, but I guess I didn't since it worked...
I don't need to import those since I already have import java.awt.*.
rizzix
Posted: Thu Oct 06, 2005 10:20 pm Post subject: (No subject)
i advise against using static imports.. use it when absoloutly necessary... like when porting C API's to JAVA..
[Gandalf]
Posted: Fri Oct 07, 2005 9:29 pm Post subject: (No subject)
The ball will neither move nor appear in the proper spot... The start location should be what is passed to the constructor, and the ball should move according to move(). It works, but doesn't work properly .
Java:
import javax.swing.*; import java.awt.*;
class Ball
{ privateint x, y;
public Ball(int xStart, int yStart) {
x = xStart;
y = yStart;
}
I must have these lines. Yes, I have imported java.awt.* but that does not include all packages within that package. So if you're importing java.awt.* you're not importing Color's white member. You're including Color, but not importing it, you have to reference it. I hope that makes sense
[Gandalf]
Posted: Fri Oct 07, 2005 10:18 pm Post subject: (No subject)
Alright, but that's what the Color.<colour> is for, right? Since each colour is static...
How about my current program?
Aziz
Posted: Fri Oct 07, 2005 10:36 pm Post subject: (No subject)
Right. So you can use 'Color.white', but not just 'white'
wtd
Posted: Fri Oct 07, 2005 10:37 pm Post subject: (No subject)
Aziz wrote:
Right. So you can use 'Color.white', but not just 'white'
Unless you're using 1.5.x or greater and use a static import.
rizzix
Posted: Fri Oct 07, 2005 11:03 pm Post subject: (No subject)
once again refrain from doing that
wtd
Posted: Fri Oct 07, 2005 11:05 pm Post subject: (No subject)
Well, first off... it's good to understand things, even if understanding them leads you to avoid them (sometimes especially in those cases).
Second... why? What's so wrong with using static imports?
rizzix
Posted: Sat Oct 08, 2005 12:03 am Post subject: (No subject)
its counter-java way of getting things done. In java everything is part of an instance of a class or part of the class it self.. (with the only exception being primitives).. that's the philosophy!.. and refrain from code that will eventually result in YOU trying to figure out where those constants were once defined (maybe some time in the future..). this is especially troublesome when you have "more than one" of those static imports.
After all "Color.white" is a lot more meaningful than "white" alone.