📄 findcar.java~26~
字号:
package carmanage;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.Rectangle;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import java.sql.Connection;
import DB.Db.*;
import DB.Db;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class FindCar extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
JLabel jLabel10 = new JLabel();
JTextField txtCarId = new JTextField();
JTextField txtCarType = new JTextField();
JButton btnFind1 = new JButton();
JButton btnExit = new JButton();
JButton btnFind2 = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
JTable jTableShow = new JTable();
JButton jButton1 = new JButton();
public FindCar() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
this.setSize(400,400);
this.setVisible(true);
setTitle("查询车辆信息窗口");
jLabel1.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel1.setText("查询车辆信息");
jLabel1.setBounds(new Rectangle(142, 27, 145, 44));
jLabel2.setText("车牌号码:");
jLabel2.setBounds(new Rectangle(50, 93, 63, 30));
jLabel3.setText("车辆类型:");
jLabel3.setBounds(new Rectangle(50, 131, 67, 28));
jLabel10.setBounds(new Rectangle(20, 453, 84, 32));
txtCarId.setText("");
txtCarId.setBounds(new Rectangle(123, 94, 141, 29));
txtCarType.setText("");
txtCarType.setBounds(new Rectangle(124, 133, 141, 27));
btnFind1.setBounds(new Rectangle(278, 90, 65, 29));
btnFind1.setText("查找");
btnFind1.addActionListener(new FindCar_btnFind1_actionAdapter(this));
btnExit.setBounds(new Rectangle(323, 441, 65, 28));
btnExit.setText("退出");
btnFind2.setBounds(new Rectangle(277, 131, 65, 27));
btnFind2.setText("查找");
btnFind2.addActionListener(new FindCar_btnFind2_actionAdapter(this));
jScrollPane1.setBounds(new Rectangle(28, 165, 344, 234));
jButton1.setBounds(new Rectangle(248, 404, 93, 25));
jButton1.setText("返回");
jButton1.addActionListener(new FindCar_jButton1_actionAdapter(this));
contentPane.add(jLabel8);
contentPane.add(jLabel9);
contentPane.add(jLabel10);
contentPane.add(jLabel1);
contentPane.add(btnFind1);
contentPane.add(btnFind2);
contentPane.add(txtCarId);
contentPane.add(txtCarType);
contentPane.add(jLabel3);
contentPane.add(jLabel2);
contentPane.add(btnExit);
contentPane.add(jScrollPane1);
contentPane.add(jButton1);
jScrollPane1.getViewport().add(jTableShow);
}
public void btnFind1_actionPerformed(ActionEvent e) {
String Username=txtCarId.getText().trim();
Connection connection=null;
ResultSet rSet=null;
Statement statement=null;
if(Username.length()!=0)
{
try {
String datas[][] = null ;
int count = 1;
Connection con = new Db().getCon() ;
statement = con.createStatement();
String sql = "select * from Car where CarId='" +
txtCarId.getText() + "'";
rSet = statement.executeQuery(sql);
if(rSet.next()==false){
/*JOptionPane msg = new JOptionPane();
JOptionPane.showConfirmDialog(this, "请正确填写车牌号码!", "没有此姓名的申请单", 2);*/
JOptionPane.showMessageDialog(this,"请正确填写车牌号码!","提示",JOptionPane.ERROR_MESSAGE);
txtCarId.setText("");
}
else {
datas = new String[count][];
int i = 0;
datas[i] = new String[] {"" + rSet.getString("CarId"), rSet.getString("Car"),
rSet.getString("CarType"), rSet.getString("CarPlace"),
rSet.getString("CarColor"), rSet.getString("CarPrice")
};
i++;
String head[] ={"车牌号码","车型","车辆类型","产地","颜色","价格"};
jTableShow = new JTable(datas, head);
jScrollPane1.getViewport().add( jTableShow);
}
}catch (Exception ex) {
ex.printStackTrace();
}
}
else
{
JOptionPane.showMessageDialog(null,"用户名不能为空!","提示",JOptionPane.ERROR_MESSAGE);
}
}
public void btnFind2_actionPerformed(ActionEvent e) {
String Username=txtCarType.getText().trim();
Connection connection=null;
ResultSet rSet=null;
Statement statement=null;
if(Username.length()!=0)
{
try {
String datas[][] = null ;
int count = 1;
Connection con = new Db().getCon() ;
statement = con.createStatement();
String sql = "select * from Car where CarType='" +
txtCarType.getText() + "'";
rSet = statement.executeQuery(sql);
if(rSet.next()==false){
/*JOptionPane msg = new JOptionPane();
JOptionPane.showConfirmDialog(this, "请正确填写车牌号码!", "没有此姓名的申请单", 2);*/
JOptionPane.showMessageDialog(this,"请正确填写车牌号码!","提示",JOptionPane.ERROR_MESSAGE);
txtCarType.setText("");
}
else {
datas = new String[count][];
int i = 0;
datas[i] = new String[] {"" + rSet.getString("CarId"), rSet.getString("Car"),
rSet.getString("CarType"), rSet.getString("CarPlace"),
rSet.getString("CarColor"), rSet.getString("CarPrice")
};
// i++;
String head[] ={"车牌号码","车型","车辆类型","产地","颜色","价格"};
jTableShow = new JTable(datas, head);
jScrollPane1.getViewport().add( jTableShow);
}
}catch (Exception ex) {
ex.printStackTrace();
}
}
else
{
JOptionPane.showMessageDialog(null,"用户名不能为空!","提示",JOptionPane.ERROR_MESSAGE);
}
}
public void jButton1_actionPerformed(ActionEvent e) {
this.dispose();
}
}
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_btnFind2_actionAdapter implements ActionListener {
private FindCar adaptee;
FindCar_btnFind2_actionAdapter(FindCar adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnFind2_actionPerformed(e);
}
}
class FindCar_btnFind1_actionAdapter implements ActionListener {
private FindCar adaptee;
FindCar_btnFind1_actionAdapter(FindCar adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnFind1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -