Class GWin

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----GWin

public class GWin
extends Panel
This creates a window with one component, a Panel (this object), and resizes and shows it. The close box works, and keypresses on the title bar are passed through to the Panel. The paint() and handleEvent() methods should be overridden. The overridden paint() method should start with a call to super.paint(). To resize the window, set preferredSize, then call layout(). This code contains numerous hacks to overcome Java bugs. The goal was to ensure that on multiple platforms (or at least for both JDK1.0-Win95 and Netscape NN30b5a), the Panel would automatically expand to fill at least most of the window when the user resized the window, the setSize() method would resize the window such that the best-fitting Panel would be EXACTLY the requested size, and every paint would match the Panel size exactly.

This code is (c) 1996 Leemon Baird <leemon@cs.cmu.edu>, http://www.cs.cmu.edu/~baird
The source and object code may be redistributed freely. If the code is modified, please state so in the comments.

Version:
1.1 13 Feb 97
Author:
Leemon Baird

Variable Index

 o applet
the applet holding every embedded GWin
 o buttonPanel
the panel holding the button that toggles embedding
 o buttons
a panel holding the button panel
 o embedButton
the button toggling embedding on the Web page vs.
 o embedPanel
the panel containing this Panel and the embed button, # button, and menus
 o menubar
the menus that should attach to a window containing this GWin
 o preferredSize
The size to make this window when layout() is called
 o startHeight
the starting Height of the window
 o startSize
The original size of this Panel at the start
 o startWidth
the starting width of the window
 o startX
the starting column of the window
 o startY
the starting row of the window
 o watchButton
the button that brings up a window of everything watched here
 o window
the actual window holding this Panel object

Constructor Index

 o GWin()

Method Index

 o addMenus(MenuBar)
Override this to give a GWin menus.
 o closeWindow()
close the window and destroy all threads, Graphics contexts, etc.
 o createWin(int, int, int, int, Applet, boolean)
create a graphics window with upper-left corner at (x,y), and the graphics area of size (width,height).
 o destroy()
This is called when the user closes the window.
 o fHeight()
Return the font height
 o height()
height of graphics area in the window (not including title bar)
 o menuToChoice(MenuBar)
convert a menubar into an equivalent Panel filled with a Choice corresponding to each menu.
 o MinimumSize()
return the size this window prefers
 o paint(Graphics)
Paint the region of size (bounds().width,bounds().height), and corner at (0,0).
 o preferredSize()
return the size this window prefers
 o width()
width of graphics area in the window (not including title bar)
 o x()
x coordinate of upper-left corner of whole window (including title)
 o y()
y coordinate of upper-left corner of whole window (including title)

Variables

 o preferredSize
 protected Dimension preferredSize
The size to make this window when layout() is called

 o startSize
 protected Dimension startSize
The original size of this Panel at the start

 o window
 public ClosableWin window
the actual window holding this Panel object

 o embedPanel
 public EmbedPanel embedPanel
the panel containing this Panel and the embed button, # button, and menus

 o embedButton
 public Button embedButton
the button toggling embedding on the Web page vs. separate window

 o watchButton
 public Button watchButton
the button that brings up a window of everything watched here

 o applet
 public Applet applet
the applet holding every embedded GWin

 o buttonPanel
 public Panel buttonPanel
the panel holding the button that toggles embedding

 o buttons
 public Panel buttons
a panel holding the button panel

 o startX
 public int startX
the starting column of the window

 o startY
 public int startY
the starting row of the window

 o startWidth
 public int startWidth
the starting width of the window

 o startHeight
 public int startHeight
the starting Height of the window

 o menubar
 public MenuBar menubar
the menus that should attach to a window containing this GWin

Constructors

 o GWin
 public GWin()

Methods

 o paint
 public void paint(Graphics g)
Paint the region of size (bounds().width,bounds().height), and corner at (0,0). This method should be overridden, but the new method should still call window.layout() first, and should assume the region to draw starts at (0,0) and is of size (width(),height()).

Overrides:
paint in class Container
 o closeWindow
 public void closeWindow()
close the window and destroy all threads, Graphics contexts, etc.

 o fHeight
 public int fHeight()
Return the font height

 o addMenus
 public void addMenus(MenuBar mb)
Override this to give a GWin menus. Menus are only visible when it's a separate window, not when embedded in the Web page. The menus should be added to mb.

 o createWin
 public void createWin(int x,
                       int y,
                       int width,
                       int height,
                       Applet app,
                       boolean embed)
create a graphics window with upper-left corner at (x,y), and the graphics area of size (width,height). If embed==true, meaning the GWin should be embedded in the web page, then it sets the preferred size of this Panel, but doesn't actually create a new window. To add menus to a GWin window, override addMenus().

 o menuToChoice
 public Panel menuToChoice(MenuBar mb)
convert a menubar into an equivalent Panel filled with a Choice corresponding to each menu.

 o destroy
 public void destroy()
This is called when the user closes the window. Override it to react to that event (e.g. kill threads, dispose of Graphics, unregister watches)

 o preferredSize
 public Dimension preferredSize()
return the size this window prefers

Overrides:
preferredSize in class Container
 o MinimumSize
 public Dimension MinimumSize()
return the size this window prefers

 o x
 public int x()
x coordinate of upper-left corner of whole window (including title)

 o y
 public int y()
y coordinate of upper-left corner of whole window (including title)

 o width
 public int width()
width of graphics area in the window (not including title bar)

 o height
 public int height()
height of graphics area in the window (not including title bar)