home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 November
/
Chip_1998-11_cd.bin
/
tema
/
Cafe
/
Source.bin
/
Demo.java
< prev
next >
Wrap
Text File
|
1998-03-18
|
4KB
|
206 lines
package symantec.itools.demo;
import java.applet.Applet;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.LayoutManager;
import symantec.itools.awt.util.Util;
/**
* A demonstration Applet class.
*
* @version 1.0, Nov 26, 1996
*
* @author Symantec
*/
public abstract class Demo
extends Applet
{
/**
* Frame title.
*/
protected String title;
/**
* True if this class is invoked as an Applet.
*/
protected boolean isApplet;
/**
* This program's frame.
*/
protected DemoFrame frame;
/**
* The frame horizontal position, in pixels.
*/
protected int xPos;
/**
* The frame vertical position, in pixels.
*/
protected int yPos;
/**
* The frame width, in pixels.
*/
protected int width;
/**
* The frame height, in pixels.
*/
protected int height;
/**
* Constucts the Demo object.
* @param s the frame title
* @param x the frame horizontal position, in pixels
* @param y the frame vertical position, in pixels
* @param w the frame width, in pixels
* @param h the frame height, in pixels
*/
public Demo(String s, int x, int y, int w, int h)
{
title = s;
xPos = x;
yPos = y;
width = w;
height = h;
}
/**
* Called by the Applet viewer to initialize this applet.
* @see java.applet.Applet#init
*/
public void init()
{
isApplet = true;
setup();
frame.show();
}
/**
* Called to initialize this object if it is not an applet.
*/
protected void driver()
{
isApplet = false;
setup();
frame.show();
}
/**
* Shared setup code.
*/
protected void setup()
{
frame = new DemoFrame(this, title);
frame.reshape(xPos, yPos, width, height);
frame.setLayout(new FlowLayout());
}
/**
* Called to end this demo.
*/
public void endDemo()
{
if(isApplet)
{
stop();
}
else
{
System.exit(0);
}
}
/**
* Hides and disposes the frame.
*/
public void cleanup()
{
frame.hide();
frame.dispose();
}
/**
* Hides and disposes the frame, then exits.
*/
public void doExit()
{
cleanup();
endDemo();
}
/**
* Handles demo help requests.
*/
public void doHelp()
{
}
/**
* Handles demo "About..." requests.
*/
public void doAbout()
{
}
/**
* Reinitializes the demo.
*/
public void doRestart()
{
cleanup();
setup();
}
public Component add(Component c)
{
return (frame.add(c));
}
public synchronized Component add(Component c, int i)
{
return (frame.add(c, i));
}
public synchronized Component add(String s, Component c)
{
return (frame.add(s, c));
}
public void setLayout(LayoutManager manager)
{
if(frame != null)
{
frame.setLayout(manager);
}
}
public Graphics getGraphics()
{
return frame.getGraphics();
}
/**
* Gets the font to use for this Demo.
* @return the font
*/
public Font getFont()
{
Font font;
if(frame != null)
{
font = frame.getFont();
font = (font == null) ? Util.getDefaultFont() : font;
}
else
{
font = Util.getDefaultFont();
}
return font;
}
}