Home -> Workshops -> STA 2000 Java Workshop -> Junk Applet

Junk Applet

Copy all into Editor and save as Junk.java

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

public class Junk extends Applet implements ActionListener
{  private Button clickA = new Button("Click me");
   private Button clickB = new Button("No, click ME");
   private TextArea display = new TextArea();

   public void init()
   {  Panel buttons = new Panel();
      buttons.setLayout(new FlowLayout());
      buttons.add(clickA);
      buttons.add(clickB);

      setLayout(new BorderLayout());
      add("Center", display);
      add("South", buttons);
      clickA.addActionListener(this);
      clickB.addActionListener(this);
   }
   public void actionPerformed(ActionEvent ae)
   {  if (ae.getSource() == clickA)
         display.append("Woah, it tickles ...\n");
      else if (ae.getSource() == clickB)
         display.append("Please, stop ...\n");
   }
}