[java] Applets aren't working.
Yeah, I clicked on it, but it doesn''t respond to any of my commands =-( Applets are a lot harder than apps.
The problem is that the applet keeps steals the focus. Your JPanel will never have it. Try the addKeyListener into the applet, but still have the JPanel do the listening. Like this:
This way the events from the applet will be listened to, but the processing will take place in the panel, where you want it.
---
Make it work.
Make it fast.
"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
[edited by - CaptainJester on March 29, 2002 3:45:59 PM]
public class Box extends JApplet implements Runnable,KeyListener { private Thread appThread; Shape[] shape; private boolean running; private DPanel panel; public void init () { appThread = new Thread(this); shape = new Shape[5]; shape[0] = new Rectangle2D.Float(2, 2, 10, 15); running = false; panel = new DPanel(this); addKeyListener(panel); //<== change here appThread.start(); }
This way the events from the applet will be listened to, but the processing will take place in the panel, where you want it.
---
Make it work.
Make it fast.
"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
[edited by - CaptainJester on March 29, 2002 3:45:59 PM]
I think I tried that before but it still didn''t work.
No worries though, I found a way (but I dunno how efficient it really is... but as long as it works). In my game loop, I call "request focus" on the game panel once every cycle. If you know of any more efficient ways, I''d like to hear them tho.
No worries though, I found a way (but I dunno how efficient it really is... but as long as it works). In my game loop, I call "request focus" on the game panel once every cycle. If you know of any more efficient ways, I''d like to hear them tho.
When I took your code and compiled it, I had the problem in Appletviewer. No keyboard events were being captured. As soon as I changed the sender of the events to the JApplet, it worked. What browser and version do you use?
---
Make it work.
Make it fast.
"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
---
Make it work.
Make it fast.
"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement