⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logindialog.java

📁 一个实现网络会议的软件.包含三个包.其中一个包需JMF的支持.
💻 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 + -