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

📄 loginpanel.java

📁 piweurrrrq i o fhsadhfka fd dskajc zxkjcnkjsahc
💻 JAVA
字号:
package com.lyrisoft.chat.client.gui.jfc;import java.awt.Component;import java.awt.GridLayout;import java.awt.Dimension;import java.awt.event.*;import javax.swing.*;import com.lyrisoft.chat.client.gui.ILogin;import com.lyrisoft.chat.client.gui.IChatClientInputReceiver;public class LoginPanel extends JPanel implements ILogin {    private IChatClientInputReceiver _receiver;    private JTextField _textField;    private JPasswordField _passField;    private JLabel _status;    private Component _container;    public LoginPanel(IChatClientInputReceiver receiver) {        _receiver = receiver;        Box b = new Box(BoxLayout.Y_AXIS);        b.add(createInputAreas());        b.add(b.createVerticalStrut(5));        b.add(createButtonArea());         b.add(b.createVerticalStrut(5));         b.add(createStatusArea());               setLayout(new GridLayout(1, 1));        add(b);    }    public Component getContainer() {        return _container;    }    public void setContainer(Component c) {        _container = c;    }    Component createInputAreas() {        Box b = new Box(BoxLayout.X_AXIS);        b.add(createLabels());        b.add(createInputFields());        return b;    }    Component createButtonArea() {        Box b = new Box(BoxLayout.X_AXIS);        JButton loginButton = new JButton("Login");        loginButton.addActionListener(            new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        doLogin();                    }                }        );                JButton cancelButton = new JButton("Cancel");        cancelButton.addActionListener(            new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        _receiver.loginCancelEvent();                    }                }        );                b.add(loginButton);        b.add(cancelButton);         return b;    }    Component createLabels() {        Box b = new Box(BoxLayout.Y_AXIS);        b.add(new JLabel("name"));        b.add(new JLabel("password"));        return b;    }    Component createInputFields() {        Box b = new Box(BoxLayout.Y_AXIS);        _textField = new JTextField();        _textField.addActionListener(            new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        _passField.requestFocus();                    }                }        );        _passField = new JPasswordField();         _passField.addActionListener(            new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        doLogin();                    }                }        );        SwingGuiFactory.tweakTextFieldSize(_textField);        SwingGuiFactory.tweakTextFieldSize(_passField);        b.add(_textField);        b.add(_passField);          return b;    }    Component createStatusArea() {        Box b = new Box(BoxLayout.X_AXIS);        _status = new JLabel("Enter your credentials and click login",                              SwingConstants.LEFT);        b.add(_status);        b.add(b.createHorizontalGlue());        return b;    }    void doLogin() {        String name = _textField.getText();        String pass = _passField.getText();        _textField.setText("");        _passField.setText("");        _receiver.loginEvent(name, pass);    }    public void setStatus(String txt) {        _status.setText(txt);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -