Im trying to figure out the mouse classes for a larger project im working on. This is a really simple applet i wrote, and based off of the sun micro systems tutorial it seems like it should work. The program should simply redraw the square where ever the mouse clicks. However it doesnt do it. As i undersatnd the applet should draw, wait for a mouse command, then redraw right? but in my program my mouseUp fires (i have console out to tell me every time it fires) but then it does fire paint again, so i must be mistaken about the way applets work. What am i missing, how do i get it to redraw? and how would i get this app to work?
/////////
import java.awt.*; import javax.swing.*; import java.applet.*; public class MovingSquare extends Applet { private int xPos = 0; private int yPos = 0; private Color currentColor = Color.BLACK; public void init() { addMouseListener(this); xPos = 200; yPos = 200; setBackground(Color.GRAY); } public void paint(Graphics g) { g.setColor(currentColor); g.fillRect(xPos,yPos,30,30); System.out.println("RUN_PAINT"); } public boolean mouseUp (Event event, int x, int y) { System.out.println(x); System.out.println(y); xPos = x; yPos = y; return true; } }