?? 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 + -