File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Mouse events Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Applets
Reply Bookmark "Mouse events" Watch "Mouse events" New topic
Author

Mouse events

Jo Eagle
Greenhorn

Joined: Feb 14, 2001
Posts: 13
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

Joined: Oct 18, 2000
Posts: 4120

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


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Jo Eagle
Greenhorn

Joined: Feb 14, 2001
Posts: 13
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

Joined: Apr 05, 2000
Posts: 1441
I'll move this to the Applets forum.
John


The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
 
 
subject: Mouse events
 
Threads others viewed
Mouse Listener on JComboBox
Mouse events
Getting current mouse position
dumb newbie question
Jpanels and Jscrollpanels
developer file tools