📄 bslogindialog.java
字号:
package edu.ou.kmi.buddyspace.gui;
/*
* BSLoginDialog.java
*
* Project: BuddySpace
* (C) Copyright Knowledge Media Institute 2002
*
*
* Created on 15 July 2002, 10:22
*/
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.beans.*; // Property change stuff
import edu.ou.kmi.buddyspace.core.BSCore;
/**
* Dialog for entering login and registration information.
*
* @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
*/
public class BSLoginDialog extends javax.swing.JDialog {
private BSMainFrame mainFrame;
private JTextField loginTextField;
private JPasswordField passwordField;
private JTextField resourceTextField;
private JTextField hostTextField;
private JTextField portTextField;
//private JCheckBox newAccountCheckBox;
private JCheckBox sslCheckBox;
private JCheckBox saveCheckBox;
private JOptionPane optionPane;
public String username = null;
public String server = null;
public String resource = null;
public String password = null;
public int port;
public boolean newAccount;
public boolean useSSL;
public boolean saveValues = false;
/** Creates new form BSLoginDialog */
public BSLoginDialog(BSMainFrame parent, String username, String password,
String resource, String server,
int port, boolean newAccount) {
this(parent, username, password, resource, server, port, newAccount, false);
}
/** Creates new form BSLoginDialog */
public BSLoginDialog(BSMainFrame parent, String username, String password,
String resource, String server,
int port, boolean newAccount, boolean useSSL) {
super(parent, "Login", true);
this.mainFrame = parent;
loginTextField = new JTextField(username);
passwordField = new JPasswordField(password);
resourceTextField = new JTextField(resource);
hostTextField = new JTextField(server);
portTextField = new JTextField(Integer.toString(port));
sslCheckBox = new JCheckBox("Use SSL connection", useSSL);
saveCheckBox = new JCheckBox("Save the 5 values above", saveValues);
//newAccountCheckBox = new JCheckBox("New account", newAccount);
sslCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (sslCheckBox.isSelected()
&& "5222".equals(portTextField.getText())) {
portTextField.setText("5223");
}
else if (!sslCheckBox.isSelected()
&& "5223".equals(portTextField.getText())) {
portTextField.setText("5222");
}
}
});
Object[] fields = {"Login: ", loginTextField,
"Password: ", passwordField,
"Resource: ", resourceTextField,
"Host: ", hostTextField,
"Port: ", portTextField,
sslCheckBox,
saveCheckBox//,
//newAccountCheckBox,
};
final String okButton = "Log in";
final String cancelButton = "Cancel";
final String newAccountButton = "New account";
final String helpButton = "Help";
Object[] options = {okButton, newAccountButton, cancelButton, helpButton};
optionPane = new JOptionPane(fields,
JOptionPane.PLAIN_MESSAGE,
JOptionPane.OK_CANCEL_OPTION,
null,
options,
options[0]);
setContentPane(optionPane);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
pack();
setLocationRelativeTo(parent);
// handles actions
optionPane.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if (isVisible()
&& (e.getSource() == optionPane)
&& (prop.equals(JOptionPane.VALUE_PROPERTY) ||
prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
Object value = optionPane.getValue();
if (value == JOptionPane.UNINITIALIZED_VALUE) {
// ignore reset
return;
}
// Reset the JOptionPane's value.
// If you don't do this, then if the user
// presses the same button next time, no
// property change event will be fired.
optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
if (value.equals(okButton)) {
connect(false);
return;
}
else if (value.equals(newAccountButton)) {
connect(true);
return;
}
else if (value.equals(cancelButton)) {
setVisible(false);
}
else if (value.equals(helpButton)) {
JOptionPane.showMessageDialog(BSLoginDialog.this,
"If you have got an existing jabber account\n"
+ "'log in' using your account details.\n\n"
+ "If you don't have one,\n"
+ "fill in the values and create a 'new account'.\n"
+ "Next time you'll just 'log in'.",
"Login help", JOptionPane.PLAIN_MESSAGE);
}
}
}
});
}
/**
* Stores entered information into inner variables.
* This actually does not connect!
*/
private void connect(boolean newAccount) {
username = loginTextField.getText();
password = new String(passwordField.getPassword());
resource = resourceTextField.getText();
server = hostTextField.getText();
//newAccount = newAccountCheckBox.isSelected();
this.newAccount = newAccount;
saveValues = saveCheckBox.isSelected();
useSSL = sslCheckBox.isSelected();
if (username == null || username.equals("") ||
resource == null || resource.equals("") ||
server == null || server.equals("")) {
JOptionPane.showMessageDialog(this,
"You must specify your login,\n"
+ "host (e.g. 'jabber.org' or 'jabber.open.ac.uk'),\n"
+ "resource (e.g. 'My laptop' or 'BuddySpace')\n"
+ "and port (usually '5222')",
"Error",
JOptionPane.ERROR_MESSAGE);
username = password = resource = server = null;
return;
}
try {
port = Integer.parseInt(portTextField.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this,
"Port must be a number",
"Error",
JOptionPane.ERROR_MESSAGE);
username = password = resource = server = null;
return;
}
setVisible(false);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -