📄 findcar.java~42~
字号:
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 java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.Font;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class FindCar extends JFrame {
TableExample te = new TableExample();
DataBaseManager db = null;
ResultSet r;
JPanel jPanel1 = new JPanel();
XYLayout xYLayout1 = new XYLayout();
Border border1 = BorderFactory.createEtchedBorder(Color.white,
new Color(148, 145, 140));
JPanel jPanel2 = new JPanel();
Border border2 = BorderFactory.createEtchedBorder(Color.white,
new Color(148, 145, 140));
JRadioButton jRadioButton1 = new JRadioButton();
JRadioButton jRadioButton2 = new JRadioButton();
XYLayout xYLayout2 = new XYLayout();
XYLayout xYLayout3 = new XYLayout();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JTextField jTextField4 = new JTextField();
JTextField jTextField5 = new JTextField();
JButton jButton1 = new JButton(new ImageIcon("find.gif"));
JButton jButton2 = new JButton(new ImageIcon("back.gif"));
Border border3 = BorderFactory.createEtchedBorder(Color.white,
new Color(165, 163, 151));
Border border4 = BorderFactory.createEtchedBorder(Color.white,
new Color(165, 163, 151));
Border border5 = BorderFactory.createEtchedBorder(Color.white,
new Color(165, 163, 151));
Border border6 = BorderFactory.createEtchedBorder(Color.white,
new Color(165, 163, 151));
JScrollPane jScrollPane1 = new JScrollPane();
JTable jTable1 ;
public FindCar() {
try {
jbInit();
//this.setSize(621,536);
} catch (Exception ex) {
ex.printStackTrace();
}
}
// public static void main(String[] args) {
// FindCar findCar = new FindCar();
//}
private void jbInit() throws Exception {
this.setTitle("沈阳志远出租汽车公司出租车信息管理系统—车辆查询窗口");
this.getContentPane().setLayout(xYLayout1);
jPanel1.setBorder(border1);
jPanel1.setLayout(xYLayout2);
xYLayout1.setWidth(658);
xYLayout1.setHeight(540);
jButton2.setBackground(Color.white);
jButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jButton2.addActionListener(new FindCar_jButton2_actionAdapter(this));
jLabel3.setBorder(border3);
jLabel2.setBorder(border4);
jLabel4.setBorder(border5);
jLabel5.setBorder(border6);
jRadioButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jRadioButton1.setSelected(true);
jRadioButton1.addActionListener(new FindCar_jRadioButton1_actionAdapter(this));
jRadioButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jRadioButton2.addActionListener(new FindCar_jRadioButton2_actionAdapter(this));
jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel1.setText("请输入车牌号:");
jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel2.setText(" 车 牌 号:");
jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel3.setText(" 车辆状态:");
jLabel4.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel4.setText(" 制 造 商:");
jLabel5.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel5.setText(" 违章次数:");
jTextField2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jTextField3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jTextField4.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jTextField5.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jButton1.setText("查找");
jButton1.addActionListener(new FindCar_jButton1_actionAdapter(this));
jRadioButton2.setText("精确查找");
jRadioButton1.setText("快速查找");
jPanel2.setBorder(border2);
jPanel2.setLayout(xYLayout3);
jTextField1.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
jTextField1_keyPressed(e);
}
});
jPanel1.add(jRadioButton1, new XYConstraints(5, 10, -1, -1));
jPanel1.add(jLabel1, new XYConstraints(107, 9, 99, 35));
jPanel1.add(jTextField1, new XYConstraints(232, 9, 130, 34));
this.getContentPane().add(jPanel2, new XYConstraints(22, 86, 508, 95));
jPanel2.add(jTextField4, new XYConstraints(390, 4, 98, 31));
jPanel2.add(jTextField5, new XYConstraints(390, 49, 98, 31));
jPanel2.add(jLabel5, new XYConstraints(311, 49, -1, 31));
jPanel2.add(jLabel4, new XYConstraints(311, 4, 80, 32));
jPanel2.add(jTextField2, new XYConstraints(174, 4, 96, 31));
jPanel2.add(jTextField3, new XYConstraints(174, 50, 96, 31));
jPanel2.add(jLabel3, new XYConstraints(92, 50, 80, 32));
jPanel2.add(jLabel2, new XYConstraints(92, 4, 80, 31));
jPanel2.add(jRadioButton2, new XYConstraints(5, 29, 83, -1));
this.getContentPane().add(jPanel1, new XYConstraints(22, 25, 508, 52));
jTable1 = te.createTable();
jTable1.setFont(new java.awt.Font("宋体", Font.PLAIN, 14));
jScrollPane1.setFont(new java.awt.Font("宋体", Font.PLAIN, 14));
jScrollPane1.getViewport().add(jTable1);
this.getContentPane().add(jScrollPane1,
new XYConstraints(21, 195, 508, 317));
this.getContentPane().add(jButton2, new XYConstraints(545, 115, 95, 50));
this.getContentPane().add(jButton1, new XYConstraints(545, 29, 95, 46));
jTextField2.setEnabled(false) ;
jTextField3.setEnabled(false) ;
jTextField4.setEnabled(false) ;
jTextField5.setEnabled(false) ;
this.setVisible(true);
this.setSize(658, 580);
this.setLocation(170, 50);
addWindowListener(new WindowAdapter() {
public void WindowClosing(WindowEvent e) {
if(db!=null)
db.closeConnection();
dispose();
}
});
}
public void jButton2_actionPerformed(ActionEvent e) {
if (db != null)
db.closeConnection() ;
dispose();
}
public void jButton1_actionPerformed(ActionEvent e) {
String sql = "select * from car where ";
String str1 = "";
String str2 = "";
db = new DataBaseManager();
try {
if (jRadioButton1.isSelected()) {
str1 = "车牌号='" + jTextField1.getText().trim() + "'";
} else if (jRadioButton2.isSelected()) {
str2 = "车牌号='" + jTextField2.getText().trim() + "' and 车辆状态='" +
jTextField3.getText().trim() + "' and 制造商='" +
jTextField4.getText().trim() + "' and 违章次数='" +
jTextField5.getText().trim() + "'";
}
if (!str1.equals("")) {
if (!db.getResult(sql + str1).first()) {
String s = "没有编号为" + jTextField1.getText().trim() +
"的车辆,请重新输入车牌号。";
JOptionPane.showMessageDialog(null, s);
jTextField1.setText("");
} else {
te.fetch(sql + str1);
}
} else {
if (!db.getResult(sql + str2).first()) {
String s = "该记录不存在,请仔细查对您输入的关键字。";
JOptionPane.showMessageDialog(null, s);
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
} else {
te.fetch(sql + str2);
}
}
} catch (HeadlessException ex) {
} catch (SQLException ex) {
}
}
public void jRadioButton1_actionPerformed(ActionEvent e) {
if (jRadioButton1.isSelected()) {
jRadioButton2.setSelected(false);
jTextField2.setEnabled(false);
jTextField3.setEnabled(false);
jTextField4.setEnabled(false);
jTextField5.setEnabled(false);
jTextField1.setEnabled(true);
}
}
public void jRadioButton2_actionPerformed(ActionEvent e) {
if(jRadioButton2.isSelected() )
{
jRadioButton1.setSelected(false);
jTextField1.setEnabled(false);
jTextField2.setEnabled(true);
jTextField3.setEnabled(true);
jTextField4.setEnabled(true);
jTextField5.setEnabled(true);
}
}
public void jTextField1_keyPressed(KeyEvent e) {
}
}
class FindCar_jRadioButton2_actionAdapter implements ActionListener {
private FindCar adaptee;
FindCar_jRadioButton2_actionAdapter(FindCar adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jRadioButton2_actionPerformed(e);
}
}
class FindCar_jRadioButton1_actionAdapter implements ActionListener {
private FindCar adaptee;
FindCar_jRadioButton1_actionAdapter(FindCar adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jRadioButton1_actionPerformed(e);
}
}
class FindCar_jButton1_actionAdapter implements ActionListener {
private FindCar adaptee;
FindCar_jButton1_actionAdapter(FindCar adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class FindCar_jButton2_actionAdapter implements ActionListener {
private FindCar adaptee;
FindCar_jButton2_actionAdapter(FindCar adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -