?? logindialog.java
字號:
package clientPackage;
import java.beans.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import mediaPackage.*;
/**
* LoginDialog displays the login dialog to ask for user name,
* password and category
*
* @author Naizheng Bian
* @version 1.0
*/
public class LoginDialog extends JDialog {
/** Class constructor
* @param aFrame the frame for UI components
*/
public LoginDialog(Frame aFrame) {
super(aFrame, "Login Box", true);
setLocation(350, 350);
setSize(400,400);
/** box indicating whether to login as a presenter
*/
final JCheckBox category = new JCheckBox("I am a Presenter");
/** label for the Welcome
*/
final JLabel Welcome = new JLabel("Welcome to Symposium");
/** label for the Login field
*/
final JLabel myLogin = new JLabel("User Name: ");
/** label for the Password field
*/
final JLabel thePassword = new JLabel("Password: ");
/** text field that is used to input the login name
*/
final JTextField loginName = new JTextField(12);
/** password field that is used to input the password
*/
final JPasswordField password = new JPasswordField(12);
cat = false;
category.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
cat = !cat;
}
});
password.setEchoChar('*');
/** An object array holding the login objects
*/
//user version
//Object[] array = {Welcome, myLogin, loginName, thePassword, password};
//presenter version
Object[] array = {Welcome, myLogin, loginName, thePassword, password, category};
final String btnString1 = "Login";
final String btnString2 = "Cancel";
/** An object array holding the button objects
*/
Object[] options = {btnString1, btnString2};
optionPane = new JOptionPane(array,
JOptionPane.INFORMATION_MESSAGE,
JOptionPane.OK_CANCEL_OPTION,
null,options,options[0]);
setContentPane(optionPane);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
}
});
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) {
return;
}
// Reset the JOptionPane's value.
optionPane.setValue(
JOptionPane.UNINITIALIZED_VALUE);
if (value.equals(btnString1)) {
login = loginName.getText();
myPassword = new String(password.getPassword());
cat = category.isSelected();
setVisible(false);
password.setText("");
} else { // user closed dialog or clicked cancel
System.exit(0);
}
}
}
});
}
/** getLoginName returns the login name
* @return login name
*/
public String getLoginName() {
return login;
}
/** getPassword returns the password
* @return password
*/
public String getPassword() {
return myPassword;
}
/** getCategory returns the category of a user
* @return category of user: 1 for student and 2 for presenter
*/
public int getCategory() {
if (cat) {
return Constants.PRESENTER;
} else {
return Constants.USER;
}
}
/** hold the UI elements for the options
*/
private JOptionPane optionPane;
/** contain the login information
*/
private String login;
/** contain the password information
*/
private String myPassword;
/** reflect the category
*/
private boolean cat;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -