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

📄 registerpanel.java

📁 实现银行系统的一系列功能,比如存款取款透支查询余额等
💻 JAVA
字号:
package tarena.bank.view;

import java.awt.*;
import java.awt.event.*;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import tarena.bank.server.Account;
import javax.swing.*;

public class RegisterPanel extends JFrame implements Runnable, ActionListener {

	private JLabel label, label1, label2, label3, label4, label5, label6,
			label7;

	private JButton button, button1, button2;

	private JComboBox comboBox;

	private JPasswordField passwordField;

	private JTextField textField, textField1, textField2, textField3,
			textField4;

	private DataInputStream inStream = null;

	private DataOutputStream outStream = null;

	private boolean isConnected;

	public RegisterPanel() {
		super("注册账号");
		isConnected = true;
		this.setLayout(null);
		getContentPane().setBackground(Color.DARK_GRAY);
		this.setBounds(100, 100, 500, 375);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		label = new JLabel();
		label.setHorizontalTextPosition(SwingConstants.CENTER);
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setForeground(Color.BLUE);
		label.setFont(new Font("@幼圆", Font.PLAIN, 22));
		label.setText("欢迎您注册银行账户");
		label.setBounds(88, 10, 328, 33);
		this.add(label);

		label1 = new JLabel();
		label1.setHorizontalAlignment(SwingConstants.CENTER);
		label1.setFont(new Font("@幼圆", Font.PLAIN, 18));
		label1.setForeground(Color.BLUE);
		label1.setText("账号:");
		label1.setBounds(85, 60, 83, 20);
		this.add(label1);

		label2 = new JLabel();
		label2.setHorizontalAlignment(SwingConstants.CENTER);
		label2.setForeground(Color.BLUE);
		label2.setFont(new Font("Dialog", Font.PLAIN, 18));
		label2.setText("密码:");
		label2.setBounds(85, 90, 83, 20);
		this.add(label2);

		label3 = new JLabel();
		label3.setHorizontalAlignment(SwingConstants.CENTER);
		label3.setForeground(Color.BLUE);
		label3.setFont(new Font("Dialog", Font.PLAIN, 18));
		label3.setText("户主:");
		label3.setBounds(85, 120, 83, 20);
		this.add(label3);

		label4 = new JLabel();
		label4.setHorizontalAlignment(SwingConstants.CENTER);
		label4.setForeground(Color.BLUE);
		label4.setFont(new Font("Dialog", Font.PLAIN, 18));
		label4.setText("身份证号:");
		label4.setBounds(85, 150, 83, 20);
		this.add(label4);

		label5 = new JLabel();
		label5.setHorizontalAlignment(SwingConstants.CENTER);
		label5.setForeground(Color.BLUE);
		label5.setFont(new Font("Dialog", Font.PLAIN, 18));
		label5.setText("email:");
		label5.setBounds(85, 175, 83, 20);
		this.add(label5);

		label6 = new JLabel();
		label6.setHorizontalAlignment(SwingConstants.CENTER);
		label6.setForeground(Color.BLUE);
		label6.setFont(new Font("Dialog", Font.PLAIN, 18));
		label6.setText("开户存额:");
		label6.setBounds(85, 205, 83, 20);
		this.add(label6);

		textField = new JTextField();
		textField.setBackground(Color.LIGHT_GRAY);
		textField.setEditable(false);
		textField.setFont(new Font("@幼圆", Font.PLAIN, 18));
		textField.setBounds(174, 61, 117, 22);
		this.add(textField);

		button = new JButton();
		button.setBackground(Color.LIGHT_GRAY);
		button.setFont(new Font("", Font.PLAIN, 14));
		button.setForeground(Color.DARK_GRAY);
		button.setText("自动生成");
		button.setBounds(326, 58, 90, 28);
		button.addActionListener(this);
		this.add(button);

		passwordField = new JPasswordField();
		passwordField.setBackground(Color.LIGHT_GRAY);
		passwordField.setBounds(174, 91, 117, 22);
		this.add(passwordField);

		textField1 = new JTextField();
		textField1.setBackground(Color.LIGHT_GRAY);
		textField1.setBounds(174, 121, 117, 22);
		this.add(textField1);

		textField2 = new JTextField();
		textField2.setBackground(Color.LIGHT_GRAY);
		textField2.setBounds(174, 151, 183, 22);
		this.add(textField2);

		textField3 = new JTextField();
		textField3.setBackground(Color.LIGHT_GRAY);
		textField3.setBounds(174, 176, 183, 22);
		this.add(textField3);

		textField4 = new JTextField();
		textField4.setBackground(Color.LIGHT_GRAY);
		textField4.setBounds(174, 206, 117, 22);
		this.add(textField4);

		label7 = new JLabel();
		label7.setHorizontalAlignment(SwingConstants.CENTER);
		label7.setForeground(Color.BLUE);
		label7.setFont(new Font("Dialog", Font.PLAIN, 18));
		label7.setText("开户类型:");
		label7.setBounds(88, 238, 83, 20);
		this.add(label7);

		comboBox = new JComboBox();
		comboBox.setBackground(Color.LIGHT_GRAY);
		comboBox.setFont(new Font("@幼圆", Font.PLAIN, 15));
		comboBox.setBounds(174, 237, 117, 27);
		comboBox.addItem("储蓄账户");
		comboBox.addItem("信用账户");
		comboBox.addItem("贷款储蓄账户");
		comboBox.addItem("贷款信用账户");
		comboBox.addActionListener(this);
		this.add(comboBox);

		button1 = new JButton();
		button1.setForeground(Color.BLACK);
		button1.setBackground(Color.LIGHT_GRAY);
		button1.setFont(new Font("@幼圆", Font.PLAIN, 15));
		button1.setText("提交");
		button1.setBounds(131, 284, 106, 28);
		button1.addActionListener(this);
		this.add(button1);

		button2 = new JButton();
		button2.setForeground(Color.BLACK);
		button2.setBackground(Color.LIGHT_GRAY);
		button2.setFont(new Font("@幼圆", Font.PLAIN, 15));
		button2.setText("取消");
		button2.setBounds(272, 284, 106, 28);
		button2.addActionListener(this);
		this.add(button2);
		this.setVisible(true);
		// this.setLocation((screemSize.width-400)/2,
		// (screemSize.height-400)/2);
	}

