Package Test;
Import Java.awt.FlowLayout;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import Javax.swing.JButton;
Import Javax.swing.JFrame;
Import Javax.swing.JPanel;
public Class A extends JFrame {shethread thread = null;
Public A () {try {createframe ();
catch (Exception e) {e.printstacktrace ();
} private void Createframe () {JPanel JP = new JPanel (new FlowLayout ());
This.add (JP);
JButton Jbstart = new JButton ("Start");
JButton jbend = new JButton ("Stop");
Jp.add (Jbstart);
Jp.add (Jbend);
This.setsize (300, 100);
This.setvisible (TRUE);
This.setresizable (FALSE);
This.setdefaultcloseoperation (Jframe.exit_on_close);
Jbstart.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {if (thread!= null)
Thread.stop ();
thread = new Shethread ();
Thread.Start ();
}
}); Jbend.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {if (thread!= null) thread.stop ();
thread = NULL;
}
});
public static void Main (string[] args) {new A (). Show (); Class Shethread extends Thread {public shethread () {} public void run () {while (true) {try {sleep (
1000);
The catch (Interruptedexception e) {} System.out.println ("This is a test!"); }
}
}