java登录界面_java实现登陆页面
登錄頁面:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventObject;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login2 extends JFrame implements ActionListener{
JPanel jp=new JPanel();
JLabel name=new JLabel("請輸入用戶名");
JLabel password=new JLabel("請輸入密碼");
JLabel show=new JLabel("");
JLabel[] jl= {name,password,show};
JButton login=new JButton("登陸");
JButton reset=new JButton("重置");
JButton register=new JButton("注冊");
JButton[] jb= {login,reset,register};
private JTextField JName=new JTextField();
private JPasswordField JPassword=new JPasswordField();
private int i;
public Login2() {
jp.setLayout(null);
for(int i=0;i<3;i++) {
jl[i].setBounds(30,20+40*i,180,20);
jb[i].setBounds(30+100*i,100,80,20);
jp.add(jl[i]);
jp.add(jb[i]);
jb[i].addActionListener(this);
}
JName.setBounds(130,15,100,20);
jp.add(JName);
JName.addActionListener(this);
JPassword.setBounds(130,60,100,20);
jp.add(JPassword);
JPassword.setEchoChar('*');
JPassword.addActionListener(this);
jl[2].setBounds(10,180,270,20);
jp.add(jl[2]);
this.add(jp);
this.setTitle("農產品銷售系統登錄窗口");
this.setBounds(200,200,350,250);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent arg0) {
EventObject e = null;
if(e.getSource()==JName) {
JPassword.requestFocus();
}
else if(e.getSource()==jb[i]) {
jl[2].setText("");
JName.setText("");
JPassword.setText("");
JName.requestFocus();
}
else if(e.getSource()==jb[2]) {
show.setText("進入農產品銷售系統注冊頁面");
}
else {
if(JName.getText().equals("qwer")&&
String.valueOf(JPassword.getPassword()).equals("1234")) {
jl[2].setText("登陸成功,歡迎您的到來!");
}
else {
jl[2].setText("對不起,您的用戶名或密碼錯誤!");
}
}
}
public static void main(String[] args) {
new Login2();
}
}
總結
以上是生活随笔為你收集整理的java登录界面_java实现登陆页面的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu16.04安装python2
- 下一篇: java 程序分析题_java程序入门5