home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / International / sampleime / SampleIMETest.java < prev    next >
Encoding:
Java Source  |  2000-05-04  |  7.2 KB  |  188 lines

  1. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  2. //******************************************************************************
  3. // SampelIMETest.java:  Applet
  4. // When running this applet, click on the TextField, and type the hex value of
  5. //   the unicode, the corresponding unicode character will go to
  6. //   the TextField.
  7. // The composition window could be dragged. When you click on the button on
  8. //   the left of the composition window, you could enable/disable the IME.
  9. //******************************************************************************
  10. import java.applet.*;
  11. import java.awt.*;
  12. import java.awt.event.* ;
  13. import SampleIMETestFrame;
  14. import com.ms.util.InputMethod.* ;
  15. //import com.ms.awt.peer.* ;
  16.  
  17. import com.ms.ui.* ;
  18.  
  19. //==============================================================================
  20. // Main Class for applet SampleIMETest
  21. //
  22. //==============================================================================
  23. public class SampleIMETest extends Applet implements ActionListener
  24. {
  25.     // STANDALONE APPLICATION SUPPORT:
  26.     //      m_fStandAlone will be set to true if applet is run standalone
  27.     //--------------------------------------------------------------------------
  28.     boolean m_fStandAlone = false;
  29.  
  30.     private InputManagerListener imm ;
  31.         // System Default InputMethod Manager.
  32.     private InputMethodListener ime ;
  33.         // Sample IME.
  34.         
  35.     // STANDALONE APPLICATION SUPPORT
  36.     //  The main() method acts as the applet's entry point when it is run
  37.     // as a standalone application. It is ignored if the applet is run from
  38.     // within an HTML page.
  39.     //--------------------------------------------------------------------------
  40.     public static void main(String args[])
  41.     {
  42.         // Create Toplevel Window to contain applet UIInputMethod
  43.         //----------------------------------------------------------------------
  44.         SampleIMETestFrame frame = new SampleIMETestFrame("UIInputMethod");
  45.  
  46.         // Must show Frame before we size it so insets() will return valid values
  47.         //----------------------------------------------------------------------
  48.         frame.show();
  49.         //frame.setVisible( false );
  50.         frame.hide();
  51.         frame.resize(frame.insets().left + frame.insets().right  + 400,
  52.                      frame.insets().top  + frame.insets().bottom + 300);
  53.  
  54.         // The following code starts the applet running within the frame window.
  55.         // It also calls GetParameters() to retrieve parameter values from the
  56.         // command line, and sets m_fStandAlone to true to prevent init() from
  57.         // trying to get them from the HTML page.
  58.         //----------------------------------------------------------------------
  59.         SampleIMETest applet_UIInputMethod = new SampleIMETest();
  60.  
  61.         frame.add("Center", applet_UIInputMethod);
  62.         applet_UIInputMethod.m_fStandAlone = true;
  63.         applet_UIInputMethod.init();
  64.         applet_UIInputMethod.start();
  65.         frame.show();
  66.     }
  67.  
  68.     // UIInputMethod Class Constructor
  69.     //--------------------------------------------------------------------------
  70.     public SampleIMETest()
  71.     {
  72.         // TODO: Add constructor code here
  73.     }
  74.  
  75.     // APPLET INFO SUPPORT:
  76.     //      The getAppletInfo() method returns a string describing the applet's
  77.     // author, copyright date, or miscellaneous information.
  78.         //--------------------------------------------------------------------------
  79.     public String getAppletInfo()
  80.     {
  81.         return "Name: UIInputMethod\r\n" +
  82.                "Created with Microsoft Visual J++ Version 1.0";
  83.     }
  84.  
  85.  
  86.     // The init() method is called by the AWT when an applet is first loaded or
  87.     // reloaded.  Override this method to perform whatever initialization your
  88.     // applet needs, such as initializing data structures, loading images or
  89.     // fonts, creating frame windows, setting the layout manager, or adding UI
  90.     // components.
  91.     //--------------------------------------------------------------------------
  92.     public void init()
  93.     {
  94.         resize(320, 240);
  95.  
  96.         // Create TextField and TextArea.
  97.         Panel panel1 = new Panel() ;
  98.         TextField text = new TextField( 20 ) ;
  99.         text.setFont( new Font( "Courier", Font.PLAIN, 20 ) ) ;
  100.         panel1.add( new Label( "TextField:" ) ) ;
  101.         panel1.add( text ) ;
  102.  
  103.         Panel panel2 = new Panel() ;
  104.         TextArea textArea = new TextArea( 5, 20 ) ;
  105.         panel2.add( new Label( "TextArea:" ) ) ;
  106.         textArea.setFont( new Font( "Courier", Font.PLAIN, 20 ) ) ;
  107.         panel2.add( textArea ) ;
  108.         add( panel1 ) ; add( panel2 ) ;
  109.         Button SampleIMEButton = new Button( "Click here to activate Sample IME" ) ;
  110.         SampleIMEButton.addActionListener( this ) ;
  111.  
  112.         add( SampleIMEButton ) ;
  113.     }
  114.  
  115.     // Place additional applet clean up code here.  destroy() is called when
  116.     // when you applet is terminating and being unloaded.
  117.     //-------------------------------------------------------------------------
  118.     public void destroy()
  119.     {
  120.         // TODO: Place applet cleanup code here
  121.     }
  122.  
  123.     // UIInputMethod Paint Handler
  124.     //--------------------------------------------------------------------------
  125.     public void paint(Graphics g)
  126.     {
  127.         //if ( ime != null )
  128.         //    ime.activate() ;
  129.     }
  130.  
  131.     //      The start() method is called when the page containing the applet
  132.     // first appears on the screen. The AppletWizard's initial implementation
  133.     // of this method starts execution of the applet's thread.
  134.     //--------------------------------------------------------------------------
  135.     public void start()
  136.     {
  137.         // TODO: Place additional applet start code here
  138.     }
  139.     
  140.     //      The stop() method is called when the page containing the applet is
  141.     // no longer on the screen. The AppletWizard's initial implementation of
  142.     // this method stops execution of the applet's thread.
  143.     //--------------------------------------------------------------------------
  144.     public void stop()
  145.     {
  146.         if ( ime != null )
  147.         {
  148.             ime.deactivate() ;
  149.             imm.setInputMethod( null ) ;
  150.             imm.removeInputMethod( ime ) ;  
  151.                 // Remove the IME from the IMM maintained list. Otherwise
  152.                 // IME will be still available for other applets.
  153.         }
  154.     }
  155.     // TODO: Place additional applet code here
  156.  
  157.  
  158.     void activateIME()
  159.     {
  160.         System.out.println( "activateIME" ) ;
  161.         if ( ime == null )
  162.         {
  163.             // Get DefaultInputManager.
  164.             imm = com.ms.lang.SystemX.getDefaultInputManager() ;
  165.             com.ms.lang.SystemX.setInputManager( imm, true ) ;
  166.             
  167.             if ( imm != null )
  168.             {
  169.                 // Create a new IME.
  170.                 ime = new SampleIME() ;
  171.                 // Set the SampleIME as current IME.
  172.                 imm.setInputMethod( ime ) ;
  173.                 ime.activate() ;
  174.             }
  175.         } else
  176.         {
  177.             imm.setInputMethod( ime ) ;
  178.             ime.activate() ;        
  179.         }
  180.     }
  181.     
  182.     public void actionPerformed(ActionEvent e)
  183.     {
  184.         activateIME() ;
  185.     }
  186. }
  187.  
  188.