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