Applet With Message


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

  /*  
  <applet code="Applet3" width=250 height=150>  
  </applet>  
  */

  public class Applet3 extends Applet implements ActionListener
  {
      String msg = "";
      Button yes, no, maybe;

      public void init()
      {
          yes = new Button("Yes"); 
          no = new Button("No");
          maybe = new Button("Undecided");

          add(yes);
          add(no); 
          add(maybe);

          yes.addActionListener(this);
          no.addActionListener(this); 
          maybe.addActionListener(this);
      }

      public void actionPerformed(ActionEvent ae)
      {
          String str = ae.getActionCommand(); 

          if (str.equals("Yes"))
          {
              msg = "You Pressed Yes.";
          } 
          else if (str.equals("No")) 
          {
              msg = "You Pressed No.";
          }
          else 
          {
              msg = "You Pressed Undecided.";
          } 
          repaint(); 
      }

      public void paint(Graphics g)
      {
          g.drawString(msg, 6, 100 ); 
      }
  }

Output: