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

📄 operationpanel.java

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

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class OperationPanel extends JFrame implements Runnable, ActionListener {

	private JPasswordField passwordField1, passwordField2;

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

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

	private JComboBox comboBox;

	private JCheckBox checkBox;

	private JButton button1, button2;

	private DataInputStream inStream = null;

	private DataOutputStream outStream = null;

	private boolean isConnected;

	public static void main(String args[]) {
		try {
			OperationPanel frame = new OperationPanel("100000", "pp",
					"3424254712", "6000.0", "0.0", "0.0", "储蓄账户");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public OperationPanel(String id, String name, String personId,
			String balance, String celling, String loan, String accountType) {
		super("用户操作界面");
		isConnected = true;
		getContentPane().setBackground(Color.DARK_GRAY);
		this.setLayout(null);
		this.setBounds(100, 100, 600, 450);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		label = new JLabel();
		label.setForeground(Color.BLUE);
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setFont(new Font("@幼圆", Font.PLAIN, 22));
		label.setText(accountType);
		label.setBounds(113, 10, 375, 32);
		this.add(label);

		label1 = new JLabel();
		label1.setForeground(Color.BLUE);
		label1.setHorizontalAlignment(SwingConstants.CENTER);
		label1.setFont(new Font("@幼圆", Font.PLAIN, 18));
		label1.setText("账号:");
		label1.setBounds(113, 48, 88, 26);
		this.add(label1);

		label2 = new JLabel();
		label2.setForeground(Color.BLUE);
		label2.setHorizontalAlignment(SwingConstants.CENTER);
		label2.setFont(new Font("@幼圆", Font.PLAIN, 18));
		label2.setText("户主:");
		label2.setBounds(113, 80, 88, 26);
		this.add(label2);

		label3 = new JLabel();
		label3.setForeground(Color.BLUE);
		label3.setHorizontalAlignment(SwingConstants.CENTER);
		label3.setFont(new Font("@幼圆", Font.PLAIN, 18));
		label3.setText("身份证:");
		label3.setBounds(113, 112, 88, 26);
		this.add(label3);

		label4 = new JLabel();
		label4.setForeground(Color.BLUE);
		label4.setHorizontalAlignment(SwingConstants.CENTER);
		label4.setFont(new Font("@幼圆", Font.PLAIN, 18));
		label4.setText("账户余额:");
		label4.setBounds(113, 144, 88, 26);
		this.add(label4);

		label7 = new JLabel("透支额度:");
		label7.setForeground(Color.BLUE);
		label7.setHorizontalAlignment(SwingConstants.CENTER);
		label7.setFont(new Font("@幼圆", Font.PLAIN, 18));
		label7.setBounds(113, 144 + 32, 88, 26);
		this.add(label7);

		label8 = new JLabel("已贷款额:");
		label8.setForeground(Color.BLUE);
		label8.setHorizontalAlignment(SwingConstants.CENTER);
		label8.setFont(new Font("@幼圆", Font.PLAIN, 18));
		label8.setBounds(113, 144 + 64, 88, 26);
		this.add(label8);

		checkBox = new JCheckBox("修改密码:");
		checkBox.setFont(new Font("@幼圆", Font.PLAIN, 18));
		checkBox.setForeground(Color.BLUE);
		checkBox.setBackground(Color.DARK_GRAY);
		checkBox.setBounds(86, 176 + 64, 115, 26);
		checkBox.addActionListener(this);
		this.add(checkBox);

		label5 = new JLabel();
		label5.setHorizontalAlignment(SwingConstants.CENTER);
		label5.setForeground(Color.BLUE);
		label5.setFont(new Font("@幼圆", Font.PLAIN, 18));
		label5.setText("操作选项:");
		label5.setBounds(113, 229 + 48, 99, 26);
		this.add(label5);

		comboBox = new JComboBox();
		comboBox.setBackground(Color.LIGHT_GRAY);
		comboBox.setForeground(Color.BLUE);
		comboBox.setFont(new Font("@幼圆", Font.PLAIN, 18));
		comboBox.setBounds(207, 231 + 48, 140, 27);
		comboBox.addItem("取款");
		comboBox.addItem("存款");
		comboBox.addItem("设置透支额度");
		comboBox.addItem("贷款");
		comboBox.addItem("还贷款");
		comboBox.addActionListener(this);
		this.add(comboBox);

		textField = new JTextField();
		// textField.setEditable(false);
		textField.setForeground(Color.BLUE);
		textField.setBackground(Color.LIGHT_GRAY);
		textField.setFont(new Font("@幼圆", Font.PLAIN, 18));
		textField.setBounds(360, 231 + 48, 140, 27);
		this.add(textField);

		textField1 = new JTextField(id);
		textField1.setEditable(false);
		textField1.setForeground(Color.BLUE);
		textField1.setBackground(Color.LIGHT_GRAY);
		textField1.setFont(new Font("@幼圆", Font.PLAIN, 18));
		textField1.setBounds(207, 52, 123, 22);
		this.add(textField1);

		textField2 = new JTextField(name);
		textField2.setForeground(Color.BLUE);
		textField2.setFont(new Font("@幼圆", Font.PLAIN, 18));
		textField2.setEditable(false);
		textField2.setBackground(Color.LIGHT_GRAY);
		textField2.setBounds(207, 84, 123, 22);
		this.add(textField2);

		textField3 = new JTextField(personId);
		textField3.setForeground(Color.BLUE);
		textField3.setFont(new Font("@幼圆", Font.PLAIN, 18));
		textField3.setEditable(false);
		textField3.setBackground(Color.LIGHT_GRAY);
		textField3.setBounds(207, 112, 123, 22);
		this.add(textField3);

		textField4 = new JTextField(balance);
		textField4.setForeground(Color.BLUE);
		textField4.setFont(new Font("@幼圆", Font.PLAIN, 18));
		textField4.setEditable(false);
		textField4.setBackground(Color.LIGHT_GRAY);
		textField4.setBounds(207, 144, 123, 22);
		this.add(textField4);

		textField5 = new JTextField(celling);
		textField5.setForeground(Color.BLUE);
		textField5.setFont(new Font("@幼圆", Font.PLAIN, 18));
		textField5.setEditable(false);
		textField5.setBackground(Color.LIGHT_GRAY);
		textField5.setBounds(207, 112 + 64, 123, 22);
		this.add(textField5);

		textField6 = new JTextField(loan);
		textField6.setForeground(Color.BLUE);
		textField6.setFont(new Font("@幼圆", Font.PLAIN, 18));
		textField6.setEditable(false);
		textField6.setBackground(Color.LIGHT_GRAY);
		textField6.setBounds(207, 112 + 96, 123, 22);
		this.add(textField6);

		passwordField1 = new JPasswordField();
		passwordField1.setForeground(Color.BLUE);
		passwordField1.setEditable(false);
		passwordField1.setBackground(Color.LIGHT_GRAY);
		passwordField1.setFont(new Font("@幼圆", Font.PLAIN, 18));
		passwordField1.setBounds(207, 180 + 64, 123, 22);
		this.add(passwordField1);

		label6 = new JLabel();
		label6.setHorizontalTextPosition(SwingConstants.CENTER);
		label6.setHorizontalAlignment(SwingConstants.RIGHT);
		label6.setFont(new Font("@幼圆", Font.PLAIN, 18));
		label6.setForeground(Color.BLUE);
		label6.setText("确认:");
		label6.setBounds(334, 176 + 64, 66, 24);
		this.add(label6);

		passwordField2 = new JPasswordField();
		passwordField2.setForeground(Color.BLUE);
		passwordField2.setEditable(false);
		passwordField2.setFont(new Font("@幼圆", Font.PLAIN, 18));
		passwordField2.setBackground(Color.LIGHT_GRAY);
		passwordField2.setBounds(395, 180 + 64, 123, 22);
		this.add(passwordField2);

		button1 = new JButton();
		button1.setBackground(Color.LIGHT_GRAY);
		button1.setForeground(Color.MAGENTA);
		button1.setFont(new Font("@幼圆", Font.PLAIN, 18));
		button1.setText("提交");
		button1.setBounds(155, 298 + 32, 106, 28);
		button1.addActionListener(this);
		this.add(button1);

		button2 = new JButton();
		button2.setForeground(Color.MAGENTA);
		button2.setFont(new Font("@幼圆", Font.PLAIN, 18));
		button2.setBackground(Color.LIGHT_GRAY);
		button2.setText("退出");
		button2.setBounds(317, 300 + 32, 106, 28);
		button2.addActionListener(this);
		this.add(button2);
		this.setVisible(true);
	}

	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 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 ("取款成功".equals(str.substring(0, 4))) {
					textField4.setText(str.substring(4));
				}
				if ("存款成功".equals(str.substring(0, 4))) {
					textField4.setText(str.substring(4));
				}
				if ("透支额度设置成功".equals(str.substring(0, 8))) {
					textField5.setText(str.substring(8));
				}
				if ("代款成功".equals(str.substring(0, 4))) {
					textField6.setText(str.substring(4));
				}
				if ("还代款成功".equals(str.substring(0, 5))) {
					textField6.setText(str.substring(5, str.indexOf('/')));
					textField4.setText(str.substring(str.indexOf('/') + 1));
				}
			}
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == button2) {
			send("exit"+textField1.getText());
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
			System.exit(0);
		} else if (e.getSource() == button1) {
			//向服务器发送一些操作命令
			if (comboBox.getSelectedIndex() == 0) {
				send("withdraw" + textField1.getText() + "/"
						+ textField.getText());
			} else if (comboBox.getSelectedIndex() == 1) {
				send("deposit" + textField1.getText() + "/"
						+ textField.getText());
			} else if (comboBox.getSelectedIndex() == 2) {
				send("setCeiling" + textField1.getText() + "/"
						+ textField.getText());
			} else if (comboBox.getSelectedIndex() == 3) {
				send("requestLoan" + textField1.getText() + "/"
						+ textField.getText());
			} else if (comboBox.getSelectedIndex() == 4) {
				send("payLoan" + textField1.getText() + "/"
						+ textField.getText());
			}
		}
	}
}

⌨️ 快捷键说明

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