| | |
    Java Beginner Home
    Table of Contents
    Swing Tutorial
     JFrame
     JInternalFrame
     JWindow
     JOptionPane
     JLabel
     JTextField
     JPasswordField
     JTextArea
     JButton
     JRadioButton
     JCheckBox
     JComboBox
     Jlist
     JTabbedPane
     JMenuBar
     Scrollable JPopupMenu
     JToolBar
     BorderLayout
     FlowLayout
     GridLayout
     GridBagLayout
     Java Look and Feel
     Swing Calculator
     Swing Address book
     Shuffle Game
    Download Java Software
    Advertise
    Feedback
    Java books
    Eclipse Plugin Site

Java JWindow class example



JWindow

Java Swing Tutorial Explaining the JWindow Component. JWindow is Swing’s version of Window and is descended directly from that class. Like Window, it uses BorderLayout by default. Almost all Swing components are lightweight except JApplet, JFrame, JDialog, and JWindow.

JWindow Source Code

public class JWindowDemo extends JWindow {

	private int X = 0;
	private int Y = 0;
	public JWindowDemo() {
		setBounds(60, 60, 100, 100);
		addWindowListener(new WindowAdapter() {

			public void windowClosing(WindowEvent e) {
				System.exit(0); // An Exit Listener
			}
		});
		// Print (X,Y) coordinates on Mouse Click
		addMouseListener(new MouseAdapter() {

			public void mousePressed(MouseEvent e) {
				X = e.getX();
				Y = e.getY();
				System.out.println("The (X,Y) coordinate of window is ("
						+ X + "," + Y + ")");
			}
		});
		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 JWindowDemo();
	}
}

Output


Download JWindow Source Code

Java JWindow Hierarchy

javax.swing
Class JWindow
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window

All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable
Direct Known Subclasses:
BasicToolBarUI.DragWindow, Dialog, Frame, JWindow

JWindow Constructor


Window(Frame owner)

Constructs a new invisible window with the specified Frame as its owner.

Window(Window owner)
Constructs a new invisible window with the specified Window as its owner.

Window(Window owner, GraphicsConfiguration gc)
Constructs a new invisible window with the specified window as its owner and a GraphicsConfiguration of a screen device.

 
 
    Java is a trademark of Sun Microsystems, Inc.
| | |
© Copyright 2007-08 javabeginner.com