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

📄 sendpay.java

📁 财务管理子系统-支出系统
💻 JAVA
字号:
// SendPay.java

package classFile;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.sql.*;

class SendPay extends JPanel implements ActionListener
{
	// 工资支出
	private JLabel number; // 员工编号
	private JLabel money; // 工资 
	private JLabel dates; // 日期
	private JLabel remark; // 备注
	
	private JTextField numberText;
	private JTextField moneyText;
	private JComboBox yearText;
	private JComboBox monthText;
	private JComboBox dayText;
	private JTextArea remarkText;
	private JScrollPane remarkScroll;
	
	private JButton submitButton;
	private JButton resetButton;
	private JButton exitButton;
	
	private JLabel flag1 = new JLabel("*", JLabel.CENTER);
	private JLabel flag2 = new JLabel("*", JLabel.CENTER);
	
	// 静态变量
	private final String years[] = new String[100];
	private final String months[] = new String[12];
	private final String days[] = new String[31];
	
	public SendPay()
	{
		// 初始化数组
		Long k = 1951L;
		for (int i=0; i<100; i++) {
			years[i] = k.toString();
			k++;
		}
		
		k = 1L;
		for (int i=0; i<12; i++) {
			months[i] = k.toString();
			k++;
		}
		
		k = 1L;
		for (int i=0; i<31; i++) {
			days[i] = k.toString();
			k++;
		}
		
		// 面板属性
		this.setLayout(null);
		this.setBackground(new Color(200, 180, 100));
		
		// 初始化
		number = new JLabel("员工编号:", JLabel.RIGHT);
		money = new JLabel("工资:", JLabel.RIGHT);
		dates = new JLabel("日期:", JLabel.RIGHT);
		remark = new JLabel("备注:", JLabel.RIGHT);
		
		numberText = new JTextField();
		moneyText = new JTextField();
		yearText = new JComboBox(years);
		monthText = new JComboBox(months);
		dayText = new JComboBox(days);
		remarkText = new JTextArea();
		remarkScroll = new JScrollPane(remarkText);
		
		submitButton = new JButton("提交");
		resetButton = new JButton("重置");
		exitButton = new JButton("退出");
		
		// 控件属属性属于
		Font font = new Font("隶书", Font.PLAIN, 15);
		number.setFont(font);
		money.setFont(font);
		dates.setFont(font);
		remark.setFont(font);
		
		flag1.setFont(new Font("宋体", Font.PLAIN, 15));
		flag2.setFont(new Font("宋体", Font.PLAIN, 15));
		
		flag1.setForeground(Color.red);
		flag2.setForeground(Color.red);
		
		// 控件定位
		flag1.setBounds(420, 50, 10, 20);
		flag2.setBounds(420, 90, 10, 20);
		
		number.setBounds(0, 50, 200, 20);
		money.setBounds(0, 90, 200, 20);
		dates.setBounds(0, 130, 200, 20);
		remark.setBounds(0, 170, 200, 20);
		
		numberText.setBounds(210, 50, 200, 20);
		moneyText.setBounds(210, 90, 200, 20);
		yearText.setBounds(210, 130, 80, 20);
		monthText.setBounds(290, 130, 60, 20);
		dayText.setBounds(350, 130, 60, 20);
		remarkScroll.setBounds(210, 170, 300, 150);
		
		submitButton.setBounds(210, 400, 60, 20);
		resetButton.setBounds(330, 400, 60, 20);
		exitButton.setBounds(450, 400, 60, 20);
		
		// 添加控件
		this.add(flag1);
		this.add(flag2);
		this.add(number);
		this.add(money);
		this.add(dates);
		this.add(remark);
		this.add(numberText);
		this.add(moneyText);
		this.add(yearText);
		this.add(monthText);
		this.add(dayText);
		this.add(remarkScroll);
		this.add(submitButton);
		this.add(resetButton);
		this.add(exitButton);
			
		// 事件监听
		submitButton.addActionListener(this);
		resetButton.addActionListener(this);
		exitButton.addActionListener(this);
	}
	
	// 监听函数
	public void actionPerformed(ActionEvent event) 
	{
		if (event.getSource() == submitButton) 
		{
			String info[] = new String[4];
			info[0] = numberText.getText().trim();
			info[1] = moneyText.getText().trim();
			info[2] = years[yearText.getSelectedIndex()] + "-"
				+ months[monthText.getSelectedIndex()] + "-"
				+ days[dayText.getSelectedIndex()];
			info[3] = remarkText.getText().trim();
			
			if (info[0].equals("") || info[1].equals(""))
			{
				JOptionPane.showMessageDialog(null, "带星号的为必填项!!");
			}
			else
			{
				try
				{
					VisitData visiter = new VisitData();
					visiter.DBLind("insert into payMoney values(?,?,?,?)");
					visiter.pre.setString(1, info[0]);
					visiter.pre.setString(2, info[1]);
					visiter.pre.setString(3, info[2]);
					visiter.pre.setString(4, info[3]);
					visiter.pre.executeUpdate();
					
					JOptionPane.showMessageDialog(null, "信息已经保存!!");
					setBlank();
				}
				catch(Exception e)
				{
					JOptionPane.showMessageDialog(null, "数据被破坏!!");
					e.printStackTrace();
				}
			}
		}
		else if (event.getSource() == resetButton) 
		{
			setBlank();
		}
		else {
			System.exit(0);
		}
	}
	
	// 
	private void setBlank()
	{
		numberText.setText("");
		moneyText.setText("");
		yearText.setSelectedIndex(0);
		monthText.setSelectedIndex(0);
		dayText.setSelectedIndex(0);
		remarkText.setText("");			
	}
}

⌨️ 快捷键说明

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