What do you mean it will not work? Are you receiving errors? Is the rectangle not showing? Also, your code is a bit strange... this is the first time I've seen the paint method as you've shown... someone correct me if I'm wrong.. but I don't think you can have a method definition inside of another one...move the paint method outside of the showMessage method can we see the whole class and/or how you're using it...
public void mouseMoved(MouseEvent e) {
//System.out.println("asdf");
showMessage("Test");
}
private void showMessage(String string) {
//System.out.println(string);
}
public void paint(Graphics g) {
g.fillRect(25, 20, 20, 20);
g.drawString("Hello", 25, 20);
}
I realize this isn't the answer you're looking for but have a good
read at the Sun tutorial on Mouse-Motion and other events.