Montag, 8. Dezember 2008

Event dispatcher thread

EE3206/EE5805 java programming and Appications

Event dispatcher thread: notes on Liang(2009)

You need to write code in he event dispatch thread to avoid deadlock.


import javax.swing.*;

public class EventDispatcherThreadDemo
extends JApplet
{
// you need to write code in he event dispatch
// thread to avoid deadlock

public EventDispatcherThreadDemo()
{
add(new JLabel("Hi, it runs from an event dispatch thread"));
}

public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable() {
public void run()
{
JFrame frame =
new JFrame("EventDispatcherThreadDemo");
frame.add(new EventDispatcherThreadDemo());
frame.setSize(300,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

}); // anonymous inncer class
}
}




Keine Kommentare: