Last active
December 11, 2015 21:48
-
-
Save tacksoo/4665121 to your computer and use it in GitHub Desktop.
EDT Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
import javax.swing.SwingUtilities; | |
public class Unresponsive extends JFrame implements ActionListener{ | |
public Unresponsive() { | |
super("Unresponsive"); | |
JButton frame = new JButton("Unresponsive"); | |
frame.addActionListener(this); | |
add(frame); | |
pack(); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
} | |
@Override | |
public void actionPerformed(ActionEvent arg0) { | |
/* | |
try { | |
Thread.sleep(5000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
*/ | |
Thread t = new Thread(new Runnable() { | |
public void run() { | |
// do something that takes long here | |
SwingUtilities.invokeLater(new Runnable() { | |
@Override | |
public void run() { | |
// update GUI | |
} | |
}); | |
} | |
}); | |
t.start(); | |
} | |
public static void main(String[] args) { | |
/* | |
Unresponsive edt = new Unresponsive(); | |
edt.setVisible(true); | |
*/ | |
SwingUtilities.invokeLater(new Runnable() { | |
@Override | |
public void run() { | |
Unresponsive edt = new Unresponsive(); | |
edt.setVisible(true); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment