Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uf.controll;
- import java.awt.Component;
- import java.awt.Point;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseMotionAdapter;
- import javax.swing.JDialog;
- import javax.swing.JFrame;
- public class WindowListeners {
- private JFrame f;
- private JDialog d;
- private Point point;
- public WindowListeners() {}
- public WindowListeners(JFrame f){
- this.f = f;
- setListeners();
- }
- public WindowListeners(JDialog d){
- this.d = d;
- setListeners();
- }
- private void setListeners(){
- Component c = f == null ? d : f;
- this.point = new Point();
- c.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mousePressed(e);
- point.x = e.getX();
- point.y = e.getY();
- }
- });
- c.addMouseMotionListener(new MouseMotionAdapter() {
- @Override
- public void mouseDragged(MouseEvent e) {
- super.mouseDragged(e);
- Point p = c.getLocation();
- c.setLocation(
- p.x + e.getX() - point.x,
- p.y + e.getY() - point.y
- );
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement