Class Window in AWT in Java

0
85
Spread the love
  • 28
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    165
    Shares

Class Window in AWT in Java

Window class represents a top-level window with no borders or menu bar, Window is a Container with BorderLayout as its default layout manager. The window is rarely used directly; its subclasses Frame and Dialog are more commonly useful.

The Window class serves as a top-level display area that exists outside the browser or applet area we may be working in. A window must have a parent Frame.

show() (which overrides Component.show ()) makes a Window visible and brings it to the front of other windows.toFront() brings a window to the front, and toBack() buries a window beneath others.

the pack() is an important method that initiates layout management for the window and sets the window size to match the preferred size of the components contained within the window.

getToolkit() returns the Toolkit in use for this window.

dispose() when a Window is no longer needed to free its window system resources.

The structure of the window class is given as

public class java.awt.Window extends java.awt.Container{
// Public Constructor
public Window(Frame parent);
// Public Instance Methods
public void addNotify();// Overrides Container
public synchronized void addWindowListener(WindowListener wl);
public void dispose();
public Component getFocusOwner();
public Locale getLocale();// Overrides Component
public Toolkit get Toolkit();// Overrides Component
public final String getWarningString();
public boolean isShowing();// Overrides Component
public void pack();
public boolean postEvent(Event e);// Overrides Component
public synchronized void removeWindow Listener(WindowListener 1);
public void show();// Overrides Component
public void toBack();
public void toFront();
// Protected Instance Methods
protected void processEvent (AWTEvent e);// Overrides Container
protected void processWindowEvent (WindowEvent e);
}

The details of the class structure are given as follows:

public Window(Frame parent);

public Window(Frame parent) constructs a Window object.

Parameter
parent – Frame that is to act as the parent of Window.

public void addNotify();

public void addNotify() method creates Window’s peer and peers of contained components.

public synchronized void addWindowListener(WindowListener l);

public synchronized void addWindowListener(WindowListener l) method adds a listener for windowing events.

Parameter
l – An object that implements the WindowListener interface.

public void dispose();

public void dispose() method releases the resources of the Window.

public Component getFocusOwner();

public Component getFocusOwner() method returns the child component that currently has the input focus.

This method returns the child component that currently has the input focus.

public Locale getLocale();

public Locale getLocale() method returns the locale for this Window.

This method returns the locale for this Window.

public Toolkit getToolkit();

public Toolkit getToolkit() method returns the Toolkit of Window.

This method returns the Toolkit of Window.

public final String getWarningString();

public final String getWarningString() method returns the String that will be displayed on the bottom of insecure Window instances.

This method returns the String that will be displayed on the bottom of insecure Window instances.

public boolean isShowing();

public boolean isShowing() method returns true if the Window is showing on the screen, false otherwise.

This method returns true if the Window is showing on the screen, false otherwise.

public void pack();

public void pack() method resizes Window to getPreferredSize() of contained components.

public boolean postEvent(Event e);

public boolean postEvent(Event e) method instructs the Window to deal with Event.

This method returns true if Event is handled. Otherwise, false is returned.

Parameter
e – Event instance to post to window.

public synchronized void remove WindowListener(WindowListener l);

public synchronized void remove WindowListener(WindowListener l) method removes an event listener.

Parameter
l – One of this Frame’s WindowListeners.

public void show();

public void show() method shows the Window and validate its components.

public void toBack();

public void toBack() method puts the Window in the background of the display.

public void toFront();

public void toFront() method brings the Window to the foreground of the display.

protected void processEvent(AWTEvent e);

protected void processEvent(AWTEvent e) method accepts low level AWTEvents for processing.

Parameter
e – The event to process.

protected void processWindowEvent(WindowEvent e);

protected void processWindowEvent(WindowEvent e) method accepts window events for processing. Normally, this method is called by processEvent().

Parameter
e – The event to process.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 28
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    165
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here