diff --git a/FirstGUI.java b/FirstGUI.java index 1930b4f..22dc156 100644 --- a/FirstGUI.java +++ b/FirstGUI.java @@ -8,9 +8,10 @@ import javax.swing.JButton; -public class FirstGUI extends JPanel implements ActionListener, WindowListener { +public class FirstGUI extends JPanel implements ActionListener, WindowListener, Runnable { JFrame frame; JButton button1, button2; + int seconds = 0; //秒数 public static void main(String[] args) { new FirstGUI(); } @@ -29,6 +30,8 @@ @Override public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); + Thread thread = new Thread(this); + thread.start(); } @Override public void windowOpened(WindowEvent e) { @@ -52,4 +55,15 @@ @Override public void windowDeactivated(WindowEvent e) { } + @Override + public void run() { + for(int i=0; i< 10;i++){ + System.out.println(i+" sec"); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } }