⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 applet1.java

📁 java rmi技术实例
💻 JAVA
字号:
// Copyright MageLang Institute; Version $Id: //depot/main/src/edu/modules/RMI-mml2/magercises/RMICallback/Solution/Applet1.java#2 $
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.Date;
import java.net.URL;
import java.rmi.*;
import java.rmi.server.*;

public

class Applet1

extends Applet

implements   TimeMonitor
{
   // Change this to your computer's name
   private final static String HOST_NAME = "ROSA";

   private TimeServer ts;

   public void init()
   {
      super.init();

      uiInit();

      try
      {
         System.out.println( "Exporting the Applet" );
         UnicastRemoteObject.exportObject( this );
         URL     base = getDocumentBase();

         String hostName = base.getHost();

         if ( 0 == hostName.length() )
         {
            hostName = HOST_NAME;
         }

         String  serverName = "rmi://" + hostName + ":" + getParameter( "registryPort" ) + "/TimeServer" ;


         System.out.println( "Looking up TimeService at: " + serverName );

         try
         {
            ts = (TimeServer)Naming.lookup( serverName );
         }
         catch ( Exception e )
         {
            System.out.println( "" + e );
         }

         ts.registerTimeMonitor( this );

         System.out.println( "We have been registered!" );

      }
      catch ( RemoteException re )
      {
         System.out.println( "" + re );
      }
	}

   public void tellMeTheTime( Date d )
   {
      textArea1.appendText( d.toString() + "\n" );
   }


   public void uiInit()
   {
      setLayout(null);
      resize(456,266);
      textArea1 = new java.awt.TextArea();
      textArea1.reshape(36,24,252,170);
      add(textArea1);

      button1 = new java.awt.Button("Clear");
      button1.reshape(324,36,72,24);
      add(button1);

      button1.addActionListener
      (
         new ActionListener()
         {

            public void actionPerformed(ActionEvent event)
            {
               textArea1.setText("");
            }
         }
      );



   }

   java.awt.TextArea textArea1;
   java.awt.Button button1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -