Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPanel implements mousemotion eventlistener not working

843804Feb 1 2005 — edited Feb 1 2005
im trying to copy the functionality of one of those lame .applet demos
in which you press the mouse button down and a circle appears.
however, this is not an applet but a stand alone swing app.
i tried this two diff ways and it didnt work. here is my super brief code...

there is a main class that has a frame that loads a class that extends JPanel.

public main{
JFrame f = new JFrame
JPanel draw = new Draw();
draw.setOpaque(true);
f.setContentPane(draw);
}

this is another file Draw.class that extends a JPanel

class Plot1d extends JPanel implements MouseMotionListener{

public Plot1d() {
super();
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D)g;
}
public void mousePressed(MouseEvent e) {
mX = e.getX();
mY = e.getY();
System.out.println("press");
repaint();
}

obviously a lot is left out. everything is setup correctly and works fine
but none of the mouse events are triggering.
i put the System.out text there to see if maybe it was working but
not repainting.
I also tried this with eventlistener

class EventListener extends MouseAdapter
implements MouseMotionListener{
public void mouseClicked(MouseEvent e) {}
... }

private EventListener eListen;
eListen = new EventListener();

putting those two statments in the right place and without the previous
implements MouseML but that didnt work either.
Any help appreciated thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 1 2005
Added on Feb 1 2005
4 comments
147 views