📄 newweizhang.java~27~
字号:
package car;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
import javax.swing.*;
import java.awt.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.awt.event.FocusEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
public class Newweizhang extends JFrame {
public Newweizhang() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
// public static void main(String[] args) {
// Newweizhang newweizhang = new Newweizhang();
// }
private void jbInit() throws Exception {
jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel1.setBorder(border1);
jLabel1.setText(" 违章车号:");
this.getContentPane().setLayout(xYLayout1);
jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel3.setBorder(BorderFactory.createEtchedBorder());
jLabel3.setText(" 违章日期:");
jLabel4.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel4.setBorder(BorderFactory.createEtchedBorder());
jLabel4.setText(" 违章地点:");
breaklowaddress_t.setText("");
breaklowaddress_t.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
breaklowaddress_t_focusLost(e);
}
});
jLabel5.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel5.setBorder(BorderFactory.createEtchedBorder());
jLabel5.setText(" 罚款金额:");
penaltymoney_t.setText("");
penaltymoney_t.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
penaltymoney_t_focusLost(e);
}
});
xYLayout1.setWidth(567);
xYLayout1.setHeight(458);
jLabel6.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel6.setBorder(BorderFactory.createEtchedBorder());
jLabel6.setText(" 处理单位:");
unit_t.setText("");
unit_t.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
unit_t_focusLost(e);
}
});
jLabel7.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel7.setBorder(BorderFactory.createEtchedBorder());
jLabel7.setText(" 违章原因:");
breaklowreason_a.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
breaklowreason_a.setBorder(border2);
breaklowreason_a.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
breaklowreason_a_focusLost(e);
}
});
jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jButton1.setText("清 空");
jButton1.addActionListener(new Newweizhang_jButton1_actionAdapter(this));
jButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jButton2.setText("添 加");
jButton2.addActionListener(new Newweizhang_jButton2_actionAdapter(this));
jButton3.setBackground(Color.white);
jButton3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jButton3.addActionListener(new Newweizhang_jButton3_actionAdapter(this));
jLabel8.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel8.setBorder(BorderFactory.createEtchedBorder());
jLabel8.setText(" 元");
breakdate_t.setText("");
breakdate_t.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
breakdate_t_focusLost(e);
}
});
breakcarid_t.addFocusListener(new Newweizhang_breakcarid_t_focusAdapter(this));
drivername_t.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
drivername_t_focusLost(e);
}
});
this.setTitle(
"沈阳志远出租汽车公司出租车信息管理系统--添加违章信息窗口");
this.getContentPane().add(jLabel1, new XYConstraints(67, 42, 82, 31));
drivername_t.setText("");
jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel2.setBorder(border1);
jLabel2.setText(" 驾驶员姓名:");
this.getContentPane().add(breakcarid_t,
new XYConstraints(151, 42, 103, 31));
this.getContentPane().add(jLabel3, new XYConstraints(67, 89, -1, 31));
this.getContentPane().add(jLabel5, new XYConstraints(67, 138, -1, 31));
this.getContentPane().add(jLabel2, new XYConstraints(314, 43, -1, 31));
this.getContentPane().add(jLabel6, new XYConstraints(314, 138, 96, 31));
this.getContentPane().add(jLabel4, new XYConstraints(314, 90, 96, 31));
this.getContentPane().add(breaklowaddress_t,
new XYConstraints(412, 90, 101, 31));
this.getContentPane().add(unit_t,
new XYConstraints(412, 138, 101, 31));
this.getContentPane().add(drivername_t,
new XYConstraints(412, 43, 102, 31));
this.getContentPane().add(jLabel7, new XYConstraints(67, 189, -1, 31));
this.getContentPane().add(jButton1, new XYConstraints(240, 374, 78, 40));
this.getContentPane().add(jButton2, new XYConstraints(122, 373, 80, 40));
this.getContentPane().add(breaklowreason_a,
new XYConstraints(151, 189, 360, 143));
this.getContentPane().add(penaltymoney_t,
new XYConstraints(151, 138, 70, 31));
this.getContentPane().add(jLabel8, new XYConstraints(220, 138, 31, 31));
this.getContentPane().add(breakdate_t,
new XYConstraints(151, 89, 103, 31));
this.getContentPane().add(jButton3, new XYConstraints(354, 375, 89, 47));
this.setVisible(true);
this.setSize(565, 487);
this.setLocation(170, 50);
addWindowListener(new WindowAdapter() {
public void WindowClosing(WindowEvent e) {
if(db!=null)
db.closeConnection();
dispose();
}
});
}
DataBaseManager db=null;
ResultSet r;
JLabel jLabel1 = new JLabel();
XYLayout xYLayout1 = new XYLayout();
Border border1 = BorderFactory.createEtchedBorder(Color.white,
new Color(165, 163, 151));
JTextField breakcarid_t = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField drivername_t = new JTextField();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JTextField breaklowaddress_t = new JTextField();
JLabel jLabel5 = new JLabel();
JTextField penaltymoney_t = new JTextField();
JLabel jLabel6 = new JLabel();
JTextField unit_t = new JTextField();
JLabel jLabel7 = new JLabel();
JTextArea breaklowreason_a = new JTextArea();
Border border2 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
Color.white, new Color(178, 178, 178));
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton(new ImageIcon("back.gif"));
JLabel jLabel8 = new JLabel();
JTextField breakdate_t = new JTextField();
public void jButton1_actionPerformed(ActionEvent e) {
breakcarid_t.setText("") ;
drivername_t.setText("") ;
breaklowaddress_t.setText("") ;
breakdate_t.setText("");
penaltymoney_t.setText("") ;
unit_t.setText("") ;
breaklowreason_a.setText("") ;
}
public void jButton3_actionPerformed(ActionEvent e) {
if(db!=null)
db.closeConnection() ;
this.dispose();
}
public void jButton2_actionPerformed(ActionEvent e) {
db=new DataBaseManager();
String str = "select * from car where 车牌号='"+breakcarid_t.getText().trim()+"'";
try {
if (!db.getResult(str).first()) {
JOptionPane.showMessageDialog(null,
"该车辆不存在!");
breakcarid_t.setText("");
drivername_t.setText("");
breaklowaddress_t.setText("");
breakdate_t.setText("");
penaltymoney_t.setText("");
unit_t.setText("");
breaklowreason_a.setText("");
} else {
str = "insert into weizhang(违章车号,驾驶员,违章日期,违章地点,罚款金额,处理单位,违章原因) values('" +
breakcarid_t.getText().trim() + "','" +
drivername_t.getText().trim() + "','" +
breakdate_t.getText().trim() + "','" +
breaklowaddress_t.getText().trim() + "','" +
penaltymoney_t.getText().trim() + "','" +
unit_t.getText() .trim() + "','" +
breaklowreason_a.getText().trim() + "'" + ")";
if (db.updateSql(str)) {
JOptionPane.showMessageDialog(null,
"添加信息成功!");
String strSQL = "update car set 违章次数=违章次数+1" +
" where 车牌号='" +
breakcarid_t.getText().trim() +
"'";
if (db.updateSql(strSQL))
;
breakcarid_t.setText("");
drivername_t.setText("");
breaklowaddress_t.setText("");
breakdate_t.setText("");
penaltymoney_t.setText("");
unit_t.setText("");
breaklowreason_a.setText("");
} else {
JOptionPane.showMessageDialog(null, "添加信息失败!");
}
}
} catch (HeadlessException ex) {
} catch (SQLException ex) {
}
}
public void breakcarid_t_focusLost(FocusEvent e) {
if (breakcarid_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "车牌号不能为空!");
}
public void drivername_t_focusLost(FocusEvent e) {
if (drivername_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "驾驶员姓名不能为空!");
}
public void breakdate_t_focusLost(FocusEvent e) {
if (breakdate_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "违章日期不能为空!");
else {
String s = breakdate_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] == '.' ||
date[i] == '/' || date[i] == '-')
;
else {
JOptionPane.showMessageDialog(null,
"您输入的日期非法或您输入的日期格式不正确,请以“.”、“/”或“-”为分隔符!");
breakdate_t.setText("");
breakdate_t.setFocusable(true);
break;
}
}
}
public void breaklowaddress_t_focusLost(FocusEvent e) {
if (breaklowaddress_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "违章地点不能为空!");
}
public void penaltymoney_t_focusLost(FocusEvent e) {
if (penaltymoney_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 breaklowreason_a_focusLost(FocusEvent e) {
if (breaklowreason_a.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "违章原因不能为空!");
}
}
class Newweizhang_breakcarid_t_focusAdapter extends FocusAdapter {
private Newweizhang adaptee;
Newweizhang_breakcarid_t_focusAdapter(Newweizhang adaptee) {
this.adaptee = adaptee;
}
public void focusLost(FocusEvent e) {
adaptee.breakcarid_t_focusLost(e);
}
}
class Newweizhang_jButton3_actionAdapter implements ActionListener {
private Newweizhang adaptee;
Newweizhang_jButton3_actionAdapter(Newweizhang adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class Newweizhang_jButton1_actionAdapter implements ActionListener {
private Newweizhang adaptee;
Newweizhang_jButton1_actionAdapter(Newweizhang adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Newweizhang_jButton2_actionAdapter implements ActionListener {
private Newweizhang adaptee;
Newweizhang_jButton2_actionAdapter(Newweizhang adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -