FileDocCategorySizeDatePackage
Counter.javaAPI DocExample1989Thu Apr 05 09:30:04 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
private TextField
T2
private Label
L1
private Label
L2
private DecimalFormat
nf
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
			{
	nf = new DecimalFormat("000.00");

			value=0.0;
			T1.setText("" + value + nf.format(value));
			repaint();
			} // endif
		}	// endif
		
	
public voidinit()

		
	  
	
	T1 = new TextField(12);
	T2 = new TextField(12);
	L2=new Label("Value");
	L1=new Label("Volume");
	start = new Button("STARTX");
	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(L1);
	testPan.add(T1);
	testPan.add(L2);
	testPan.add(T2);

	
	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(50);
		}
	catch (InterruptedException ie)
		{
		}
		}// end while