/** * Computer Graphics, Assignment 1, Exercise 3 * Richard Cyganiak * * The applet shows a button labeled "Open window". * Clicking the button opens a new window with some text. **/ import java.awt.*; import java.awt.event.*; public class SimpleWindowApplet extends java.applet.Applet { /** * The applet initialisation method. It just adds a button. **/ public void init() { Button b = new Button("Open window"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Open window")) { openWindow(); } } }); add(b); } /** * Executed when the button is pressed. Opens a new window, * which contains a label and can be closed. **/ private void openWindow() { final Frame f = new Frame("Simple Demo Window"); f.setLayout(new FlowLayout()); f.add(new Label("I am a window.")); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { f.dispose(); } }); f.pack(); f.show(); } }