📄 oaaconnectdialog.java
字号:
/*
* @(#)OaaConnectDialog.java 08/1999
*
* The contents of this file are subject to the OAA Community Research
* License Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License
* at http://www.ai.sri.com/~oaa/. Software distributed under the License
* is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific language governing
* rights and limitations under the License. Portions of the software are
* Copyright (c) SRI International, 1999. All rights reserved.
* "OAA" is a registered trademark, and "Open Agent Architecture" is a
* trademark, of SRI International, a California nonprofit public benefit
* corporation.
*/
/*
* file: OaaConnectDialog.java
* Author: Didier Guzzoni
* purpose: Asks users for host/port of parent Facilitator
*
*/
package com.sri.oaa2.guiutils;
import java.lang.String;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Provides low-level communications methods for the agentlib.
*/
public class OaaConnectDialog extends JDialog {
/** True if the OK button was pushed */
public boolean mOk = false;
private JPanel mainPanel = new JPanel();
private JButton btnOk = new JButton();
private JButton btnCancel = new JButton();
private JTextField edHostName = new JTextField();
private JTextField edPortNumber = new JTextField();
private JLabel label1 = new JLabel();
private JLabel label2 = new JLabel();
private Frame mParent;
/****************************************************************************
* Constructor.
* @param frame Parent frame
* @param title To appear in the dialog's caption
* @param modal True if the dialog has to be modal
****************************************************************************/
public OaaConnectDialog(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
setModal(modal);
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
getContentPane().add(mainPanel);
pack();
mParent = frame;
}
/****************************************************************************
* Constructor.
* @param frame Parent frame
* @param title To appear in the dialog's caption
* @param modal True if the dialog has to be modal
* </dl><b>Remarks:</b>
* <dl>
* <dd>Forces modal mode
* </dl>
****************************************************************************/
public OaaConnectDialog(Frame frame, String title) {
this(frame, title, true);
}
/****************************************************************************
* Constructor.
* @param frame Parent frame
* @param title To appear in the dialog's caption
* @param modal True if the dialog has to be modal
* </dl><b>Remarks:</b>
* <dl>
* <dd>Forces modal mode and the caption to "OAA Connect"
* </dl>
****************************************************************************/
public OaaConnectDialog(Frame frame) {
this(frame, "OAA Connect", true);
}
/****************************************************************************
* Sets the host name.
* @param inHostName The host name where the facilitator is running
****************************************************************************/
public void setHostName(String inHostName) {
edHostName.setText(inHostName);
}
/****************************************************************************
* Gets the host name.
* @return The host name where the facilitator is running
****************************************************************************/
public String getHostName() {
return edHostName.getText();
}
/****************************************************************************
* Sets the port number.
* @param inHostName The port number to which the facilitator is bound
****************************************************************************/
public void setPortNumber(int inPortNumber) {
edPortNumber.setText(String.valueOf(inPortNumber));
}
/****************************************************************************
* Gets the host name.
* @return The port number to which the facilitator is bound
****************************************************************************/
public int getPortNumber() {
return Integer.valueOf(edPortNumber.getText()).intValue();
}
private void jbInit() throws Exception {
mainPanel.setSize(new Dimension(229, 90));
btnOk.setBounds(new Rectangle(5, 60, 100, 24));
btnOk.setText("OK");
btnCancel.setBounds(new Rectangle(115, 60, 100, 24));
btnCancel.setText("Cancel");
edHostName.setBounds(new Rectangle(85, 6, 130, 20));
edHostName.setText("textField1");
edPortNumber.setBounds(new Rectangle(84, 31, 130, 20));
edPortNumber.setText("textField2");
label1.setBounds(new Rectangle(5, 2, 72, 23));
label1.setText("Host name");
label2.setBounds(new Rectangle(5, 30, 78, 26));
label2.setText("Port number");
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnOk_actionPerformed();
}
});
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnCancel_actionPerformed();
}
});
mainPanel.setLayout(null);
mainPanel.add(label1);
mainPanel.add(edHostName);
mainPanel.add(label2);
mainPanel.add(edPortNumber);
mainPanel.add(btnCancel, null);
mainPanel.add(btnOk, null);
}
/****************************************************************************
* Displays the dialog box, centered with respect to its parent's dimension
****************************************************************************/
public void setVisible(boolean inVisible) {
if (inVisible){
super.setSize(225,110);
this.setLocation(mParent.getLocation());
this.setLocation(mParent.getLocation().x+mParent.getSize().width/2-this.getSize().width/2,
mParent.getLocation().y+mParent.getSize().height/2-this.getSize().height/2);
}
super.setVisible(inVisible);
}
// OK
void btnOk_actionPerformed() {
mOk = true;
dispose();
}
// Cancel
void btnCancel_actionPerformed() {
mOk = false;
dispose();
}
void this_windowClosing(WindowEvent e) {
dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -