📄 otherpayout.java
字号:
// OtherPayout.java
package classFile;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.sql.*;
class OtherPayout extends JPanel implements ActionListener
{
// 差旅支出
private JLabel name; // 出差人名字
private JLabel cases; // 为何事务
private JLabel money; // 开支
private JLabel dates; // 日期
private JLabel remark; // 备注
private JButton submitButton; // 提交
private JButton resetButton; // 重置
private JButton exitButton; // 退出
private JTextField nameText; // 名字编辑框
private JTextArea caseText; // 事务概述
private JScrollPane caseScroll; // caseText滑动面板
private JTextField moneyText; // 开支输入
private JComboBox yearText; // 年
private JComboBox monthText; // 月
private JComboBox dayText; // 日
private JTextArea remarkText; // 备注编辑框
private JScrollPane remarkScroll;// 备注框滚动框
private String years[] = new String[100];
private String months[] = new String[12];
private String days[] = new String[31];
private JLabel flag1 = new JLabel("*", JLabel.CENTER);
private JLabel flag2 = new JLabel("*", JLabel.CENTER);
private JLabel flag3 = new JLabel("*", JLabel.CENTER);
public OtherPayout()
{
// 初始化数组
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.setBackground(new Color(220, 120, 200));
this.setLayout(null);
// 初始化控件-------------------------------------------------------------
name = new JLabel("出差人名字:", JLabel.RIGHT);
cases = new JLabel("事务概述:", JLabel.RIGHT);
money = new JLabel("经费:", JLabel.RIGHT);
dates = new JLabel("日期:", JLabel.RIGHT);
remark = new JLabel("备注:", JLabel.RIGHT);
submitButton = new JButton("提交");
resetButton = new JButton("重置");
exitButton = new JButton("退出");
nameText = new JTextField();
caseText = new JTextArea();
caseScroll = new JScrollPane(caseText);
moneyText = new JTextField();
yearText = new JComboBox(years);
monthText = new JComboBox(months);
dayText = new JComboBox(days);
remarkText = new JTextArea();
remarkScroll = new JScrollPane(remarkText);
Font font1 = new Font("宋体", Font.PLAIN, 15);
flag1.setFont(font1);
flag2.setFont(font1);
flag3.setFont(font1);
Color color = Color.red;
flag1.setForeground(color);
flag2.setForeground(color);
flag3.setForeground(color);
// 字体
Font font = new Font("隶书", Font.PLAIN, 15);
name.setFont(font);
cases.setFont(font);
dates.setFont(font);
money.setFont(font);
remark.setFont(font);
// 布局控件
flag1.setBounds(420, 50, 10, 20);
flag2.setBounds(520, 90, 10, 20);
flag3.setBounds(420, 180, 10, 20);
name.setBounds(0, 50, 200, 20);
cases.setBounds(0, 90, 200, 20);
money.setBounds(0, 180, 200, 20);
dates.setBounds(0, 220, 200, 20);
remark.setBounds(0, 260, 200, 20);
nameText.setBounds(210, 50, 200, 20);
caseScroll.setBounds(210, 90, 300, 75);
moneyText.setBounds(210, 180, 200, 20);
yearText.setBounds(210, 220, 80, 20);
monthText.setBounds(290, 220, 60, 20);
dayText.setBounds(350, 220, 60, 20);
remarkScroll.setBounds(210, 260, 300, 150);
submitButton.setBounds(210, 440, 60, 20);
resetButton.setBounds(330, 440, 60, 20);
exitButton.setBounds(450, 440, 60, 20);
// 添加到面板
this.add(flag1);
this.add(flag2);
this.add(flag3);
this.add(name);
this.add(cases);
this.add(money);
this.add(dates);
this.add(remark);
this.add(nameText);
this.add(caseScroll);
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 boolean checkBlank(String info[])
{
for (int i=0; i<info.length-2; i++)
{
if (info[i].equals(""))
{
return false;
}
}
return true;
}
// 事件监听函数
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == submitButton)
{
String info[] = new String[5];
info[0] = nameText.getText().trim();
info[1] = caseText.getText().trim();
info[2] = moneyText.getText().trim();
info[3] = years[yearText.getSelectedIndex()] + "-"
+ months[monthText.getSelectedIndex()] + "-"
+ days[dayText.getSelectedIndex()];
info[4] = remarkText.getText().trim();
if (checkBlank(info))
{
try
{
VisitData visiter = new VisitData();
visiter.DBLind("insert into others 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.setString(5, info[4]);
visiter.pre.executeUpdate();
JOptionPane.showMessageDialog(null, "信息已经保存!!");
setBlank();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "数据被破坏!!");
e.printStackTrace();
}
}
else
{
JOptionPane.showMessageDialog(null, "带星号的为必填项");
}
}
else if (event.getSource() == resetButton)
{
setBlank();
}
else
{
System.exit(0);
}
}
// 清空
private void setBlank()
{
nameText.setText(""); // 名字编辑框
caseText.setText(""); // 事务概述
moneyText.setText(""); // 开支输入
yearText.setSelectedIndex(0); // 年
monthText.setSelectedIndex(0); // 月
dayText.setSelectedIndex(0); // 日
remarkText.setText(""); // 备注编辑框
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -