memilavi
asked on
HELP!! Trapping mouse events
Hi.
I've began to write an applet a few days ago using Visual J++ 6.0.
In my recent applets, I've trapped mouse click using the 'mouseDown' event, but now I see this event is deprecated, and there is new method for trapping event. I just can't understand how to implement the new method! I see terms like 'processMouseEvent','event Listenet' and so on, and can't find my way through that maze of words!
Please help me! Please give me a step-by-step instruction of implementing mouse events trapping!
Thanks a lot!
I've began to write an applet a few days ago using Visual J++ 6.0.
In my recent applets, I've trapped mouse click using the 'mouseDown' event, but now I see this event is deprecated, and there is new method for trapping event. I just can't understand how to implement the new method! I see terms like 'processMouseEvent','event
Please help me! Please give me a step-by-step instruction of implementing mouse events trapping!
Thanks a lot!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, zicai!
zicai,
pls help ,i am going tommorrow on a long holiday.
import java.awt.*;
import java.awt.event.*;
public class Assign2 extends java.applet.Applet
{
private TextField txt = new TextField("",20);
private Button b1 = new Button("Button");
private Button b2 = new Button("Glutton");
private Button b3 = new Button("Sutton");
private static Assign2 applet=null;
private static Color foreGround=null;
private static Color backGround=null;
public void init()
{
setLayout(new BorderLayout());
txt.setEditable(false);
Panel p1 = new Panel();
//b1.setBackground(Color.c
b1.addMouseListener(new GenericListener());
b2.addMouseListener(new GenericListener());
b3.addMouseListener(new GenericListener());
p1.add(b1);
p1.add(b2);
p1.add(b3);
add(p1,BorderLayout.NORTH)
add(txt,BorderLayout.SOUTH
}
class GenericListener extends MouseAdapter
{
public void mouseEntered( MouseEvent e )
{
//System.out.println("Chan
Button temp = (Button)e.getSource();
foreGround=temp.getForegro
backGround=temp.getBackgro
temp.setForeground(new
Color((float)Math.random()
temp.setBackground(new
Color((float)Math.random()
}
public void mouseExited( MouseEvent e )
{
//System.out.println("*** Restoring Foreground");
Button temp = (Button)e.getSource();
temp.setForeground(foreGro
temp.setBackground(backGro
}
}
public static void main(String[] args)
{
applet = new Assign2();
Frame aFrame = new Frame("Assign2");
aFrame.addWindowListener(n
public void windowClosing(WindowEvent e)
{
applet.stop();
applet.destroy();
System.exit(0);
}
});
aFrame.add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
aFrame.pack();
aFrame.setVisible(true);
}
}