import java.awt.;
import javax.swing.;
import java.awt.event.*;
public class QQLogin implements ActionListener{
public static void main(String args[]){
JFrame w = new JFrame();
w.setSize(250, 125);
//new 组件
JLabel labUser = new JLabel("用户名");
JLabel labPass = new JLabel("密码");
JTextField txtUser = new JTextField();
JPasswordField txtPass = new JPasswordField();
JButton btnLogin = new JButton("登录");
JButton btnReg = new JButton("注册");
JButton btnCancel = new JButton("取消");
//注册事件监听
QQLogin e = new QQLogin();
btnLogin.addActionListener(e);
btnReg.addActionListener(e);
btnCancel.addActionListener(e);
//布置输入面板
JPanel panInput = new JPanel();
panInput.setLayout(new GridLayout(2, 2));
panInput.add(labUser);
panInput.add(txtUser);
panInput.add(labPass);
panInput.add(txtPass);
//布置按钮面板
JPanel panButton = new JPanel();
panButton.setLayout(new FlowLayout());
panButton.add(btnLogin);
panButton.add(btnReg);
panButton.add(btnCancel);
//布置窗体
w.setLayout(new BorderLayout());
w.add(panInput, BorderLayout.CENTER);
w.add(panButton, BorderLayout.SOUTH);
w.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent arg0){
if(arg0.getActionCommand() == "登录"){
System.out.println("用户点击了登录");
}
if(arg0.getActionCommand() == "注册"){
System.out.println("用户点击了注册");
}
if(arg0.getActionCommand() == "取消"){
System.out.println("用户点击了取消");
}
}
}