/home/wpollock1/public_html/AJava/Oops.java
// This code show an "Oops!" moment---sleeping on the Event Dispatch
// Thread. Clicking the "Click me!" button will freeze the GUI for
// 10 seconds. The events are still queued by the JVM but the EDT is
// stuck waiting before it can process them.
//
// Written 3/2011 by Wayne Pollock
import java.awt.*;
import java.awt.event.*;
public class Oops {
public static void main ( String [] args ) {
Frame f = new Frame("Opps!");
f.setSize(250, 150);
Panel p;
Button badBtn = new Button("Click me!");
p = new Panel();
p.add( badBtn );
f.add( p, "North" );
badBtn.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent evt ) {
try { Thread.sleep( 10000 ); }
catch ( InterruptedException ie ) {}
}
});
Button exitBtn = new Button( "Exit" );
p = new Panel();
p.add( exitBtn );
f.add( p, "South" );
exitBtn.addActionListener( new ActionListener(){
@Override public void actionPerformed( ActionEvent evt ) {
System.exit(0);
}
});
f.addWindowListener( new WindowAdapter() {
@Override public void windowClosing ( WindowEvent evt ) {
System.exit(0);
}
});
f.setVisible( true );
}
}