View Single Post
  #4 (permalink)  
Old 09-09-2008, 08:36 PM
maggie_2 maggie_2 is offline
Member
 
Join Date: Sep 2008
Posts: 9
maggie_2 is on a distinguished road
Please I need help with an applet
I managed to get the program to compile, but I'm still having trouble getting it to do what I want. Basicaly I need small ovals to appear at random until they cover the entire background this is supposed to happen as I press the "press" buttin. What I get is one large oval that just sits there and the text goes off to the bottom of the screen as I click the "Press" button. If someone could point me in the correct direction as to what I can do to fix this it would be greatly appreciated:

Code:
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); } } }
Reply With Quote