java做个简单的登录界面_java一个简单的登录界面制作

展开全部

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);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值