import java.awt.event.mouseadapter;import java.awt.event.mousemotionlistener;import java.awt.borderlayout;import java.awt.component;import java.awt.point;import java.awt.event.actionevent;import java.awt.event.actionlistener;import java.awt.event.mouseevent;import javax.swing.borderfactory;import javax.swing.jbutton;import javax.swing.jframe;import javax.swing.border.bevelborder;public class easymove extends mouseadapter implements mousemotionlistener { private point offset; private component host; public static void main(string[] args) { jframe frm = new jframe("easymove demo."); frm.setdefaultcloseoperation(jframe.exit_on_close); frm.setsize(300, 300); frm.setundecorated(true);// 影藏边框 frm.getrootpane().setborder( borderfactory.createbevelborder(bevelborder.raised)); new easymove().install(frm); jbutton exit = new jbutton("exit"); exit.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { system.exit(0); } }); frm.getcontentpane().add(exit, borderlayout.south); frm.setvisible(true); } public synchronized void install(component comp) { uninstall(); host = comp; host.addmouselistener(this); host.addmousemotionlistener(this); } public synchronized void uninstall() { if (host != null) { host.removemouselistener(this); host.removemousemotionlistener(this); host = null; } } public void mousepressed(mouseevent e) { if (e.getsource() == host) offset = e.getpoint(); } public void mousedragged(mouseevent e) { if (e.getsource() != host) return; final int x = host.getx(); final int y = host.gety(); final point lastat = e.getpoint(); host.setlocation(x + lastat.x - offset.x, y + lastat.y - offset.y); } public void mousemoved(mouseevent e) { }}
??
java swing:http://www.java2s.com/code/java/swing-jfc/cata
logswing-jfc.htm