File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes see this very simple code. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "see this very simple code." Watch "see this very simple code." New topic

see this very simple code.

nima lama

Joined: Jun 18, 2001
Posts: 19
hello guys,
this is a very simple code, but i am confused can you help me out?
in this code, i wanted to changed the color of the button when mouse entered over the button.but problem with the below code
is that when i move mouse over one button both the button color get changes. so, please see this.
thank you.
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class but extends Applet implements MouseListener
Button b1,b2;
public void init()
b1=new Button("click1");
b2=new Button("click2");


public void mousePressed(MouseEvent e)
public void mouseReleased(MouseEvent e)
public void mouseClicked(MouseEvent e)
public void mouseEntered(MouseEvent e)
how to change the particular button color which has the mouse over it. at present whenever the mouse come over either of the button, both the color changes.


public void mouseExited(MouseEvent e)



Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Nima,
Make use of the getSource method of the MouseEvent:

Do the same thing for the mouseEntered and mouseExited and you will be done.
I agree. Here's the link:
subject: see this very simple code.
jQuery in Action, 3rd edition