Wednesday, 12 March 2014

This Program shows how to develop a Draggable JWindow using JAVA.

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();
     }
}

OUTPUT :


byteKoding

byteKoding

byteKoding.com is started with an intention to provide every updates related to technology and programming. It is specially for helping people in developing software projects in different programming languages like C/C++, Java, C#.Net, ASP.Net etc. The details that we share here can be very much useful in creating your software a great success.

Newer Post
This is the last post.

0 comments