Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Java Programming Code Examples

Java > Swing Code Examples

Create a Draggable JWindow

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
Create a Draggable JWindow import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ab extends JWindow { private int X=0; private int Y=0; public ab() { setBounds(50,50,200,200); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { X=e.getX(); Y=e.getY(); } }); addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { setLocation(getLocation().x+(e.getX()-X),getLocation().y+(e.getY()-Y)); } }); setVisible(true); } public static void main(String[] args) { new ab(); } }