import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*********************************************************
* Name: Your Name *
* Course: ICS 4M Pd. 5 *
* Assignment #1 *
* Purpose: One or two sentence purpose of the program. *
* Due Date: October 14, 2003 *
*********************************************************/
public class AppletEx2 extends Applet implements ActionListener
{
/*** Variable Dictionary ******************************
* calls - number ot times paint has been called *
* b - the button that makes paint get called again *
******************************************************/
int calls = 0;
Button b = new Button ("Click Me");
/*** init *********************************************
* Purpose: Set the background color and set up the *
* button *
* Parameters: none *
* Returns: none *
******************************************************/
public void init()
{
setBackground(Color.green);
// set up button
add(b);
b.addActionListener(this);
}
/*** paint ********************************************
* Purpose: Prints the number of times the button was *
* clicked *
* Parameters: g - Graphics object for drawing on *
* Returns: none *
******************************************************/
public void paint(Graphics g)
{
String s = "Button has been clicked " + calls + " time";
// Add 's' to times unless calls = 1
if (calls != 1)
s += "s";
s += ".";
g.drawString(s, 100,50);
}
/*** actionPerformed **********************************
* Purpose: Deal with the button being pressed *
* Parameters: e - details about the button event *
* Returns: none *
******************************************************/
public void actionPerformed(ActionEvent e)
{
calls++;
// make paint get called so that it can update the # of clicks
repaint();
}
}
|