?? loginframe.java
字號:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class LoginFrame implements ActionListener{
JTextField name_tf;
JPasswordField pwd_tf;
JFrame lFrame;
JButton confirm_button;
JButton reset_button;
ArrayList array = new ArrayList();
Customer ct;
//構造方法
public LoginFrame(){
array.add(new Customer("一號船","一號位","hello","12345678","hello","上海市吳中路"));
array.add(new Customer("二號船","二號位","Miky","32345678","miky","上海市漢中路"));
array.add(new Customer("三號船","三號位","呵呵","22345678","hehe","上海市漢中路"));
array.add(new Customer("4號船","4號位","heello","62345678","hehe","上海市漢中路"));
JFrame lFrame = new JFrame("登陸");
//定義panel
JPanel up_panel = new JPanel();
JPanel down_panel = new JPanel();
JPanel main_panel = new JPanel();
JPanel up_panel1 = new JPanel();
//定義標簽
JLabel name_lb = new JLabel("用戶名:");
name_lb.setHorizontalAlignment(JLabel.RIGHT);
JLabel pwd_lb = new JLabel("密 碼:");
pwd_lb.setHorizontalAlignment(JLabel.RIGHT);
name_tf = new JTextField(15);
pwd_tf = new JPasswordField(15);
pwd_tf.setEchoChar('#');
//定義按妞
confirm_button = new JButton("確定");
reset_button = new JButton("重填");
confirm_button.addActionListener(this);
reset_button.addActionListener(this);
//panel加入標簽
up_panel.add(name_lb);
up_panel.add(name_tf);
up_panel1.add(pwd_lb);
up_panel1.add(pwd_tf);
//按妞假如panel
down_panel.add(confirm_button);
down_panel.add(reset_button);
main_panel.add(up_panel);
main_panel.add(up_panel1);
main_panel.add(down_panel);
lFrame.add(main_panel);
lFrame.setSize(300,200);
lFrame.setLocation(350,250);
lFrame.setDefaultCloseOperation(lFrame.EXIT_ON_CLOSE);
lFrame.setResizable(false);
lFrame.setVisible(true);
}
public LoginFrame(ArrayList ar){
int ar_i = ar.size();
for(int j=0;j<ar_i;j++){
Customer ct = (Customer)ar.get(j);
String id = new String(ct.getB().getId());
String length = new String(ct.getB().getLength());
String name = new String(ct.getName());
String tel = new String(ct.getTel());
String pwd = new String(ct.getPwd());
String add = new String(ct.getAddress());
ct = new Customer(id,length,name,tel,pwd,add);
this.array.add(ct);
}
array.add(new Customer("5號船","5號位","five","02112345678","hello","上海市吳中路"));
array.add(new Customer("6號船","6號位","six","02112345678","miky","上海市漢中路"));
array.add(new Customer("7號船","7號位","seven","02112345678","hehe","上海市漢中路"));
JFrame lFrame = new JFrame("登陸");
//定義panel
JPanel up_panel = new JPanel();
JPanel down_panel = new JPanel();
JPanel main_panel = new JPanel();
JPanel up_panel1 = new JPanel();
//定義標簽
JLabel name_lb = new JLabel("用戶名:");
name_lb.setHorizontalAlignment(JLabel.RIGHT);
JLabel pwd_lb = new JLabel("密 碼:");
pwd_lb.setHorizontalAlignment(JLabel.RIGHT);
name_tf = new JTextField(15);
pwd_tf = new JPasswordField(15);
pwd_tf.setEchoChar('#');
//定義按妞
confirm_button = new JButton("確定");
reset_button = new JButton("重填");
confirm_button.addActionListener(this);
reset_button.addActionListener(this);
//panel加入標簽
up_panel.add(name_lb);
up_panel.add(name_tf);
up_panel1.add(pwd_lb);
up_panel1.add(pwd_tf);
//按妞假如panel
down_panel.add(confirm_button);
down_panel.add(reset_button);
main_panel.add(up_panel);
main_panel.add(up_panel1);
main_panel.add(down_panel);
lFrame.add(main_panel);
lFrame.setSize(300,200);
lFrame.setLocation(350,250);
lFrame.setDefaultCloseOperation(lFrame.EXIT_ON_CLOSE);
lFrame.setResizable(false);
lFrame.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("確定")){
int f = 0;
String name = name_tf.getText();
String pwd = new String(pwd_tf.getPassword());
if(name.equals("admin")){
if(pwd.equals("admin")){
JOptionPane.showMessageDialog(lFrame,"登陸成功!","提示信息",JOptionPane.ERROR_MESSAGE);
new MainFrame(array);
//lFrame.dispose();
//lFrame.dispose();
}
else{
JOptionPane.showMessageDialog(lFrame,"密碼錯誤!","提示信息",JOptionPane.ERROR_MESSAGE);
pwd_tf.setText("");
pwd_tf.requestFocus(true);
}
}
else{
int ai = array.size();
for(int i = 0;i<ai;i++){
int j=0;
Customer ct = (Customer)array.get(i);
f ++;
j++;
System.out.println("i:"+i);
System.out.println("j:"+j);
if(name.equals(ct.getName()) ){
if(pwd.equals(ct.getPwd())){
ArrayList ar =array;
new ShowInfo(ct);
//lFrame.setVisible(false);
break;
//lFrame.dispose();
//lFrame.setVisible(false);
//JOptionPane.showMessageDialog(lFrame,"登陸成功!","提示信息",JOptionPane.ERROR_MESSAGE);
}
else{
JOptionPane.showMessageDialog(lFrame,"密碼錯誤!","提示信息",JOptionPane.ERROR_MESSAGE);
pwd_tf.setText("");
pwd_tf.requestFocus(true);
//lFrame.dispose();
break;
}
}
//else if(j>=ai){
//JOptionPane.showMessageDialog(lFrame,"用戶不存在請先注冊!","提示信息",JOptionPane.ERROR_MESSAGE);
//new RegisterCustomer(array);
//}
else if(f==ai-1){
JOptionPane.showMessageDialog(lFrame,"用戶不存在請先注冊!","提示信息",JOptionPane.ERROR_MESSAGE);
new RegisterCustomer(array);
//JOptionPane.showMessageDialog(lFrame,"密碼或錯誤,請重新輸入!","提示信息",JOptionPane.ERROR_MESSAGE);
//pwd_tf.setText("");
//name_tf.setText("");
//name_tf.requestFocus(true);
}
}
}
}
if(e.getActionCommand().equals("重填")){
name_tf.setText("");
pwd_tf.setText("");
name_tf.requestFocus(true);
}
}
public static void main(String[] args){
new LoginFrame();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -