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 10package com.ibm.icu.dev.demo.impl; 11 12import java.awt.Button; 13import java.awt.Color; 14import java.awt.Dimension; 15import java.awt.Frame; 16import java.awt.event.ActionEvent; 17import java.awt.event.ActionListener; 18 19public 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 25 protected abstract Frame createDemoFrame(DemoApplet applet); 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 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 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 64 public void demoClosed() 65 { 66 demoFrame = null; 67 demoFrameClosed(); 68 } 69 70 public static void demoFrameOpened() { 71 demoFrameCount++; 72 System.err.println("DemoFrameOpened, now at:"+demoFrameCount); 73 } 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