All Methods
zio package

context

zio
Class ZWindow


java.lang.Object

  extended byzio.ZWindow


public class ZWindow
extends java.lang.Object

ZWindows are top level windows known to the operating system. Here is an example program that creates and displays a window containing a red square.

 public static void main( String [] junk) {
    ZWindow g = new ZWindow(
                     "Red Box",
                     new ZBox()
                           .color(Color.RED).size(new Dimension(100,100))
    );
 }

Here is an example with two squares appearing in a row.

 public static void main( String [] junk) {
    Dimension d = new Dimension(100,100);
    ZWindow g = new ZWindow(
                      "Red Box",
                      new ZRow(
                         new ZBox().color(Color.RED).size(d),
                         new ZBox().color(Color.BLUE).size(d)
                      )  
                );
 }

Replace ZRow with ZCol to get a column of squares. ZRows and ZCols are called slices. Layout management is handled by placing slices within slices.

When there are multiple windows on the screen they will be placed at different locations. When a single window works out to be too big for the screen, all its components are downsized. This downsizing is seldom pretty but it will let you see relative sizes. To see the exact calculated size (that is before any downsizing) of any component ZObject, use a debug() suffix on that ZObject. (See the "about slices" reference below for an explanation of what suffixes are.)

Unless a program does something to explicitly cease execution, it will run until the user closes the last visible window. The preferred way of stopping your program is to invoke Zio.stop().

Imports for Both Examples:

 import java.awt.*;  // for the Color and Dimension classes
 import zio.*;
 

Fine Print for the First Example: The red square is created as a ZBox whose width and height are both 100 pixels. The window shows "Red Box" in the title bar. The window (and all windows created with the zio package), will have expanding margins on all sides. These margins start out at zero width so you won't see them unless you expand the window. You will see the red square because all zio windows rigidly enforce a minimum size.

Fine Print for the Second Example: Here, the zero sized horizontal margins are replaced with the ZRow's margins. The minimum size of white space in a ZRow is not 0 but can be adjusted.

One Gotcha: Do not put the same ZObject two places in a window or windows.

Version:
Jul 22, 2005
Author:
copyright 2005 by J Adrian Zimmer
Licensed under the Open Software License version 2.1
See Also:
about slices, Dimension , Color

Constructor Summary
ZWindow(java.lang.String title, ZObject gui)
          In cooperation with operating system, creates a top level window.
ZWindow(java.lang.String title, ZObject gui, boolean visible)
          In cooperation with operating system, creates a top level window.
 
Method Summary
 void closeWindow()
          Closes window.
protected  void epilog()
          This is invoked when a window closes (by the user or thru closeWindow()).
 void fullScreen()
          Makes window's minimum size full_screen.
 void hide()
          Makes the window invisible so a user will see no trace of it.
static void setBackgroundColor(java.awt.Color bg)
          Defunct.
static void setForegroundColor(java.awt.Color fg)
          Defunct.
 void setLocation(int x, int y)
          Moves the window.
 void setMenuBar(javax.swing.JMenuBar menuBar)
          Sets the window's menubar.
 void show()
          Makes the window visible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZWindow


public ZWindow(java.lang.String title,
               ZObject gui)
In cooperation with operating system, creates a top level window. The window will contain just one ZObject. Use ZRow and ZCol to populate windows with multiple objects.

Parameters:
title - the window's title
gui - any ZObject

ZWindow


public ZWindow(java.lang.String title,
               ZObject gui,
               boolean visible)
In cooperation with operating system, creates a top level window. The window will contain just one ZObject. Use ZRow and ZCol to populate windows with multiple objects.

Parameters:
title - the window's title
gui - any ZObject
visible - true iff the window is to be visible when created
Method Detail

closeWindow


public final void closeWindow()
Closes window. To "close" means to get rid of forever.


setForegroundColor


public static final void setForegroundColor(java.awt.Color fg)
Defunct. Does nothing. Replace with Zio.setForegroundColor()


setBackgroundColor


public static final void setBackgroundColor(java.awt.Color bg)
Defunct. Does nothing. Replace with Zio.setBackgroundColor().


hide


public final void hide()
Makes the window invisible so a user will see no trace of it. Undo this effect with show().

hide() has no effect if only one window is visible. We keep one window on the screen (perhaps buried by other windows) to give the user the ability to stop the program by closing the last window.


show


public final void show()
Makes the window visible. Use after hide().


setLocation


public final void setLocation(int x,
                              int y)
Moves the window. Enter the coordinates of the new upper left hand corner. Note that setLocation(0,0) would put the window in upper left of the screen.

Parameters:
x - horizontal coordinate, positive direction is to left
y - vertical coordinate, positive direction is downward

fullScreen


public final void fullScreen()
Makes window's minimum size full_screen. Default is a calculated size based on the minimum sizes of the components.


setMenuBar


public final void setMenuBar(javax.swing.JMenuBar menuBar)
Sets the window's menubar. Included for completeness but as yet untested.


epilog


protected void epilog()
This is invoked when a window closes (by the user or thru closeWindow()). Override it in a subclass if you want anything to happen.


author
context