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

📄 helloclientframe.java

📁 java网络编程 包含全书所有代码编程以及实例
💻 JAVA
字号:
package rmisocket;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.rmi.*;import java.rmi.server.*;import java.rmi.registry.*;import java.net.*;import java.io.*;public class helloClientFrame extends JFrame {  private JPanel contentPane;  private Button button1 = new Button();  private Label label1 = new Label();  //Construct the frame  public helloClientFrame() {    enableEvents(AWTEvent.WINDOW_EVENT_MASK);    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  //Component initialization  private void jbInit() throws Exception  {    contentPane = (JPanel) this.getContentPane();          //设计布局    button1.setLabel("连接主机");    button1.setBounds(new Rectangle(114, 181, 112, 33));    button1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    contentPane.setLayout(null);    this.setSize(new Dimension(338, 272));    this.setTitle("RMI套接字客户机");    label1.setBounds(new Rectangle(103, 102, 190, 32));    contentPane.add(button1, null);    contentPane.add(label1, null);    RMISocketFactory.setSocketFactory(new RMISocketFoc());       //声明在此RMI远程调用中使用RMISocketFoc类型的通讯方法  }  //Overridden so we can exit when window is closed  protected void processWindowEvent(WindowEvent e) {    super.processWindowEvent(e);    if (e.getID() == WindowEvent.WINDOW_CLOSING) {      System.exit(0);    }  }  void button1_actionPerformed(ActionEvent e) {    String serverName = "";    System.setSecurityManager(new RMISecurityManager());       //建立一个安全管理器    try {      label1.setText("正在连接RMI主机...");      serverName = InetAddress.getLocalHost().getHostName();   //得到RMI服务器端的主机名      Hello myHello = (Hello)Naming.lookup("//" + serverName + "/HelloWorld");   //寻找RMI主机的相应服务      String d = myHello.sayHello();                           //调用远程函数      label1.setText(d);                                       //显示结果    }    catch(Exception e1) {      System.out.println("Error: " + e1);                     //捕捉异常情况    }  }}

⌨️ 快捷键说明

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