?? newjiaofei.java
字號:
Border border9 = BorderFactory.createEtchedBorder(Color.white,
new Color(165, 163, 151));
JButton jButton1 = new JButton(new ImageIcon("image\\163.gif"));
JButton jButton2 = new JButton(new ImageIcon("image\\48.gif"));
JButton jButton3 = new JButton(new ImageIcon("image\\back.gif"));
Border border10 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
Color.white, new Color(178, 178, 178));
JLabel jLabel10 = new JLabel();
JTextField begin_t = new JTextField();
JTextField end_t = new JTextField();
JTextField givedate_t = new JTextField();
public void jButton2_actionPerformed(ActionEvent e) {
carid_t.setText("");
charges_t.setText("");
begin_t.setText("");
end_t.setText("");
givedate_t.setText("");
payee_t.setText("");
unit_t.setText("");
demo_a.setText("");
}
public void jButton3_actionPerformed(ActionEvent e) {
if (db != null)
db.closeConnection();
this.dispose();
}
public void jButton1_actionPerformed(ActionEvent e) {
String str = "select * from car where 車牌號='" + carid_t.getText().trim() +
"'";
try {
if (!db.getResult(str).first()) {
JOptionPane.showMessageDialog(null, "該車輛不存在!");
carid_t.setText("");
charges_t.setText("");
begin_t.setText("");
end_t.setText("");
givedate_t.setText("");
payee_t.setText("");
unit_t.setText("");
demo_a.setText("");
} else {
str =
"insert into jiaofei(車牌號,費用種類,起始日期,截止日期,交費日期,收款人,收款單位,費用金額,備注) values('" +
carid_t.getText().trim() + "','" +
jComboBox1.getSelectedItem() + "','" +
begin_t.getText().trim() + "','" +
end_t.getText().trim() + "','" +
givedate_t.getText().trim() + "','" +
payee_t.getText().trim() + "','" +
unit_t.getText().trim() + "','" +
charges_t.getText().trim() + "','" +
demo_a.getText().trim() + "'" + ")";
if (db.updateSql(str)) {
JOptionPane.showMessageDialog(null, "添加信息成功!");
carid_t.setText("");
charges_t.setText("");
begin_t.setText("");
end_t.setText("");
givedate_t.setText("");
payee_t.setText("");
unit_t.setText("");
demo_a.setText("");
} else {
JOptionPane.showMessageDialog(null, "添加信息失敗!");
}
}
} catch (HeadlessException ex) {
} catch (SQLException ex) {
}
}
public void carid_t_focusLost(FocusEvent e) {
if (carid_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "車牌號不能為空!");
}
public void begin_t_focusLost(FocusEvent e) {
if (begin_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "起始日期不能為空!");
else {
String s = begin_t.getText().trim() + "!";
char date[] = new char[20];
int i;
date = s.toCharArray();
for (i = 0; date[i] != '!'; i++)
if ((date[i] >= '0' && date[i] <= '9') || date[i] == '.')
;
else {
JOptionPane.showMessageDialog(null,
"您輸入的日期非法或您輸入的日期格式不正確,請以“.”為分隔符!");
begin_t.setText("");
begin_t.setFocusable(true);
break;
}
}
}
public void end_t_focusLost(FocusEvent e) {
if (end_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "截止日期不能為空!");
else {
String s = end_t.getText().trim() + "!";
char date[] = new char[20];
int i;
date = s.toCharArray();
for (i = 0; date[i] != '!'; i++)
if ((date[i] >= '0' && date[i] <= '9') || date[i] == '.')
;
else {
JOptionPane.showMessageDialog(null,
"您輸入的日期非法或您輸入的日期格式不正確,請以“.”為分隔符!");
end_t.setText("");
end_t.setFocusable(true);
break;
}
}
}
public void givedate_t_focusLost(FocusEvent e) {
if (givedate_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "交費日期不能為空!");
else {
String s = givedate_t.getText().trim() + "!";
char date[] = new char[20];
int i;
date = s.toCharArray();
for (i = 0; date[i] != '!'; i++)
if ((date[i] >= '0' && date[i] <= '9') || date[i] == '.')
;
else {
JOptionPane.showMessageDialog(null,
"您輸入的日期非法或您輸入的日期格式不正確,請以“.”為分隔符!");
givedate_t.setText("");
givedate_t.setFocusable(true);
break;
}
}
}
public void charges_t_focusLost(FocusEvent e) {
if (charges_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "交費金額不能為空!");
}
public void payee_t_focusLost(FocusEvent e) {
if (payee_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "收款人不能為空!");
}
public void unit_t_focusLost(FocusEvent e) {
if (unit_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "收款單位不能為空!");
}
public void demo_a_focusLost(FocusEvent e) {
}
public void demo_a_keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
String str = "select * from car where 車牌號='" +
carid_t.getText().trim() +
"'";
try {
if (!db.getResult(str).first()) {
JOptionPane.showMessageDialog(null, "該車輛不存在!");
carid_t.setText("");
charges_t.setText("");
begin_t.setText("");
end_t.setText("");
givedate_t.setText("");
payee_t.setText("");
unit_t.setText("");
demo_a.setText("");
} else {
str =
"insert into jiaofei(車牌號,費用種類,起始日期,截止日期,交費日期,收款人,收款單位,費用金額,備注) values('" +
carid_t.getText().trim() + "','" +
jComboBox1.getSelectedItem() + "','" +
begin_t.getText().trim() + "','" +
end_t.getText().trim() + "','" +
givedate_t.getText().trim() + "','" +
payee_t.getText().trim() + "','" +
unit_t.getText().trim() + "','" +
charges_t.getText().trim() + "','" +
demo_a.getText().trim() + "'" + ")";
if (db.updateSql(str)) {
JOptionPane.showMessageDialog(null, "添加信息成功!");
carid_t.setText("");
charges_t.setText("");
begin_t.setText("");
end_t.setText("");
givedate_t.setText("");
payee_t.setText("");
unit_t.setText("");
demo_a.setText("");
} else {
JOptionPane.showMessageDialog(null, "添加信息失敗!");
}
}
} catch (HeadlessException ex) {
} catch (SQLException ex) {
}
}
}
}
class Newjiaofei_jButton3_actionAdapter implements ActionListener {
private Newjiaofei adaptee;
Newjiaofei_jButton3_actionAdapter(Newjiaofei adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class Newjiaofei_jButton2_actionAdapter implements ActionListener {
private Newjiaofei adaptee;
Newjiaofei_jButton2_actionAdapter(Newjiaofei adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -