⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logingui.java

📁 java编程好的网上银行的例子
💻 JAVA
字号:
/*
 * 创建日期 2005-9-5
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.border.*;

public class LoginGUI extends JFrame implements ActionListener {

    private JPanel contentPane;

    private JTextField password, accountNumber;

    private JTextArea announcements;

    private JButton login, registration;

    public String _accountNumber, _password;

    public boolean status = false;

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO 自动生成方法存根
        LoginGUI gui = new LoginGUI();
        // gui.setVisible(true);
    }

    public LoginGUI() {

        try {
            Init();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void Init() throws Exception {
        contentPane = (JPanel) this.getContentPane();

        accountNumber = new JTextField();
        accountNumber.setBorder(new TitledBorder("Accountnumber"));
        accountNumber.setBounds(10, 10, 120, 40);

        password = new JTextField();
        password.setBorder(new TitledBorder("password"));
        password.setBounds(160, 10, 120, 40);

        login = new JButton("Log_in");
        login.setBounds(10, 60, 120, 40);

        registration = new JButton("registration");
        registration.setBounds(160, 60, 120, 40);

        announcements = new JTextArea("");
        announcements.setBorder(new TitledBorder("Announcements"));
        announcements.setBounds(10, 110, 270, 100);

        contentPane.setLayout(null);
        contentPane.add(login);
        contentPane.add(registration);
        contentPane.add(password);
        contentPane.add(accountNumber);
        contentPane.add(announcements);

        login.addActionListener(this);
        registration.addActionListener(this);

        this.setSize(300, 250);

        this.setTitle("Login");
        this.setLocation(300, 250);
        this.addWindowListener(new LoginGUI_this_windowAdapter(this));
        this.setVisible(true);
    }

    public void actionPerformed(ActionEvent event) {
        if (event.getSource() == login) {
            _accountNumber = accountNumber.getText();
            _password = password.getText();

            if ((_accountNumber.length() == 0) || (_password.length() == 0)) {
                JOptionPane.showMessageDialog(this,
                        "Please enter a valid account number and password",
                        "Error", JOptionPane.WARNING_MESSAGE);
                _accountNumber = null;
                _password = null;
                return;
            } else {
                status = true;
                this.setVisible(false);

                try {
                    new BankUser(status, Integer.parseInt(_accountNumber),
                            _password);
                } catch (NumberFormatException e) {
                    JOptionPane.showMessageDialog(this,
                            "AccountNumber must be number", "Error",
                            JOptionPane.WARNING_MESSAGE);
                    new LoginGUI();
                    status = false;
                } catch (java.rmi.RemoteException e) {

                }

            }

        }

        if (event.getSource() == registration) {
            this.dispose();
            new RegGUI();

        }

    }

    void this_windowClosing(WindowEvent e) {
        System.exit(0);
    }

}

class LoginGUI_this_windowAdapter extends java.awt.event.WindowAdapter {
    LoginGUI adaptee;

    LoginGUI_this_windowAdapter(LoginGUI adaptee) {
        this.adaptee = adaptee;
    }

    public void windowClosing(WindowEvent e) {
        adaptee.this_windowClosing(e);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -