package b;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class Main extends JFrame implements ActionListener {
public JLabel labelUsername() {
JLabel labelUsername = new JLabel("输入用户名", SwingUtilities.RIGHT);
labelUsername.setFont(new Font("微软雅黑", Font.BOLD, 50));
return labelUsername;
}
public JTextField jtfUsername() {
JTextField jtfUsername = new JTextField(10);
jtfUsername.setFont(new Font("微软雅黑", Font.BOLD, 50));
return jtfUsername;
}
public JLabel labelPassword() {
JLabel labelPassword = new JLabel("输入密码", SwingUtilities.RIGHT);
labelPassword.setFont(new Font("微软雅黑", Font.BOLD, 50));
return labelPassword;
}
public JPasswordField jpfPassword() {
JPasswordField jpfPassword = new JPasswordField();
jpfPassword.setFont(new Font("微软雅黑", Font.BOLD, 50));
return jpfPassword;
}
public JButton jbLogin() {
JButton jbLogin = new JButton("登录");
jbLogin.setFont(new Font("微软雅黑", Font.BOLD, 50));
jbLogin.addActionListener(this);
return jbLogin;
}
public JButton jbReg() {
JButton jbReg = new JButton("注册");
jbReg.setFont(new Font("微软雅黑", Font.BOLD, 50));
jbReg.addActionListener(this);
return jbReg;
}
public Main() {
this.setLayout(new GridLayout(3, 2));
this.add(this.labelUsername());
this.add(this.jtfUsername());
this.add(this.labelPassword());
this.add(this.jpfPassword());
this.add(this.jbLogin());
this.add(this.jbReg());
}
public static void main(String[] args) {
Main m = new Main();
m.setBounds(0, 0, 640, 480);
// m.setExtendedState(JFrame.MAXIMIZED_BOTH);
m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
m.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
String s = ae.getActionCommand();
if (s.equals("登录")) {
System.out.println(s);
} else if (s.equals("注册")) {
System.out.println(s);
}
}
}