java - Getting the coordinates of the panel -
using mouseevents, able x , y coordinates of frame, yet unable x , y coordinates of panel. below codes me getting x , y coordinates of frame.
public void mousemoved(mouseevent e) { x = e.getx(); y = e.gety(); text = integer.tostring(x) +","+integer.tostring(y); frame.frame.repaint(); }
the below codes me trying x , y coordinates of panel, it's painting out 0's instead. paint.paint name of jpanel. don't know i'm doing wrong. please if can.
public void mousemoved(mouseevent e) { x = paint.paint.getx(); y = paint.paint.gety(); text = integer.tostring(x) +","+integer.tostring(y); frame.frame.repaint(); }
if understand right, mouselistener registered jframe, , wish x/y relative jpanel contained within jframe. x , y within mouseevent refer component in mouselistener registered. if have mouselistener registered on parent container, , coordinates of mouseevent relative child component, can using swingutilities convert coordinates
public void mousepressed(mouseevent e){ point childcoordinate = swingutilities.convertpoint(parent, e.getpoint(), child); }
Comments
Post a Comment