📄 rmiservertestframe.java
字号:
package ntis.com.util;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.rmi.Naming;
import java.util.StringTokenizer;
import ntis.com.base.RmiServer;
public class RmiServerTestFrame extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JTextField command = new JTextField();
JPanel jPanel1 = new JPanel();
Border border1;
Border border2;
TitledBorder titledBorder1;
JScrollPane jScrollPane1 = new JScrollPane();
GridBagLayout gridBagLayout1 = new GridBagLayout();
JButton lookupBtn = new JButton();
JTextArea console = new JTextArea();
JButton MethodBtn = new JButton();
JButton exitBtn = new JButton();
/**僼儗乕儉偺峔抸*/
public RmiServerTestFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**僐儞億乕僱儞僩偺弶婜壔*/
private void jbInit() throws Exception {
border1 = BorderFactory.createEmptyBorder();
border2 = BorderFactory.createEmptyBorder();
titledBorder1 = new TitledBorder("");
jLabel1.setText("command:");
//setIconImage(Toolkit.getDefaultToolkit().createImage(RmiServerTestFrame.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(gridBagLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Rmi Server Test");
jPanel1.setBorder(titledBorder1);
jPanel1.setLayout(gridBagLayout2);
lookupBtn.setText("Lookup");
lookupBtn.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
lookupBtn_mouseClicked(e);
}
});
MethodBtn.setText("Method");
MethodBtn.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
MethodBtn_mouseClicked(e);
}
});
exitBtn.setText("Exit");
exitBtn.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
exitBtn_mouseClicked(e);
}
});
contentPane.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
contentPane.add(command, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
contentPane.add(jPanel1, new GridBagConstraints(2, 0, 1, 2, 0.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 2510));
jPanel1.add(lookupBtn, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
jPanel1.add(MethodBtn, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
jPanel1.add(exitBtn, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 22, 0));
jPanel1.add(jPanel2, new GridBagConstraints(0, 3, 1, 1, 0.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0));
contentPane.add(jScrollPane1, new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
jScrollPane1.getViewport().add(console, null);
}
/**僂傿儞僪僂偑暵偠傜傟偨偲偒偵廔椆偡傞傛偆偵僆乕僶乕儔僀僪*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
private RmiServer rmiServer = null;
GridBagLayout gridBagLayout2 = new GridBagLayout();
JPanel jPanel2 = new JPanel();
void lookupBtn_mouseClicked(MouseEvent e) {
try {
rmiServer = (RmiServer)Naming.lookup(command.getText());
console.append("Lookup!\n");
}
catch(Exception ex) {
console.append(ex.getClass().getName() + "\n");
console.append(ex.getMessage() + "\n");
}
}
void MethodBtn_mouseClicked(MouseEvent e) {
try {
StringTokenizer st = new StringTokenizer(command.getText(), ",");
String[] params = (st.countTokens() - 1 > 0 ? new String[st.countTokens() - 1] : null);
int type = Integer.parseInt(st.nextToken());
if(params != null) {
for(int i = 0; i < params.length; i++) {params[i] = st.nextToken();}
}
Object[] obj = rmiServer.request(type, params);
console.append("Method Call!\n");
console.append("return\n");
if(obj != null) {
for(int i = 0; i < obj.length; i++) {console.append((String)obj[i] + "\n");}
}
console.append("return end\n");
}
catch(Exception ex) {
console.append(ex.getClass().getName() + "\n");
console.append(ex.getMessage() + "\n");
}
}
void exitBtn_mouseClicked(MouseEvent e) {
try {
rmiServer.exit();
console.append("Rmi Server Exit!\n");
}
catch(Exception ex) {
console.append(ex.getClass().getName() + "\n");
console.append(ex.getMessage() + "\n");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -