diff --git a/src/FirstGUI.java b/src/FirstGUI.java index a584601..30dc3aa 100644 --- a/src/FirstGUI.java +++ b/src/FirstGUI.java @@ -6,7 +6,8 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; -class MyJButton extends JButton implements ActionListener { +class MyJButton extends JButton implements ActionListener , Runnable { + Thread thread; public MyJButton(String label){ super(label); } @@ -15,9 +16,31 @@ } @Override public void actionPerformed(ActionEvent e) { + if (thread == null){ + thread = new Thread(this); + thread.start(); + } else { + thread = null; + } FirstGUI.jf.pack(); System.out.println(e.getActionCommand()); } + int num = 0; + @Override + public void run() { + while(thread != null){ + num++; + setText("Second: "+num); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} +class MyThread extends Thread { + } public class FirstGUI {