• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mouse events

 
Jo Eagle
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to have the background color of the Applet change when there is a mouse click. (Randomly)
I've tried:
//-----
public void mouseClicked(MouseEvent e) {
mouseX = 0;
mouseY = 0;
msg ="Mouse Clicked." ;
setBackground(Color.green);
repaint();
}
//----
Do I use math.random ? Do I need to use RGB numbers?
Jo
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jo,
Here's how I would do it...

I'm not sure what this has to do with OO Programming, though, so I expect someone will come along and move this to Java in General(Beginner), or Applets...
HTH,
-Nate
 
Jo Eagle
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help - I'll give it a try.
-Jo
Sorry for posting this in the wrong section -
new to this great site and new to java - trying to teach myself.
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll move this to the Applets forum.
John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic