求java登陆界面啊
java登陆界面:
import java.awt.event.*;
import javax.swing.*;
public class login implements ActionListener{
String username="123456";
String password="111111";
JFrame test=new JFrame("登陆系统");
JPanel k1=new JPanel();
JButton ok=new JButton("登录");
JButton cancel=new JButton("取消");
JLabel name=new JLabel("用户名 :");
JLabel passwd=new JLabel("密 码 :");
JTextField nameinput=new JTextField(15);
JPasswordField passwordinput=new JPasswordField(15);
public login(){
test.setSize(300,250);
k1.setLayout(null);
k1.add(ok);
k1.add(cancel);
k1.add(name);
k1.add(passwd);
k1.add(nameinput);
k1.add(passwordinput);
k1.requestFocus();
ok.addActionListener(this);
cancel.addActionListener(this);
name.setBounds(60,20,60,20);
passwd.setBounds(60,50,60,20);
nameinput.setBounds(120,20,80,20);
passwordinput.setBounds(120,50,80,20);
ok.setBounds(60,120,60,20);
cancel.setBounds(130,120,60,20);
test.add(k1);
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==ok){
String nameInput=nameinput.getText();
String passwordInput=String.valueOf(passwordinput.getPassword());
if(nameInput.equals(username) && passwordInput.equals(password)){
JOptionPane.showMessageDialog(null, "登录成功!");
}else{
JOptionPane.showMessageDialog(null, "登录失败!");
}
}else if(e.getSource()==cancel){
nameinput.setText("");
passwordinput.setText("");
}
}
public static void main(String[] args) {
new login();
}
}
多重随机标签