展开全部
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
* 2014年12月28日下午7:18:41
* @author season
*
*/
public class LoginDemo extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField textField;
private JPasswordField passwordField;
/**
* Launch the application.
*/
public static void main(String[] args) {
32313133353236313431303231363533e78988e69d8331333335346163EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LoginDemo frame = new LoginDemo();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public LoginDemo() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 370, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblAccount = new JLabel("Account:");
lblAccount.setFont(new Font("Consolas", Font.BOLD, 14));
lblAccount.setBounds(25, 90, 104, 28);
contentPane.add(lblAccount);
JLabel lblPassword = new JLabel("Password:");
lblPassword.setFont(new Font("Consolas", Font.BOLD, 14));
lblPassword.setBounds(25, 128, 104, 28);
contentPane.add(lblPassword);
textField = new JTextField();
textField.setBounds(113, 93, 154, 21);
contentPane.add(textField);
textField.setColumns(10);
passwordField = new JPasswordField();
passwordField.setBounds(113, 131, 154, 21);
contentPane.add(passwordField);
final JLabel lblNewLabel = new JLabel("");
lblNewLabel.setFont(new Font("Consolas", Font.BOLD, 12));
lblNewLabel.setBounds(0, 222, 344, 30);
contentPane.add(lblNewLabel);
JButton btnSignIn = new JButton("Sign in");//登录按钮和监听
btnSignIn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String userName =textField.getText();
String userPwd = new String(passwordField.getPassword());
if(userName.equals("haiyan")&&userPwd.equals("haiyan")){
lblNewLabel.setText("You success login ");
}else{
lblNewLabel.setText("Fail to login ,check please ");
}
}
});
btnSignIn.setFont(new Font("Consolas", Font.BOLD, 14));
btnSignIn.setBounds(60, 189, 93, 23);
contentPane.add(btnSignIn);
JButton btnReset = new JButton("Reset");//重置按钮和监听
btnReset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField.setText("");
passwordField.setText("");
}
});
btnReset.setFont(new Font("Consolas", Font.BOLD, 14));
btnReset.setBounds(174, 189, 93, 23);
contentPane.add(btnReset);
JLabel lblHaiyan = new JLabel("Haiyan");
lblHaiyan.setFont(new Font("Consolas", Font.BOLD, 14));
lblHaiyan.setBounds(123, 10, 104, 28);
contentPane.add(lblHaiyan);
}
}