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

 //All applets must be declared public
public class HelloWorld3 extends Applet implements ActionListener{

 //Declare objects
 String text;
 Font font;
 Button button1,button2;
 Color color;

 //this method does the initializing
   public void init(){

 text="Hello World";
 font=new Font("Helvetica",Font.BOLD,24);

 setBackground(Color.black);

 //Initialise the buttons, add actionListener, and add them to the panel
 button1=new Button("COLOR GREEN");
 button2=new Button("COLOR WHITE");
 button1.addActionListener(this);
 button2.addActionListener(this);
 button1.setActionCommand("green");
 button2.setActionCommand("white");
 add("North",button1);
 add("South",button2);

 //Sets the text color to default white
 color=Color.white;
 }

 //This method must be included in a class that implements ActionListener
   public void actionPerformed(ActionEvent evt){

 if(evt.getActionCommand().equals("green"))
  color=Color.green;
 else if(evt.getActionCommand().equals("white"))
  color=Color.white;

 repaint();
 }
 

 //This method paints the graphic to the applet
 //in this example only the String Hello world
 //If you want another text, just change the init method
   public void paint(Graphics g){

 //Draws a nice frame for the String
 g.setColor(Color.blue);
 g.fillRect(70,45,160,60);
 g.setColor(Color.red);
 g.fillRect(75,50,150,50);
 
 //Sets the font which the applet will use to draw the String
 g.setFont(font);

 //actually paints the string in position 33,34
 g.setColor(color);
 g.drawString(text,83,83);

 }
}