标签:
1 去掉标题栏:JFrame frame=new JFrame(); frame.setUndecorated(true); 2 3 实现拖动:定义全局变量: int first_x; int first_y; 4 5 添加MouseListener, 重写mousePressed方法 6 7 public void mousePressed(MouseEvent e){ 8 9 first_x=e.getX(); 10 11 first_y=e.getY(); //记录下位移的初点 12 13 } 14 15 添加MouseMotionListener,重写mouseDragged方法 16 17 public void mouseDragged(MouseEvent e){ 18 19 int x=e.getX()-first_x; 20 21 int y=e.getY()-first_y; //取得位移(x,y) 22 23 frame.setBounds(frame.getX()+x, frame.getY()+y, frame.getWidth(), frame.getHeight()); 24 25 }
标签:
原文地址:http://www.cnblogs.com/nmeng/p/5950621.html