?? loginframe.java
字號(hào):
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LoginFrame extends JFrame implements ActionListener{
MainFrame mainframe;
Bank bank1;
JPanel panel1 ,panel2;
JLabel labelbj,labelbt,labeltext,AccountLabel,PasswordLabel1,PasswordLabel2,UserLabel,SexLabel,IDnumLabel,PhonenumLabel,AddressLabel,PostnumLabel;
JTextField labeltextField,AccountField,PasswordField,UserField,IDnumField,PhonenumField,AddressField,PostnumField;
Choice sexchoice;
JPasswordField PasswordTextField1,PasswordTextField2;
JButton YesBtn,returnBtn;
public LoginFrame(MainFrame mainframe1,Bank b1)
{
mainframe = mainframe1;
bank1=b1;
GridBagLayout layout = new GridBagLayout();
setLayout(layout);
labeltext = new JLabel(" ");
labelbt = new JLabel(" ");
PasswordLabel1 = new JLabel("請(qǐng)輸入您的密碼:");
PasswordLabel2 = new JLabel("請(qǐng)確認(rèn)您的密碼:");
UserLabel = new JLabel("請(qǐng)輸入您的姓名:");
SexLabel = new JLabel("請(qǐng)輸入您的性別:");
IDnumLabel = new JLabel("請(qǐng)輸入身份證號(hào):");
PhonenumLabel = new JLabel("請(qǐng)輸入手機(jī)號(hào)碼:");
AddressLabel = new JLabel("請(qǐng)輸入聯(lián)系地址:");
PostnumLabel = new JLabel("請(qǐng)輸入郵編號(hào)碼:");
labelbj = new JLabel();
ImageIcon img = new ImageIcon( "bj02.jpg ");
labelbj .setIcon(img);
getLayeredPane().add(labelbj, new Integer(Integer.MIN_VALUE));
labelbj.setBounds(0,0,img.getIconWidth(), img.getIconHeight());
((JPanel)getContentPane()).setOpaque(false);
PasswordTextField1 = new JPasswordField(10);
PasswordTextField2 = new JPasswordField(10);
UserField = new JTextField(10);
sexchoice = new Choice();
sexchoice.addItem(" 男 ");
sexchoice.addItem(" 女 ");
IDnumField = new JTextField(10);
PhonenumField = new JTextField(10);
AddressField = new JTextField(10);
PostnumField = new JTextField(10);
YesBtn = new JButton(" 注冊(cè) ");
returnBtn = new JButton(" 返回上一層 ");
YesBtn.addActionListener(this);
returnBtn.addActionListener(this);
// 設(shè)置布局都是在這里實(shí)現(xiàn)的。。。。
add(labeltext, new GBC(0, 1).setWeight(100, 100).setInsets(2));
add(labelbt , new GBC(1, 1).setWeight(100, 100).setInsets(2));
add(PasswordLabel1, new GBC(0, 2).setAnchor(GBC.CENTER));
add(PasswordLabel2, new GBC(0, 3).setAnchor(GBC.CENTER));
add(UserLabel, new GBC(0, 4).setAnchor(GBC.CENTER));
add(SexLabel, new GBC(0,5).setAnchor(GBC.CENTER));
add(IDnumLabel, new GBC(0, 6).setAnchor(GBC.CENTER));
add(PhonenumLabel, new GBC(0, 7).setAnchor(GBC.CENTER));
add(AddressLabel, new GBC(0, 8).setAnchor(GBC.CENTER));
add(PostnumLabel, new GBC(0, 9).setAnchor(GBC.CENTER));
add(YesBtn, new GBC(0, 10).setWeight(100, 100));
add(returnBtn, new GBC(1, 10).setWeight(100, 100));
add(UserField, new GBC(1, 4).setWeight(100, 0).setInsets(5).setAnchor(GBC.WEST));
add(sexchoice, new GBC(1, 5).setWeight(100, 0).setInsets(5).setAnchor(GBC.WEST));
add(IDnumField, new GBC(1, 6).setWeight(100, 0).setInsets(5).setAnchor(GBC.WEST));
add(PhonenumField, new GBC(1, 7).setWeight(100, 0).setInsets(5).setAnchor(GBC.WEST));
add(AddressField, new GBC(1, 8).setWeight(100, 0).setInsets(5).setAnchor(GBC.WEST));
add(PostnumField, new GBC(1, 9).setWeight(100, 0).setInsets(5).setAnchor(GBC.WEST));
add(PasswordTextField1, new GBC(1, 2).setWeight(100, 0).setInsets(5).setAnchor(GBC.WEST)); // 把UserTextField 放在1列2行, 外部增加20px空間
add(PasswordTextField2, new GBC(1, 3).setWeight(100, 0).setInsets(5).setAnchor(GBC.WEST));
//把returnBtn 放到0列4行,如果水平,垂直方向有多余空間的話。按比例給YesBtn 加空間
setSize(500,480);
setLocation(50,50);
// 設(shè)置這個(gè)窗體關(guān)閉按鈕的操作. 這里是設(shè)置為彈出對(duì)話框,并關(guān)閉整個(gè)系統(tǒng)!
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
JOptionPane.showMessageDialog(null," 關(guān)閉整個(gè)系統(tǒng)!");
System.exit(0);
}
}
);
}
public void actionPerformed(ActionEvent e)
{
// TODO 自動(dòng)生成方法存根
if(e.getSource()== YesBtn)
{
validateDate();
}
else if(e.getSource()== returnBtn)
{
this.dispose();
mainframe.setVisible(true);
}
}
private void validateDate()
{
String name;
String sex;
long idnum;
long phonenum;
String homead;
long postcode;
try
{
String pwd1 = new String(PasswordTextField1.getPassword());
String password=pwd1;
String pwd2 = new String(PasswordTextField2.getPassword());
name = UserField.getText();
sex = sexchoice.getSelectedItem();
idnum =Long.parseLong(IDnumField.getText());
phonenum =Long.parseLong(PhonenumField.getText());
homead = AddressField.getText();
postcode = Long.parseLong(PostnumField.getText());
if(!compareTwoPassword())
{
JOptionPane.showMessageDialog(this,"兩次密碼輸入不一致");
PasswordTextField2.setText("");
PasswordTextField1.setText("");
}
else if(IDnumField.getText().length()!=18)
{
JOptionPane.showMessageDialog(this,"您的身份證號(hào)必須為18位數(shù)字");
IDnumField.setText("");
}
else
{
String str = " 注冊(cè)成功!!!";
JOptionPane.showMessageDialog(null,str);
Account a1 = new Account(password);
Userinfo u1 = new Userinfo(name, sex,idnum, phonenum, homead, postcode);
bank1.registration(a1, u1);
mainframe.setVisible(true);
this.setVisible(false);
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null," 請(qǐng)?zhí)顚?xiě)完整您的個(gè)人信息!");
}
}
private boolean compareTwoPassword() //兩次輸入密碼核對(duì)方法
{
boolean b = false;
String password1 = new String(PasswordTextField1.getPassword());
//將字符數(shù)組passwordTextField.getPassword()的內(nèi)容,創(chuàng)建為字符串password1
String password2 = new String(PasswordTextField2.getPassword());
//將字符數(shù)組confirmPswTextField.getPassword()的內(nèi)容,創(chuàng)建為字符串password2
if(password1.equals(password2)) b=true; //比較字符串
return b; //返回布爾型變量的值
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -