http://www.tutorialspoint.com/awt/awt_window.htm AWT WINDOW CLASS Copyright tutorialspoint.com Introduction The class Window is a top level window with no border and no menubar. It uses BorderLayout as default layout manager. Class declaration Following is the declaration for java.awt.window class: public class Window extends Container implements Accessible Class constructors S.N. 1 Constructor & Description WindowFrameowner Constructs a new, initially invisible window with the specified Frame as its owner. 2 WindowWindowowner Constructs a new, initially invisible window with the specified Window as its owner. 3 WindowWindowowner, GraphicsConfigurationgc Constructs a new, initially invisible window with the specified owner Window and a GraphicsConfiguration of a screen device. Class methods S.N. 1 Method & Description void addnotify Makes this Window displayable by creating the connection to its native screen resource. 2 void addpropertychangelistenerpropertychangelistenerlistener Adds a PropertyChangeListener to the listener list. 3 void add Property ChangeListenerStringpropertyName, PropertyChangeListenerlistener Adds a PropertyChangeListener to the listener list for a specific property.
4 void addwindowfocuslistenerwindowfocuslistenerl Adds the specified window focus listener to receive window events from this window. 5 void addwindowlistenerwindowlistenerl Adds the specified window listener to receive window events from this window. 6 void addwindowstatelistenerwindowstatelistenerl Adds the specified window state listener to receive window events from this window. 7 void applyresourcebundleresourcebundlerb Deprecated. As of J2SE 1.4, replaced by Component.applyComponentOrientation. 8 void applyresourcebundlestringrbname Deprecated. As of J2SE 1.4, replaced by Component.applyComponentOrientation. 9 void createbufferstrategyintnumbuffers Creates a new strategy for multi-buffering on this component. 10 void createbufferstrategyintnumbuffers, BufferCapabilitiescaps Creates a new strategy for multi-buffering on this component with the required buffer capabilities. 11 void dispose Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. 12 AccessibleContext getaccessiblecontext Gets the AccessibleContext associated with this Window. 13 BufferStrategy getbufferstrategy Returns the BufferStrategy used by this component. 14 boolean getfocusablewindowstate Returns whether this Window can become the focused Window if it meets the other requirements outlined in isfocusablewindow. 15 Container getfocuscyclerootancestor
Always returns null because Windows have no ancestors; they represent the top of the Component hierarchy. 16 Component getfocusowner Returns the child Component of this Window that has focus if this Window is focused; returns null otherwise. 17 Set<AWTKeyStroke> getfocustraversalkeysintid Gets a focus traversal key for this Window. 18 GraphicsConfiguration getgraphicsconfiguration This method returns the GraphicsConfiguration used by this Window. 19 List<Image> geticonimages Returns the sequence of images to be displayed as the icon for this window. 20 InputContext getinputcontext Gets the input context for this window. 21 <T extends EventListener> T[] getlistenersclass < T > listenertype Returns an array of all the objects currently registered as FooListeners upon this Window. 22 Locale getlocale Gets the Locale object that is associated with this window, if the locale has been set. 23 Dialog.ModalExclusionType getmodalexclusiontype Returns the modal exclusion type of this window. 24 Component getmostrecentfocusowner Returns the child Component of this Window that will receive the focus when this Window is focused. 25 Window[] getownedwindows Return an array containing all the windows this window currently owns. 26 Window getowner Returns the owner of this window.
27 static Window[] getownerlesswindows Returns an array of all Windows created by this application that have no owner. 28 Toolkit gettoolkit Returns the toolkit of this frame. 29 String getwarningstring Gets the warning string that is displayed with this window. 30 WindowFocusListener[] getwindowfocuslisteners Returns an array of all the window focus listeners registered on this window. 31 WindowListener[] getwindowlisteners Returns an array of all the window listeners registered on this window. 32 static Window[] getwindows Returns an array of all Windows, both owned and ownerless, created by this application. 33 WindowStateListener[] getwindowstatelisteners Returns an array of all the window state listeners registered on this window. 34 void hide Deprecated. As of JDK version 1.5, replaced by setvisibleboolean. 35 boolean isactive Returns whether this Window is active. 36 boolean isalwaysontop Returns whether this window is an always-on-top window. 37 boolean isalwaysontopsupported Returns whether the always-on-top mode is supported for this window. 38 boolean isfocusablewindow
Returns whether this Window can become the focused Window, that is, whether this Window or any of its subcomponents can become the focus owner. 39 boolean isfocuscycleroot Always returns true because all Windows must be roots of a focus traversal cycle. 40 boolean isfocused Returns whether this Window is focused. 41 boolean islocationbyplatform Returns true if this Window will appear at the default location for the native windowing system the next time this Window is made visible. 42 boolean isshowing Checks if this Window is showing on screen. 43 void pack Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. 44 void paintgraphicsg Paints the container. 45 boolean posteventevente Deprecated. As of JDK version 1.1 replaced by dispatcheventawtevent. 46 protected void processeventawtevente Processes events on this window. 47 protected void processwindoweventwindowevente Processes window events occurring on this window by dispatching them to any registered WindowListener objects. 48 protected void processwindowfocuseventwindowevente Processes window focus event occuring on this window by dispatching them to any registered WindowFocusListener objects. 49 protected void processwindowstateeventwindowevente
Processes window state event occuring on this window by dispatching them to any registered WindowStateListener objects. 50 void removenotify Makes this Container undisplayable by removing its connection to its native screen resource. 51 void removewindowfocuslistenerwindowfocuslistenerl Removes the specified window focus listener so that it no longer receives window events from this window. 52 void removewindowlistenerwindowlistenerl Removes the specified window listener so that it no longer receives window events from this window. 53 void removewindowstatelistenerwindowstatelistenerl Removes the specified window state listener so that it no longer receives window events from this window. 54 void reshapeintx, inty, intwidth, intheight Deprecated. As of JDK version 1.1, replaced by setboundsint, int, int, int. 55 void setalwaysontopbooleanalwaysontop Sets whether this window should always be above other windows. 56 void setboundsintx, inty, intwidth, intheight Moves and resizes this component. 57 void setboundsrectangler Moves and resizes this component to conform to the new bounding rectangle r. 58 void setcursorcursorcursor Set the cursor image to a specified cursor. 59 void setfocusablewindowstatebooleanfocusablewindowstate Sets whether this Window can become the focused Window if it meets the other requirements outlined in isfocusablewindow. 60
60 void setfocuscyclerootbooleanfocuscycleroot Does nothing because Windows must always be roots of a focus traversal cycle. 61 void seticonimageimageimage Sets the image to be displayed as the icon for this window. 62 void seticonimageslist <?extendsimage > icons Sets the sequence of images to be displayed as the icon for this window. 63 void setlocationbyplatformbooleanlocationbyplatform Sets whether this Window should appear at the default location for the native windowing system or at the current location returnedbygetlocation the next time the Window is made visible. 64 void setlocationrelativetocomponentc Sets the location of the window relative to the specified component. 65 void setminimumsizedimensionminimumsize Sets the minimum size of this window to a constant value. 66 void setmodalexclusiontypedialog. ModalExclusionTypeexclusionType Specifies the modal exclusion type for this window. 67 void setsizedimensiond Resizes this component so that it has width d.width and height d.height. 68 void setsizeintwidth, intheight Resizes this component so that it has width width and height height. 69 void setvisiblebooleanb Shows or hides this Window depending on the value of parameter b. 70 void show Deprecated. As of JDK version 1.5, replaced by setvisibleboolean. 71 void toback If this Window is visible, sends this Window to the back and may cause it to lose focus or
activation if it is the focused or active Window. 72 void tofront If this Window is visible, brings this Window to the front and may make it the focused Window. Methods inherited This class inherits methods from the following classes: java.awt.window java.awt.container java.awt.component java.lang.object Window Example Create the following java program using any editor of your choice in say D:/ > AWT > com > tutorialspoint > gui > AwtContainerDemo.java package com.tutorialspoint.gui; import java.awt.*; import java.awt.event.*; public class AwtContainerDemo { private Frame mainframe; private Label headerlabel; private Label statuslabel; private Panel controlpanel; private Label msglabel; public AwtContainerDemo(){ preparegui(); public static void main(string[] args){ AwtContainerDemo awtcontainerdemo = new AwtContainerDemo(); awtcontainerdemo.showframedemo(); private void preparegui(){ mainframe = new Frame("Java AWT Examples"); mainframe.setsize(400,400); mainframe.setlayout(new GridLayout(3, 1)); mainframe.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent windowevent){ System.exit(0); ); headerlabel = new Label(); headerlabel.setalignment(label.center); statuslabel = new Label(); statuslabel.setalignment(label.center); statuslabel.setsize(350,100); msglabel = new Label(); msglabel.setalignment(label.center); msglabel.settext("welcome to TutorialsPoint AWT Tutorial.");
controlpanel = new Panel(); controlpanel.setlayout(new FlowLayout()); mainframe.add(headerlabel); mainframe.add(controlpanel); mainframe.add(statuslabel); mainframe.setvisible(true); private void showwindowdemo(){ headerlabel.settext("container in action: Window"); final MessageWindow window = new MessageWindow(mainFrame, "Welcome to TutorialsPoint AWT Tutorial."); Button okbutton = new Button("Open a Window"); okbutton.addactionlistener(new ActionListener() { public void actionperformed(actionevent e) { window.setvisible(true); statuslabel.settext("a Window shown to the user."); ); controlpanel.add(okbutton); mainframe.setvisible(true); class MessageWindow extends Window{ private String message; public MessageWindow(Frame parent, String message) { super(parent); this.message = message; setsize(300, 300); setlocationrelativeto(parent); setbackground(color.gray); public void paint(graphics g) { super.paint(g); g.drawrect(0,0,getsize().width - 1,getSize().height - 1); g.drawstring(message,50,150); Compile the program using command prompt. Go to D:/ > AWT and type the following command. D:\AWT>javac com\tutorialspoint\gui\awtcontainerdemo.java If no error comes that means compilation is successful. Run the program using following command. D:\AWT>java com.tutorialspoint.gui.awtcontainerdemo Verify the following output
Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js