📄 helloapplet.java
字号:
package helloinapplet;import java.awt.*;import java.awt.event.*;import java.applet.*;import java.rmi.*;public class helloApplet extends Applet { boolean isStandalone = false; String message = "blank"; //"obj" is the identifier that we'll use to refer //to the remote object that implements the "Hello" //interface private Button button1 = new Button(); private Label label1 = new Label(); //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construct the applet public helloApplet() { } //Initialize the applet public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { button1.setLabel("Click me"); //设计布局 button1.setBounds(new Rectangle(120, 143, 91, 29)); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); this.setLayout(null); label1.setBounds(new Rectangle(105, 90, 395, 31)); this.add(button1, null); this.add(label1, null); } public void paint(Graphics g){ g.drawString("", 25, 50); } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { return null; } void button1_actionPerformed(ActionEvent e) { try { label1.setText("正在连接RMI主机..."); hello obj = (hello)Naming.lookup("rmi://127.0.0.1/HelloWorld"); //寻找RMI主机的相应服务 message = obj.sayHello(); //调用远程函数 label1.setText(message); //显示结果 } catch (Exception e1) { label1.setText("Error: " + e1); //捕捉异常情况 } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -