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