📄 serverinfoinputdialog.java
字号:
package client.ds;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.NumberFormat;
import javax.swing.*;
import client.tools.Tools;
public class ServerInfoInputDialog extends JDialog {
/**
*
*/
private static final long serialVersionUID = 7417754602967967464L;
public static final int OK_OPTION = 0;
public static final int CANCEL_OPTION = 1;
private JTextField txtHostname;
private JTextField txtRmiObjName;
private JFormattedTextField txtPort;
private JFormattedTextField txtPort1;
private JFormattedTextField lagsSec;
private int option;
public ServerInfoInputDialog(Frame parent) {
super(parent, "Input Server Info", true);
option = CANCEL_OPTION;
setContentPane();
this.pack();
Tools.center(this);
addWindowListener(new WinL());
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
setVisible(true);
}
private void setContentPane() {
txtHostname = new JTextField(20);
txtRmiObjName = new JTextField(20);
NumberFormat nf = NumberFormat.getIntegerInstance();
nf.setGroupingUsed(false);
txtPort = new JFormattedTextField(nf);
txtPort.setValue(1099);
txtPort.setColumns(20);
txtPort1 = new JFormattedTextField(nf);
txtPort1.setValue(1100);
txtPort1.setColumns(20);
lagsSec = new JFormattedTextField(nf);
lagsSec.setValue(1);
lagsSec.setColumns(20);
JButton btnOk = new JButton("查询/启动");
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
option = OK_OPTION;
ServerInfoInputDialog.this.setVisible(false);
ServerInfoInputDialog.this.dispose();
}
});
JButton btnCancel = new JButton("取消");
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
option = CANCEL_OPTION;
ServerInfoInputDialog.this.setVisible(false);
ServerInfoInputDialog.this.dispose();
}
});
JPanel panel = new JPanel();
panel.add(btnOk);
panel.add(btnCancel);
Container c = getContentPane();
GridBagLayout gbLayout = new GridBagLayout();
GridBagConstraints gbCon = new GridBagConstraints();
gbCon.fill = GridBagConstraints.HORIZONTAL;
c.setLayout(gbLayout);
Tools.addComponent(c, 0, 0, 1, 1, gbCon, new JLabel("目录服务器地址:"));
Tools.addComponent(c, 1, 0, 2, 1, gbCon, txtHostname);
Tools.addComponent(c, 0, 1, 1, 1, gbCon, new JLabel("目录服务器端口号:"));
Tools.addComponent(c, 1, 1, 2, 1, gbCon, txtPort);
Tools.addComponent(c, 0, 2, 1, 1, gbCon, new JLabel("时间服务器端口号:"));
Tools.addComponent(c, 1, 2, 2, 1, gbCon, txtPort1);
Tools.addComponent(c, 0, 3, 1, 1, gbCon, new JLabel("查询的服务名:"));
Tools.addComponent(c, 1, 3, 2, 1, gbCon, txtRmiObjName);
Tools.addComponent(c, 0, 4, 1, 1, gbCon, new JLabel("时间间隔(秒):"));
Tools.addComponent(c, 1, 4, 2, 1, gbCon, lagsSec);
Tools.addComponent(c, 0, 5, 3, 1, gbCon, panel);
}
public int getOption() {
return option;
}
public String getHostname() {
return txtHostname.getText().trim();
}
public int getPort() {
return ((Number) txtPort.getValue()).intValue();
}
public String getRmiObjName() {
return txtRmiObjName.getText().trim();
}
class WinL extends WindowAdapter {
public void windowClosing(WindowEvent e) {
option = CANCEL_OPTION;
ServerInfoInputDialog.this.setVisible(false);
ServerInfoInputDialog.this.dispose();
}
}
public int getPort1() {
return ((Number) txtPort1.getValue()).intValue();
}
public int getLags() {
return ((Number) lagsSec.getValue()).intValue();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -