import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class Counter2
  extends Applet
  implements ActionListener
{  
  private Button upButton = new Button("+1");
  private Button downButton = new Button("-1");
  private int counter = 0;
  
  public void init() {
    add(downButton);
    add(upButton);
    downButton.addActionListener(this);
    upButton.addActionListener(this);
  } // init
  
  public void paint(Graphics g) {
    g.drawString("Count: "+counter, 70, 50);
  }// paint
  
  public void actionPerformed(ActionEvent e) { 
    // Might be a "-1" or a "+1" button click
    // Check the event's "source" and act accordingly
    if (e.getSource() == downButton) {
      counter = counter-1;
    }
    else {
      // Must be upButton
      counter = counter+1;
    }
    repaint();
  } // actionPerformed
  
} // class CounterUpDown