FileDocCategorySizeDatePackage
Counter.javaAPI DocExample1719Wed Apr 04 12:46:52 BST 2001None

Counter

public class Counter extends Applet implements ActionListener, Runnable

Fields Summary
private Button
start
private Button
stop
private Button
reset
private Panel
testPan
private TextField
T1
Thread
counterThread
boolean
on
private double
value
Constructors Summary
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent ae)

	
	if ((ae.getSource() == start))
		{
			on = true;
			counterThread = new Thread(this, "");
			counterThread.start();
		}
	if ((ae.getSource() == stop))
		{
		on=false;
		repaint();
		}
	if((ae.getSource() == reset))
		{
		if(on==false)  // Don't want reset button to work if on is true
			{
			value=0;
			T1.setText("" + value);
			repaint();
			} // endif
		}	// endif
		
	
public voidinit()

		
	  
	
	T1 = new TextField(12);
	
	start = new Button("START");
	start.addActionListener(this);
	stop = new Button("STOP");
	stop.addActionListener(this);
	reset = new Button("RESET");
	reset.addActionListener(this);

	
	testPan = new Panel();
	testPan.add(start);
	testPan.add(stop);
	testPan.add(reset);
	testPan.add(T1);
	add(testPan);
	
public voidpaint(java.awt.Graphics g)

	
	
public voidrun()

	while (on==true)
	{
		value = value+0.05;
		T1.setText("" + value); // output needs formatting properly
		repaint();
	try
		{
	counterThread.sleep(500);
		}
	catch (InterruptedException ie)
		{
		}
		}// end while