java - Making the getX() and getY() methods to get the locations of the panel, not the frame -


i'm using getx() , gety() methods in mouselistener class location of panel, it's getting location of frame instead, , includes top of title bar , sides, it's not getting location want. have the:

@override public dimension getpreferredsize() {     return new dimension(300, 300); } 

method in paint class override frame when paint in graphics, , set paint location of x, , y, sets panel location, , not frame location, don't know how make mouselistener class same. please help. thanks.

code mouselistener class:

package events;  import javax.swing.*; import java.awt.*; import java.awt.event.*;  public class events implements actionlistener, mouselistener, mousemotionlistener {      static events events = new events();      int x;     int y;      public void actionperformed(actionevent e) {     }      public void mousepressed(mouseevent e) {     }      public void mousereleased(mouseevent e) {     }      public void mouseentered(mouseevent e) {     }      public void mouseexited(mouseevent e) {     }      public void mouseclicked(mouseevent e) {         x = e.getx();         y = e.gety();          system.out.println("x:" + x + " " + "y:" + y);     }      public void mousemoved(mouseevent e) {     }      public void mousedragged(mouseevent e) {     } } 

nevermind. can call panel name panel x, , y locations. anyways.

x = p.g.getx(); y = p.g.gety() 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -