home *** CD-ROM | disk | FTP | other *** search
/ Internet News 1999 October / INEWS_10_CD.ISO / pc / jdk / jdk1.2.2 / docs / guide / intl / sample / IMFDemo.java < prev    next >
Encoding:
Java Source  |  1999-09-19  |  1.7 KB  |  68 lines

  1. /*
  2.  * @(#)IMFDemo.java    1.2 98/06/05
  3.  * 
  4.  * Copyright 1997-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  */
  8.  
  9. import java.applet.Applet;
  10. import java.awt.Frame;
  11. import java.awt.GridLayout;
  12. import java.awt.event.WindowAdapter;
  13. import java.awt.event.WindowEvent;
  14. import java.awt.event.WindowListener;
  15.  
  16. public class IMFDemo extends Applet {
  17.  
  18.     public void init() {
  19.         addComponents();
  20.     }
  21.     
  22.     public void start() {
  23.     }
  24.     
  25.     public void stop() {
  26.     }
  27.     
  28.     public void addComponents() {
  29.         setLayout(new GridLayout(4, 1, 10, 10));
  30.         add(new LWTextComponent("Lightweight component, non-client", false));
  31.         add(new LWTextComponent("Lightweight component, passive client", true));
  32.         add(new ActiveClient("Lightweight component, active client"));
  33.         add(new PeeredTextArea());
  34.     }
  35.  
  36.     public static void main(String argv[]) {
  37.         final IMFDemo applet = new IMFDemo();
  38.         applet.init();
  39.         applet.start();
  40.         makeFrame(applet, "Input Method Framework Demo");
  41.     }
  42.  
  43.     public static void makeFrame(Applet applet, String title) {
  44.         Frame frame = new Frame(title);
  45.         frame.pack(); // adds peer
  46.         frame.add("Center", applet);
  47.         frame.setSize(400, 400);
  48.         WindowListener listener = new AppletWindowListener(applet);
  49.         frame.addWindowListener(listener);
  50.         frame.pack();
  51.         frame.show();
  52.     }
  53. }
  54.  
  55. class AppletWindowListener extends WindowAdapter {
  56.  
  57.     private Applet applet;
  58.  
  59.     AppletWindowListener(Applet applet) {
  60.         this.applet = applet;
  61.     }
  62.  
  63.     public void windowClosing(WindowEvent e) {
  64.         e.getWindow().dispose();
  65.         System.exit(0);
  66.     }
  67. }
  68.