1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
|
public class MyActionListener implements ActionListener, Runnable
{
private Main owner; // Die klasse, das Label und Button enthält
private Thread t;
public MyActionListener( Main m )
{
this.owner = m;
}
public void run()
{
for(int i=0; i<10; i++)
{
this.owner.zahlL.setText( String.valueOf( i ) );
try
{
Thread.sleep( 2000 );
}
catch( InterruptedException IX )
{
}
// den Thread auf null setzen, damit die aktion
// wiederholt werden kann
this.t = null;
}
public void actionPerformed( ActionEvent e)
{
if( this.t == null && e.getSource() == this.owner.startB )
{
this.t = new Thread(this);
this.t.start();
}
}
} |