-
How to listen to JOptionPane's KeyEvents?
Hi all,
I have the following code :
import javax.swing.*;
import java.awt.event.*;
public class TestFrame implements KeyListener
{
public TestFrame()
{
JOptionPane Obj = new JOptionPane();
Obj.addKeyListener(this);
Obj.showMessageDialog(null,"Hello World","Test",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
public static void main(String[] args)
{
TestFrame testFrame = new TestFrame();
}
public final void keyPressed(KeyEvent e)
{
System.out.print("Hello World 2");
}
public final void keyTyped(KeyEvent e) {}
public final void keyReleased(KeyEvent e) {}
}
As you can see I'm trying to listen to the JOptionPane's keyevent, but when
I press any key it doesn't seem to respond as expected.
What's wrong with the code ?
Thanks in advance
Setya
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks