|
/*
* An application to run the double buffer
* applet example.
*/
import java.awt.*;
import java.awt.event.*;
public class
DBAppletHolder extends Frame
implements ActionListener{
public
static void main(String [] args){
// Pass the image name as a command line
argument
if( args.length != 1) {
System.out.println(
"Usage:
java DBAppletHolder imageFilename");
System.exit(0);
}
// Create an instance of this frame class
// for holding the applet
DBAppletHolder h= new DBAppletHolder();
// Create an instance of the applet
DoubleBufferedClipped DBApplet = new
DoubleBufferedClipped();
// Call init() to do
whatever initialization can be
// done outside of a browser environment.
DBApplet.init();
// Pass the applet the
image name
DBApplet.initImg(args[0]);
h.add("Center", DBApplet);
// Use an adapter to
close the window
WindowListener listener = new WindowAdapter()
{
public void windowClosing(WindowEvent
e){
System.exit(0);
}
};
h.addWindowListener(listener);
h.pack();
h.show();
}
// Add a menubar with only the
Quit item.
DBAppletHolder() {
setTitle("Hello World");
Menu m = new Menu("File");
MenuItem mi = new MenuItem( "Quit" );
mi.addActionListener( this );
m.add(mi);
MenuBar mb = new MenuBar();
mb.add(m);
setMenuBar(mb);
}
// Catch the Quit menuItem event
to close the window.
public void actionPerformed( ActionEvent e ) {
if ( e.getActionCommand().equals("Quit") )
dispose();
System.exit(0);
}
}
|