How would I go about programming an applet so that one could hit the arrow keys on the keyboard to make my arc (which is actually half a circle) move around on the applet screen?
You would add a KeyListener, which reacts to the keys you're interested in, then redraws the graphics as appropriate and calls repaint/update.
Since this has nothing to do with applets specifcially, I'm moving the thread to the AWT/Swing/GUI forum. [ April 15, 2006: Message edited by: Ulf Dittmer ]
I'm new to this part of building an applet in java. Can somebody give me a reference or something that I could work with to figure it out? I'v never used a key refference before.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35443
9
posted
0
Event handling is discussed in a chapter of the Swing GUI tutorial. Even if you use AWT, not Swing, as your graphics library, the event handling of both is identical.
Martin vanPutten
Ranch Hand
Joined: Mar 26, 2006
Posts: 124
posted
0
Heres my code:
I'm stuck here at trying to figure out how to give the first arc controls. Can somebody help me?
1) KeyPressed() is not keyListeners's keyPressed() 2) all the values in paint() are hard-coded i.e. there will be no 'movement'
here's a (very) simple applet, when run a 'ball' will move from left to right. use the arrow keys to change direction
and the html to run it
Martin vanPutten
Ranch Hand
Joined: Mar 26, 2006
Posts: 124
posted
0
Thanks! I can use this to figure mine out. Thank u so much!!
Martin vanPutten
Ranch Hand
Joined: Mar 26, 2006
Posts: 124
posted
0
Ok... maybe I can't. I got this far:
I commented all the unneccesary stuff away for now so that I can focus on the one arc. When I push a button (actually any button) on the keyboard, it looks like lines are going through the applet and its trying to do something but I'm not specific enough in my code to have it doing what I want it to do. For now... all I want is to move the arc left. If you want to view it the html code is:
What else do I have to do? Whats wrong with my applet?
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
here's your applet with a few comments
and here it is with a few amendments (will only work with the left arrow)
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.