Archived

This topic is now archived and is closed to further replies.

Java applet woes

This topic is 5521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

After some extensive debugging I've finally isolated a serious bug, but I don't understand it. I'd be very grateful if someone could tell me what's wrong with this code.
import java.applet.Applet;
import java.awt.Label;
import java.awt.event.*;

public class MyTest extends Applet
{
	private Label myLabel;

	public void init()
	{
		myLabel = new Label ("test");
		add (myLabel);

		addKeyListener (new KeyboardHandler());
	}

	private class KeyboardHandler extends KeyAdapter
	{
		public void keyPressed (KeyEvent event)
		{
			myLabel.setText ("key pressed");
		}
	}
}
  
The label doesn't change when pressing a key, but I get an exception when closing. Exception occured during event dispatching: java.lang.IllegalStateException: Can't dispose InputContext while it's active ___________________ Aim for the horizon but watch your step [edited by - EasyRaider on November 6, 2002 3:42:36 PM]

Share this post


Link to post
Share on other sites
The Label is hogging the input so that the Applet doesn''t receive the key events. Try adding the key listener to the label, or reworking the design so that the key events end up where they are supposed to be.

Share this post


Link to post
Share on other sites