JAVA小專案-銀行管理系統(圖形化介面)3-登入與查詢
阿新 • • 發佈:2019-01-01
還是老規矩 ,先上圖, 得清晰的認識到自己寫到哪了, 還差多少
我們看圖 出了掛失ReportLose和資訊註冊Register 我們不要進行資訊驗證
其他在途中都必須進行
但我為什麼要綜合成一個呢, 因為懶, 覺得寫6個一樣的貼上都感覺很狗
但既然使用一個 , 我們就需要建立變數 , 將我們在選單選擇的功能 記錄
然後在login類中 分開處理
同時 在 編寫時需要注意 使用者名稱密碼不能為為空,不能為中文
雖然現在還是不說 怎麼寫驗證類 。但先將思路說一下
介面很無聊
package contentcl;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.*;
public class Login extends JFrame implements ActionListener{
JButton jb1, jb2, jb3; //按鈕
JPanel jp1,jp2,jp3, jp4; //面板
JTextField jtf; //文字框
JLabel jlb1, jlb2, jlb3; //標籤
JPasswordField jpf; //密碼框
String name = "123"; //賬號密碼
String pwd = "123";
String order;
public Login(String order) {
this.order = order;
// TODO Auto-generated constructor stub
jb1 = new JButton("登入" );
jb2 = new JButton("重置");
//設定按鈕監聽
jb1.addActionListener(this);
jb2.addActionListener(this);
jp1 = new JPanel(); //建立面板
jp2 = new JPanel();
jp3 = new JPanel();
jlb1 = new JLabel("使用者名稱"); //新增標籤
jlb2 = new JLabel(" 密 碼");
jtf = new JTextField(10); //建立文字框和密碼框
jpf = new JPasswordField(10);
//加入面板中
jp1.add(jlb1);
jp1.add(jtf);
jp2.add(jlb2);
jp2.add(jpf);
jp3.add(jb1);
jp3.add(jb2);
//將JPane加入JFrame中
this.add(jp1);
this.add(jp2);
this.add(jp3);
//設定佈局
this.setTitle("使用者登入");
this.setLayout(new GridLayout(3,1));
this.setSize(300, 200); //設定窗體大小
this.setLocationRelativeTo(null);//在螢幕中間顯示(居中顯示)
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); //設定僅關閉當前視窗
this.setVisible(true); //設定可見
this.setResizable(false); //設定不可拉伸大小
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getActionCommand()=="登入")
{
try {
login();
} catch (HeadlessException | IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
else if(e.getActionCommand()=="重置")
{
clear();
}
}
//清空賬號和密碼框
private void clear() {
// TODO Auto-generated method stub
jtf.setText(""); //設定為空
jpf.setText("");
}
//驗證登入資訊,並做處理
public void login() throws HeadlessException, IOException
{
//判斷賬戶名和密碼是否包含中文
if (new Check().checkcountname(jtf.getText())||new Check().checkcountname(jpf.getText()))
{
JOptionPane.showMessageDialog(null, "使用者名稱或密碼存在中文,不合法!","訊息提示",JOptionPane.WARNING_MESSAGE);
}
else if(jtf.getText().isEmpty()&&jpf.getText().isEmpty())
{
JOptionPane.showMessageDialog(null, "賬號密碼為空,請輸入!","訊息提示",JOptionPane.WARNING_MESSAGE);
}
else if (jtf.getText().isEmpty())
{
JOptionPane.showMessageDialog(null, "賬號為空,請輸入!","訊息提示",JOptionPane.WARNING_MESSAGE);
}
else if (jpf.getText().isEmpty())
{
JOptionPane.showMessageDialog(null, "密碼為空,請輸入!","訊息提示",JOptionPane.WARNING_MESSAGE);
}
else if (new Check().check1(jtf.getText(),jpf.getText()))
{
JOptionPane.showMessageDialog(null,"登入成功!","提示訊息",JOptionPane.WARNING_MESSAGE);
//dispose(); //使文原窗體消失
if (order.equals("查詢"))
{
new Inquiry(jtf.getText()); //跳轉到登入個人資訊選項介面
dispose();
}
if (order.equals("存款"))
{
new SaveMoney(jtf.getText());
dispose();
}
if (order.equals("取款"))
{
new DrawMoney(jtf.getText());
dispose();
}
if (order.equals("改密"))
{
new Modify(jtf.getText());
dispose();
}
if (order.equals("轉賬"))
{
new Transfer(jtf.getText());
dispose();
}
}
else
{
JOptionPane.showMessageDialog(null, "賬號密碼錯誤請重新輸入!","訊息提示",JOptionPane.ERROR_MESSAGE);
clear(); //呼叫清除函式
}
}
}
為什麼先說查詢類, 因為好做啊, 增刪改查
當然查最好做, 當初寫txt時候 就在思考 怎麼改 最後還是解決了
但是個人資訊畢竟是私人的, 所以我們 將部分資訊用*代替後再顯示
感覺註釋寫的挺清楚的
package contentcl;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.*;
/**
* 此類時對使用者資訊查詢的編寫, 我們將查詢出使用者的姓名身份證號和餘額
* @author contentcl
* @Date 2017年12月27日 下午8:54:17
*
*/
public class Inquiry extends JFrame implements ActionListener{
JLabel jlb1, jlb2, jlb3; //標籤
JTextField jtf1,jtf2,jtf3; //文字框
JPasswordField jpf; //密碼框
JPanel jp1,jp2,jp3; //面板
public Inquiry(String countname) throws IOException {
// TODO Auto-generated constructor stub
//標籤資訊
jlb1 = new JLabel(" 姓名");
jlb2 = new JLabel("身份證號");
jlb3 = new JLabel(" 餘額");
jtf1 = new JTextField(13);
jtf2 = new JTextField(13);
jtf3 = new JTextField(13);
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jp1.add(jlb1);
jp1.add(jtf1);
jp2.add(jlb2);
jp2.add(jtf2);
jp3.add(jlb3);
jp3.add(jtf3);
//設定佈局
this.setTitle("查詢");
this.setLayout(null); //採用空佈局
jp1.setBounds(-10, 40, 300 ,50); //-別問我為什麼-10 因為 介面好看一點啊
jp2.setBounds(-10, 110, 300 ,50);
jp3.setBounds(-10, 180, 300 ,50);
//將JPane加入JFrame中
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.setSize(300, 300); //設定窗體大小
this.setLocationRelativeTo(null);//在螢幕中間顯示(居中顯示)
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); //設定僅關閉當前視窗
this.setVisible(true); //設定可見
this.setResizable(false); //設定不可拉伸大小
String []message = new UserMessage().read(countname);
//將姓名的第一個字變為*
message[0] ="*"+message[0].substring(1,message[0].length());
//將身份證號第6到12位變成*
message[1] =message[1].substring(0,6)+"*******"+message[1].substring(13,message[1].length());
jtf1.setText(message[0]); //將資訊顯示在文字框中
jtf2.setText(message[1]);
jtf3.setText(message[4]);
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
}