日期:2014-05-20 浏览次数:20627 次
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class TestVisible extends JFrame {
private JButton btn;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
TestVisible thisClass = new TestVisible();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public TestVisible() {
super();
this.setSize(300,200);
JPanel panel = new JPanel();
panel.setLayout(null);
btn = new JButton("haha");
btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
btn.setVisible(false);
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
btn.setBounds(30, 30, 80, 30);
panel.add(btn);
this.setContentPane(panel);
}
}
btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
btn.setVisible(false);
try {
SwingUtilities.invokeAndWait(new Thread() {
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});