import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class JEraseImage extends JApplet implements ActionListener
{
ImageIcon image = new ImageIcon("event.gif");
JButton press = new JButton("press");
int width, height;
int imageWidth, imageHeight;
int startPosX = 150;
int startPosY = 100;
Container con = getContentPane();
public void init()
{
con.setLayout(new FlowLayout());
press.addActionListener(this);
con.add(press);
width = image.getIconWidth();
height = image.getIconHeight();
}
public void actionPerformed(ActionEvent event)
{
width = width * 2;
height = height * 2;
repaint();
}
public void paint(Graphics g)
{
g.drawImage(image.getImage(), 150, 100, width, height, this);
press.repaint();
for(int count = 0; count < 20; ++count)
{
int x = (int) (Math.random() * imageWidth) + startPosX;
int y = (int) (Math.random() * imageHeight) + startPosY;
g.fillOval(x, y, 150, 100);
}
}
} |