Chapter 10 - Exercise 2 Program
//Jimmy Lee
//Chapter 10 - Exercise 2
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JBlueGray extends JApplet implements ActionListener {
String name = "Jimmy Lee";
JButton button = new JButton("Click Me");
JPanel pane = new JPanel();
Font font = new Font("Helvetica",Font.PLAIN,12);
public void init()
{
Graphics g = getGraphics();
pane.add(button);
button.addActionListener(this);
pane.setBackground(Color.green);
setContentPane(pane);
setVisible(true);
button.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == button)
{
repaint();
}
}
public void paint(Graphics g)
{
int num = 0;
g.setFont(font);
g.setColor(Color.black);
g.drawString("Jimmy Lee",250,100);
if(num == 1)
{
g.setFont(font);
g.setColor(Color.blue);
g.drawString("Jimmy Lee",250,100)
++num;
}else{
font = new Font("Helvetica",Font.PLAIN,36);
g.setColor(Color.gray);
g.drawString("Jimmy Lee",250,100);
}
++num;
}
}
_________________ I put on my robe and wizard hat.
|