//my first applet
//watch the colors change as you click the buttons
//these are java packages that we use in the applet
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;

public class Colors extends Applet implements ActionListener
//the name of our applet is "Colors"
{
        //these are the objects and variables that we use in the applet
        Font f=new Font("Helvetica", Font.BOLD,18);
        int colorOfBackground=0;
        int colorOfText=0;
        Button backButton, textButton;
        Dimension myAppletDim;

        public void init()
        //this method is called when the applet starts running
        {
                backButton = new Button ("Background Color");
                add(backButton);

                textButton=new Button("Text Color");
                add(textButton);
        }//end of method unit

        public void actionPerformed(ActionEvent e)
        //this method is called when we click on one of the buttons
        {
                if(e.getSource()==backButton)
                        colorOfBackground = ++colorOfBackground % 4;
                if(e.getSource()==textButton)
                        colorOfText = ++colorOfText % 3;
                repaint();
        }//end of method action

        public void paint(Graphics g)
        //this method is called whenever the applet window is redrawn
        {
                switch (colorOfBackground)
                {
                        case 0: setBackground(Color.cyan); break;
                        case 1: setBackground(Color.orange); break;
                        case 2: setBackground(Color.red); break;
                        case 3: setBackground(Color.black); break;
                        default: setBackground(Color.cyan); break;
                }

                switch (colorOfText)
                {
                        case 0: g.setColor(Color.blue); break;
                        case 1: g.setColor(Color.magenta); break;
                        case 2: g.setColor(Color.green); break;
                        default: g.setColor(Color.blue); break;
                }

                g.setFont(f);
                myAppletDim = size();
                g.drawString("Goodbye Woorld!  Hello Java!!",
                        (myAppletDim.width/2) - 120,
                        (myAppletDim.height/2) + 20);

        }//end of method paint

}//end of class Colors