	public static void main(String args[]) {
		try {
			new RegisterPanel();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void start() {
		Thread thread = new Thread(this);
		// 打开线程
		thread.start();
	}
	//	发送消息的方法
	private void send(String str) {
		try {
			outStream.writeUTF(str);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void actionPerformed(ActionEvent e) {

		if (e.getSource() == button) {
			textField.setText(String.valueOf(Account.CreatId()));
		} else if (e.getSource() == button1) {
			String s = "register" + textField.getText() + "/"
					+ String.valueOf(passwordField.getPassword()) + "/"
					+ textField1.getText() + "/" + textField2.getText() + "/"
					+ textField3.getText() + "/" + textField4.getText() + "/"
					+ comboBox.getSelectedIndex() + "/";
			System.out.println(s);
			send(s);//向服务器发送注册命令
			// this.dispose();
		} else if (e.getSource() == button2) {
			System.exit(0);
		}
	}

	public void run() {
		try {
			Socket socket = new Socket("127.0.0.1", 8888);
			// System.out.println(socket);
			outStream = new DataOutputStream(socket.getOutputStream());
			inStream = new DataInputStream(socket.getInputStream());

			while (isConnected) {
				String str = inStream.readUTF();// 读取服务器发来的信息
				if (str.equals("注册成功")) {
					socket.close();
					// new 注册后的界面
					new OperationPanel(textField.getText(), textField1
							.getText(), textField2.getText(), textField4
							.getText(), "0.0", "0.0", (String) comboBox
							.getSelectedItem()).start();
					this.dispose();
				}
			}
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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