1 /* 2 ******************************************************************************* 3 * Copyright (C) 1997-2010, International Business Machines Corporation and * 4 * others. All Rights Reserved. * 5 ******************************************************************************* 6 */ 7 8 package com.ibm.icu.dev.demo.impl; 9 10 import java.awt.Button; 11 import java.awt.Color; 12 import java.awt.Dimension; 13 import java.awt.Frame; 14 import java.awt.event.ActionEvent; 15 import java.awt.event.ActionListener; 16 17 public abstract class DemoApplet extends java.applet.Applet { 18 private static final long serialVersionUID = -8983602961925702071L; 19 private Button demoButton; 20 private Frame demoFrame; 21 private static int demoFrameCount = 0; 22 createDemoFrame(DemoApplet applet)23 protected abstract Frame createDemoFrame(DemoApplet applet); getDefaultFrameSize(DemoApplet applet, Frame f)24 protected Dimension getDefaultFrameSize(DemoApplet applet, Frame f) { 25 return new Dimension(700, 550); 26 } 27 28 //Create a button that will display the demo init()29 public void init() 30 { 31 setBackground(Color.white); 32 demoButton = new Button("Demo"); 33 demoButton.setBackground(Color.yellow); 34 add( demoButton ); 35 36 demoButton.addActionListener( new ActionListener() { 37 public void actionPerformed(ActionEvent e) { 38 if (e.getID() == ActionEvent.ACTION_PERFORMED) { 39 demoButton.setLabel("loading"); 40 41 if (demoFrame == null) { 42 demoFrame = createDemoFrame(DemoApplet.this); 43 showDemo(); 44 } 45 46 demoButton.setLabel("Demo"); 47 } 48 } 49 } ); 50 } 51 showDemo()52 public void showDemo() 53 { 54 demoFrame = createDemoFrame(this); 55 demoFrame.doLayout(); 56 Dimension d = getDefaultFrameSize(this, demoFrame); 57 demoFrame.setSize(d.width, d.height); 58 demoFrame.show(); 59 demoFrameOpened(); 60 } 61 demoClosed()62 public void demoClosed() 63 { 64 demoFrame = null; 65 demoFrameClosed(); 66 } 67 demoFrameOpened()68 public static void demoFrameOpened() { 69 demoFrameCount++; 70 System.err.println("DemoFrameOpened, now at:"+demoFrameCount); 71 } demoFrameClosed()72 public static void demoFrameClosed() { 73 if (--demoFrameCount == 0) { 74 System.err.println("DemoFrameClosed, now at:"+demoFrameCount + " - quitting"); 75 System.exit(0); 76 } 77 System.err.println("DemoFrameClosed, now at:"+demoFrameCount); 78 } 79 } 80 81