aspose file tools
The moose likes Applets and the fly likes see this very simple code. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Applets
Reply Bookmark "see this very simple code." Watch "see this very simple code." New topic
Author

see this very simple code.

nima lama
Greenhorn

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");

b1.setBackground(Color.gray);
b2.setBackground(Color.gray);

b1.addMouseListener(this);
b2.addMouseListener(this);
add(b1);
add(b2);
}
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.
*/

b1.setBackground(Color.cyan);
b2.setBackground(Color.cyan);

}
public void mouseExited(MouseEvent e)
{

b1.setBackground(Color.gray);
b2.setBackground(Color.gray);

}

}
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.
Regards,
Manfred.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: see this very simple code.
 
Similar Threads
setBounds() does not work????
mouseEntered method
mouselistener for Scrollbar
how to keep drawn free hand painted image when resizing the window
setBounds() does not work????