📄 rmiclient2.java
字号:
import java.awt.Color;import java.awt.BorderLayout;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.net.*;import java.rmi.*;import java.rmi.server.*;class RMIClient2 extends JFrame implements ActionListener { JLabel text, clicked; JButton button; JPanel panel; JTextArea textArea; Socket socket = null; PrintWriter out = null; static Send send; RMIClient2(){ //Begin Constructor text = new JLabel("Text received:"); textArea = new JTextArea(); button = new JButton("Click Me"); button.addActionListener(this); panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBackground(Color.white); getContentPane().add(panel); panel.add("North", text); panel.add("Center", textArea); panel.add("South", button); } //End Constructor public void actionPerformed(ActionEvent event){ Object source = event.getSource(); if(source == button){ try{ String text = send.getData(); textArea.append(text); } catch (java.rmi.RemoteException e) { System.out.println("Cannot access data in server"); } } } public static void main(String[] args){ RMIClient2 frame = new RMIClient2(); frame.setTitle("Client Two"); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; frame.addWindowListener(l); frame.pack(); frame.setVisible(true); if(System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } try { String name = "//" + args[0] + "/Send"; send = ((Send) Naming.lookup(name)); } catch (java.rmi.NotBoundException e) { System.out.println("Cannot access data in server"); } catch(java.rmi.RemoteException e){ System.out.println("Cannot access data in server"); } catch(java.net.MalformedURLException e) { System.out.println("Cannot access data in server"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -