📄 weixiu.java
字号:
package bus;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
import javax.swing.table.*;
public class weixiu
extends JPanel {
JPanel pe1 = new JPanel();
JPanel pe2 = new JPanel();
JButton bt2 = new JButton("增加");
JButton bt3 = new JButton("删除");
JButton bt4 = new JButton("修改");
JButton bt5 = new JButton("取消");
BorderLayout borderLayout1 = new BorderLayout();
JLabel le1 = new JLabel();
JComboBox Box1 = new JComboBox();
JButton bt1 = new JButton();
Vector head = new Vector();
DefaultTableModel model = new DefaultTableModel();
BusManager bm = new BusManager();
JButton bt_save = new JButton();
static String wx;
JPanel jPanel1 = new JPanel();
JScrollPane jScrollPane1 = new JScrollPane();
BorderLayout borderLayout2 = new BorderLayout();
JTable table1 = new JTable();
weixiu() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public void jbInit() throws Exception {
this.setLayout(borderLayout1);
le1.setFont(new java.awt.Font("Dialog", 0, 14));
le1.setText("请输入查询车辆:");
bt1.setBackground(new Color(254, 231, 251));
bt1.setFont(new java.awt.Font("Dialog", 0, 12));
bt1.setPreferredSize(new Dimension(60, 25));
bt1.setText("查询");
Box1.setBackground(new Color(254, 231, 251));
Box1.setPreferredSize(new Dimension(150, 22));
Box1.setRequestFocusEnabled(true);
Box1.setPopupVisible(false);
bt2.setBackground(new Color(254, 231, 251));
bt2.setFont(new java.awt.Font("Dialog", 0, 12));
bt2.setPreferredSize(new Dimension(60, 25));
bt3.setBackground(new Color(254, 231, 251));
bt3.setFont(new java.awt.Font("Dialog", 0, 12));
bt3.setPreferredSize(new Dimension(60, 25));
bt4.setBackground(new Color(254, 231, 251));
bt4.setFont(new java.awt.Font("Dialog", 0, 12));
bt4.setAlignmentY( (float) 0.5);
bt4.setPreferredSize(new Dimension(60, 25));
bt4.setFocusPainted(true);
bt5.setBackground(new Color(254, 231, 251));
bt5.setFont(new java.awt.Font("Dialog", 0, 12));
bt5.setPreferredSize(new Dimension(60, 25));
bt_save.setBackground(new Color(254, 231, 251));
bt_save.setFont(new java.awt.Font("Dialog", 0, 12));
bt_save.setPreferredSize(new Dimension(60, 25));
bt_save.setFocusPainted(true);
bt_save.setText("保存");
this.setFont(new java.awt.Font("Dialog", 0, 16));
this.setForeground(SystemColor.window);
pe1.setBackground(new Color(224, 224, 254));
pe1.setForeground(SystemColor.info);
pe2.setBackground(new Color(224, 224, 254));
pe2.setForeground(SystemColor.window);
jPanel1.setLayout(borderLayout2);
jPanel1.setBackground(new Color(254, 231, 251));
jScrollPane1.getViewport().setBackground(new Color(224, 224, 254));
table1.setBackground(new Color(224, 224, 254));
table1.setFont(new java.awt.Font("Dialog", 0, 16));
pe1.add(le1, null);
this.add(pe1, BorderLayout.NORTH);
pe1.add(Box1, null);
pe1.add(bt1, null);
pe2.add(bt2);
pe2.add(bt_save, null);
pe2.add(bt3);
pe2.add(bt4);
pe2.add(bt5);
this.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(table1, null);
this.add(pe2, "South");
head.add("ID");
head.add("车牌号");
head.add("维修类型");
head.add("维修时间");
head.add("维修天数");
head.add("维修记录");
head.add("维修地点");
head.add("维修费用");
table1.setGridColor(Color.pink);
table1.getTableHeader().setBackground(new Color(224, 224, 254));
table1.getTableHeader().setFont(new Font("宋体", Font.PLAIN, 16));
table1.setRowHeight(30);
model.setColumnIdentifiers(head);
table1.setModel(model);
Box1.addItem("全部");
Vector no = new Vector();
no = bm.selectBus("select BusPai from BusGuanli");
for (int i = 0; i < no.size(); i++) {
Vector vt = new Vector();
vt = (Vector) no.get(i);
Box1.addItem(vt.get(0));
}
bt1.addActionListener(new AL());
bt2.addActionListener(new AL());
bt3.addActionListener(new AL());
bt4.addActionListener(new AL());
bt_save.addActionListener(new AL());
}
//**************************************
class AL
implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bt1) {
String name = Box1.getSelectedItem().toString();
if (name.equals("全部")) {
String s = "select * from ModJilu";
Vector one = bm.selectBus(s);
model.setDataVector(one, head);
}
else {
String s = "select * from ModJilu where BusPai='" + name + "'";
Vector one = bm.selectBus(s);
model.setDataVector(one, head);
}
}
if (e.getSource() == bt2) {
String s2 = "select Dengji from QuanXian where People='" + Login.s1 +
"'";
Vector mo = bm.selectBus(s2);
String s3 = ( (Vector) mo.get(0)).get(0).toString();
int a = Integer.parseInt(s3);
if (a < 100) {
JOptionPane.showMessageDialog(null, "您的权限太低,不能进行此项操作");
}
else {
model.addRow(new Vector());
}
}
if (e.getSource() == bt3) {
String s2 = "select Dengji from QuanXian where People='" + Login.s1 +
"'";
Vector mo = bm.selectBus(s2);
String s3 = ( (Vector) mo.get(0)).get(0).toString();
int a = Integer.parseInt(s3);
if (a < 100) {
JOptionPane.showMessageDialog(null, "您的权限太低,不能进行此项操作");
}
else {
int row = table1.getSelectedRow();
if (row < 0)
return;
String obj = model.getValueAt(row, 0).toString();
int b = Integer.parseInt(obj);
String s = "delete from ModJilu where id=" + obj;
System.out.println(obj);
System.out.println(s);
bm.updateBus(s);
model.removeRow(row);
System.out.println("删除成功");
}
}
if (e.getSource() == bt_save) {
String s2 = "select Dengji from QuanXian where People='" + Login.s1 +
"'";
Vector mo = bm.selectBus(s2);
String s3 = ( (Vector) mo.get(0)).get(0).toString();
int a = Integer.parseInt(s3);
if (a < 100) {
JOptionPane.showMessageDialog(null, "您的权限太低,不能进行此项操作");
}
else {
System.out.println("jsdkfjeklwjfk");
int row = table1.getSelectedRow();
String pai = model.getValueAt(row, 1).toString();
String leix = model.getValueAt(row, 2).toString();
String time = model.getValueAt(row, 3).toString();
int day = Integer.parseInt(model.getValueAt(row, 4).toString());
String jilu = model.getValueAt(row, 5).toString();
String place = model.getValueAt(row, 6).toString();
double money = Double.parseDouble(model.getValueAt(row, 7).toString());
System.out.print(money);
String id = model.getValueAt(row, 0).toString();
String s = "insert into ModJilu (BusPai,ModNum,ModTime,ModDay,ModJilu,ModPlace,ModMon) values('" +
pai + "','" + leix + "','" + time + "'," + day + ",'" + jilu +
"','" + place + "'," + money + ")";
bm.updateBus(s);
}
}
if (e.getSource() == bt4) {
String s2 = "select Dengji from QuanXian where People='" + Login.s1 +
"'";
Vector mo = bm.selectBus(s2);
String s3 = ( (Vector) mo.get(0)).get(0).toString();
int a = Integer.parseInt(s3);
if (a < 100) {
JOptionPane.showMessageDialog(null, "您的权限太低,不能进行此项操作");
}
else {
int row = table1.getSelectedRow();
wx = model.getValueAt(row, 0).toString();
new XaddFrame();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -