|
The second is a thread blocking problem. You stop the main thread, so you can't show it. In order to make you have a lot of changes, I use this method to modify:
Import javax.swing. *;
Import java.awt. *;
Import java.awt.event. *;
Public class text extends JFrame IMPLEments ActionListener, runnable {// adds a thread interface.
JButton TB = New JButton ("Start");
INT A = 0;
Jtextfield text = new jtextfield (", 10);
Jtextfield text1 = new jtextfield ("5", 10);
// Thread TH = New Thread (this);
TEXT () {
Super (Text Test ");
Setsize (100, 150);
SETLOCATION (200, 300);
GetContentPane (). setLayout (New flowLayout ());
GetContentPane (). add (text);
GetContentPane (). add (tb);
getContentPane (). Add (text1);
Tb.addActionListener (this);
Pack ();
SetDefaultCloseOperation (jframe.exit_on_close);
SetVisible (TRUE);
TEXT.SETENABLED (FALSE);
Run (); // ------------------> It is equivalent to executing your Begin method.
}
Public void run () {// -------> BeGin is changed to RUN, which is for overload.
INT i = 0;
A = integer.parseint (Text1.getText (). Trim ());
While (a> 0) {
A-;
i = 50;
While (i> 0) {
I-;
System.out.print ("+ i);
Text.setText ("+ i);
Try {
Thread.sleep (50);
}
Catch (Exception E) {}
}
}
}
Public Void ActionPerformed (ActionEvent EE) {
New thread (this) .start (); // ---> Mainly here, create new threads, this will not affect the main thread
}
Public static void main (String SRGS []) {
NEW text ();
}
} |
|