import java.awt.*;
import java.awt.event.*;
class FruitGrow implements ActionListener {
FruitCanvas fc;
Fruit f;
FruitThread thread;
.
.
.
FruitGrow(){
.
.
.
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("Grow"))
{
thread
= new FruitThread(f,fc,tf,this);
thread.start();
.
.
.
}
else if(e.getActionCommand().equals("Stop"))
{
thread.stop();
.
.
.
}
.
.
.
}
.
.
.
}
import java.awt.*;
class FruitThread extends Thread {
Fruit fruit;
FruitCanvas fc;
TextField tf;
FruitGrow fg;
FruitThread(Fruit f, FruitCanvas fc2, TextField tf2, FruitGrow
fg2) {
.
.
.
}
public void run(){
try{
while
(true) {
fruit.grow();
int d = fruit.getDiameter();
tf.setText(""+d);
fc.repaint();
try {
sleep(100);
}
catch (InterruptedException e) {}
}
}
catch (DiamException de) {
tf.setText("800");
fg.butt.setEnabled(false);
fg.ass.setEnabled(false);
}
}
}