|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
javax.swing.JApplet
net.pacbell.jfai.toh.util.AbstractJMainFrame
public abstract class AbstractJMainFrame
Inherit from this class to enable a program to run as an applet and as an
application. Loosely cloned from
JMainFrame ,
which seems to have problems with redraws, probably because it manipulates
Swing components outside of the event dispatch thread.
Applets : you can override init().
For an application , implement a main method in YourClass like:
public abstract main(String[] args) { new YourClass(args); }
You may also call YourClass(args, width, height) if either
width or height should have a default value. In either case, width and
height may be overridden using width= or height=
as invocation arguments.
Constructors with arguments parse the invocation arguments, and then call
buildWindow() to construct a root container, and display it.
Override
initialize to
execute setup code after argument parsing but before anything else happens
during instance creation, like:
protected void initialize(String[] args) {
super initialize(args); // parse arguments
// YourClass initialization goes here
}
Use
setErrorComponent
if a problem is detected during setup. If the error component is not null,
then
buildContentPane
is skipped and the error component is displayed instead.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JApplet |
|---|
JApplet.AccessibleJApplet |
| Nested classes/interfaces inherited from class java.applet.Applet |
|---|
Applet.AccessibleApplet |
| Nested classes/interfaces inherited from class java.awt.Panel |
|---|
Panel.AccessibleAWTPanel |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
static String |
ARGUMENT_HEIGHT
Invocation argument name for the window height. |
static String |
ARGUMENT_WIDTH
Invocation argument name for the window width. |
| Fields inherited from class javax.swing.JApplet |
|---|
accessibleContext, rootPane, rootPaneCheckingEnabled |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
AbstractJMainFrame()
(Applet) Creates a new instance. |
|
AbstractJMainFrame(String[] args)
(Application) Creates a new instance, parses the given arguments, creates a root container, constructs its content pane (or uses the error component), and displays the window with default size. |
|
AbstractJMainFrame(String[] args,
int width,
int height)
(Application) Creates a new instance, parses the given arguments, creates a root container, constructs its content pane (or uses the error component), and displays the window with the given size. |
|
| Method Summary | |
|---|---|
protected void |
addListeners(JFrame frame)
(Application) Registers listeners with the root container, such as window event listeners. |
protected abstract void |
buildContentPane(Container contentPane)
(Application and Applet) Constructs the contents of the given content pane of a root container. |
protected void |
buildWindow(int width,
int height)
(Application) Creates a frame as root
container and adds a panel. |
static String |
getArgument(String name)
(Application) Returns the value of the named argument, if it was found in the properties list. |
static String |
getArgument(String name,
Properties someProperties)
(Application) Returns the value of the named argument, if it was found in the given properties list. |
protected Component |
getErrorComponent()
Gets the errorComponent. |
protected boolean |
hasErrorComponent()
Checks if an error component is present. |
void |
init()
(Applet) Performs initialization. |
protected void |
initialize(String[] args)
(Application and Applet) Parses the given arguments. |
static void |
parseArguments(String[] args,
Properties someProperties)
(Application) Parses the list of argument strings and adds key-value pairs into the specified properties list. |
protected static int |
parseHeightArgument(int height,
Properties someProperties)
Checks if height was specified as an invocation argument, e.g. |
protected static int |
parseWidthArgument(int width,
Properties someProperties)
Checks if width was specified as an invocation argument, e.g. |
static void |
resize(Container frame,
int width,
int height,
Properties someProperties)
(Application) Resizes the given container. |
protected void |
setErrorComponent(Component errorComponent)
Sets the errorComponent. |
void |
usage()
Writes the usage messageto System.err, then
exitswith code -1. |
void |
usage(String message)
Writes the given string to System.err, followed by
the usage message, then
exitswith code -1. |
abstract String |
usageMessage()
Answers a string describing how to invoke the application correctly. |
String |
windowTitle()
(Application) Answers a String for the title bar of the main window. |
| Methods inherited from class javax.swing.JApplet |
|---|
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, remove, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update |
| Methods inherited from class java.applet.Applet |
|---|
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop |
| Methods inherited from class java.awt.Panel |
|---|
addNotify |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String ARGUMENT_HEIGHT
public static final String ARGUMENT_WIDTH
| Constructor Detail |
|---|
public AbstractJMainFrame()
public AbstractJMainFrame(String[] args)
args - the invocation arguments
public AbstractJMainFrame(String[] args,
int width,
int height)
args - the invocation argumentswidth - the window width (if >= 0)height - the window height (if >= 0)| Method Detail |
|---|
public static String getArgument(String name)
name - a string - case is insignificant
public static String getArgument(String name,
Properties someProperties)
name - a string - case is insignificantsomeProperties - a Properties
public static void parseArguments(String[] args,
Properties someProperties)
args - the argument stringssomeProperties - a Properties
public static void resize(Container frame,
int width,
int height,
Properties someProperties)
If width and/or height argument properties were specified or the last two parameters are greater than -1, set the size of the given container.
If the parameter values are invalid integers, a
NumberFormatExceptionis thrown.
frame - a Containerwidth - the width of the frame (if >= 0)height - the height of the frame (if >= 0)someProperties - a Properties
protected static int parseHeightArgument(int height,
Properties someProperties)
System.errand the result is the given height parameter. If
there is no height invocation argument, the result is the given height
parameter.
height - the default window heightsomeProperties - a Properties
protected static int parseWidthArgument(int width,
Properties someProperties)
System.errand the result is the given width parameter. If
there is no width invocation argument, the result is the given width
parameter.
width - the default window widthsomeProperties - a Properties
public void init()
initialize, then the error component is
added to the panel. If there is no error component, then
buildContentPane
is called.
init in class ApplethasErrorComponent(),
setErrorComponent(Component),
getErrorComponent(),
Applet.init()public void usage()
System.err, then
exitswith code -1.
public void usage(String message)
System.err, followed by
the usage message, then
exitswith code -1.
message - a stringpublic abstract String usageMessage()
Override to provide something like:
Usage: YourClass arg1 arg2, where arg1 is...
public String windowTitle()
protected void addListeners(JFrame frame)
destroy and
exits with code 0.
frame - the frameprotected abstract void buildContentPane(Container contentPane)
contentPane - the content pane of a container
protected void buildWindow(int width,
int height)
frame as root
container and adds a panel. If an error
component was set during initialize, then
the error component is added to the panel. If there is no error
component, then
buildContentPane
is called to construct the content pane. The window is made visible. If
width and/or height are >= 0, they'll determine the window size.
width - window width (if >= 0)height - window height (if >= 0)windowTitle(),
addListeners(JFrame),
resize(Container,int,int,Properties),
hasErrorComponent(),
setErrorComponent(Component),
getErrorComponent()protected void initialize(String[] args)
args - The invocation arguments. If args parameter is null, then
the instance is an applet.protected boolean hasErrorComponent()
protected Component getErrorComponent()
protected void setErrorComponent(Component errorComponent)
errorComponent - The errorComponent to set.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||