01: /*
02: *******************************************************************************
03: * Copyright (C) 1997-2004, International Business Machines Corporation and *
04: * others. All Rights Reserved. *
05: *******************************************************************************
06: */
07:
08: package com.ibm.icu.dev.demo.impl;
09:
10: import java.awt.*;
11: import java.awt.event.*;
12:
13: public abstract class DemoApplet extends java.applet.Applet {
14: private Button demoButton;
15: private Frame demoFrame;
16: private static int demoFrameCount = 0;
17:
18: protected abstract Frame createDemoFrame(DemoApplet applet);
19:
20: protected Dimension getDefaultFrameSize(DemoApplet applet, Frame f) {
21: return new Dimension(700, 550);
22: }
23:
24: //Create a button that will display the demo
25: public void init() {
26: setBackground(Color.white);
27: demoButton = new Button("Demo");
28: demoButton.setBackground(Color.yellow);
29: add(demoButton);
30:
31: demoButton.addActionListener(new ActionListener() {
32: public void actionPerformed(ActionEvent e) {
33: if (e.getID() == ActionEvent.ACTION_PERFORMED) {
34: demoButton.setLabel("loading");
35:
36: if (demoFrame == null) {
37: demoFrame = createDemoFrame(DemoApplet.this );
38: showDemo();
39: }
40:
41: demoButton.setLabel("Demo");
42: }
43: }
44: });
45: }
46:
47: public void showDemo() {
48: demoFrame = createDemoFrame(this );
49: demoFrame.doLayout();
50: Dimension d = getDefaultFrameSize(this , demoFrame);
51: demoFrame.setSize(d.width, d.height);
52: demoFrame.show();
53: demoFrameOpened();
54: }
55:
56: public void demoClosed() {
57: demoFrame = null;
58: demoFrameClosed();
59: }
60:
61: protected static void demoFrameOpened() {
62: demoFrameCount++;
63: }
64:
65: protected static void demoFrameClosed() {
66: if (--demoFrameCount == 0) {
67: System.exit(0);
68: }
69: }
70: }
|