日期:2014-05-20 浏览次数:20806 次
public class M3 { public void Time1(Object obj) { int i = 0; while (true) { if (i == 5) break; if (obj instanceof AAA) { AAA a = (AAA) obj; a.label.setText("this is " + i); a.setTitle("this is " + i); System.out.println("this is " + i); try { Thread.sleep(5000); } catch (Exception ex) { System.out.println(ex.toString()); } } i++; } } } import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; public class AAA extends JDialog{ JLabel label; JButton b; public AAA() { setBounds(100, 100, 400, 130); Container contentPanel = getContentPane(); label = new JLabel("", JLabel.CENTER); JPanel panel = new JPanel(); b = new JButton("安装"); b.setForeground(Color.blue); b.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub execute(); } }); panel.add(b); contentPanel.add(panel, BorderLayout.NORTH); contentPanel.add(label, BorderLayout.SOUTH); setVisible(true); } void execute(){ M3 m3=new M3(); m3.Time1(this); //this.dispose(); } public static void main(String[] args) { AAA app = new AAA(); } }