[java] Applets aren't working.

Started by
13 comments, last by Tac-Tics 22 years ago
Yeah, I clicked on it, but it doesn''t respond to any of my commands =-( Applets are a lot harder than apps.
Advertisement
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:

    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]
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
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.
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
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
MS IE 6.0
Maybe I didn''t try sending it to the applet. I thought I did. Oh well. As long as it works.

This topic is closed to new replies.

Advertisement