⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tj.java~12~

📁 cs结构的一个公交车系统好有使用价值啊下吧--- --- ---
💻 JAVA~12~
字号:
package bus;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Vector;
import javax.swing.border.*;
class tj
    extends JFrame {
  JLabel cp = new JLabel("车牌");
  JTextField tf_cp = new JTextField(10);
  JLabel cl = new JLabel("车辆类型");
  JComboBox bo = new JComboBox();
  JLabel cy = new JLabel("车辆颜色");
  String[] colors = {
      " 白色", "红色", "蓝色", "绿色"};
  JComboBox box = new JComboBox(colors);
  JLabel sj = new JLabel("司机");
  JTextField tf_sj = new JTextField(10);
  JButton bt_img = new JButton(new ImageIcon("1.GIF"));
  JLabel bz = new JLabel("备注:");
  JTextArea ta = new JTextArea(20, 20);
  JButton bt_save = new JButton("保存");
  JButton bt = new JButton("取消");
  BusManager db = new BusManager();
  tj() {
    this.setSize(500, 500);
    bt_save.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    bt.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    this.setTitle("车辆信息");
    this.setBackground(new Color(224,224,254));
    Container ct = this.getContentPane();
    JPanel pc = new JPanel();
    pc.setLayout(new GridBagLayout());
    bt.setFont(new java.awt.Font("Dialog", 0, 12));
    bt.setPreferredSize(new Dimension(60, 25));
    bt.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.setBackground(new Color(254, 231, 251));
    bt_img.setFont(new java.awt.Font("Dialog", 0, 12));
    bt_img.setPreferredSize(new Dimension(60, 25));
    bt_img.setBackground(new Color(254, 231, 251));
    ta.setBackground(new Color(254, 231, 251));
    bo.setBackground(new Color(254, 231, 251));
    GridBagConstraints cons = new GridBagConstraints();
    cons.insets = new Insets(10, 10, 10, 10);
    cons.gridx = 0;
    cons.gridy = 0;
    pc.add(cp, cons);
    cons.gridx = 1;
    cons.gridy = 0;
    pc.add(tf_cp, cons);
    cons.gridx = 2;
    cons.gridy = 0;
    bo.addItem("卡车");
    bo.addItem("微型车");
    bo.addItem("客车");
    bo.addItem("摩托车");
    bo.addItem("轿车");
    bo.addItem("巴士");
    bo.addItem("中巴士");
    pc.add(cl, cons);
    cons.gridx = 3;
    cons.gridy = 0;
    bo.setPreferredSize(new Dimension(100, 20));
    pc.add(bo, cons);
    cons.gridx = 0;
    cons.gridy = 1;
    pc.add(cy, cons);
    cons.gridx = 1;
    cons.gridy = 1;
    box.setPreferredSize(new Dimension(110, 20));
    pc.add(box, cons);
    cons.gridx = 2;
    cons.gridy = 1;
    pc.add(sj, cons);
    cons.gridx = 3;
    cons.gridy = 1;
    pc.add(tf_sj, cons);
    cons.gridx = 4;
    cons.gridy = 1;
    pc.add(bt_img, cons);
    bt_img.addActionListener(new Al());
    cons.gridx = 0;
    cons.gridy = 2;
    pc.add(bz, cons);
    ct.add(pc, "North");
    ta.setLineWrap(true); //设置转行
    JScrollPane sp = new JScrollPane(ta);
    ct.add(sp, "Center");
    JPanel ps = new JPanel();
    sp.getViewport().setBackground(new Color(224, 224, 254));
    ps.setBackground(new Color(224, 224, 254));
    bt_save.setPreferredSize(new Dimension(60, 25));
    bt_save.setBorder(BorderFactory.createLoweredBevelBorder());
    ps.add(bt_save);
    bt_save.addActionListener(new Al());
    bt.setPreferredSize(new Dimension(60, 25));
    bt.setBorder(BorderFactory.createLoweredBevelBorder());
    ps.add(bt);
    bt.addActionListener(new Al());
    ct.add(ps, "South");
    this.setVisible(true);
  }

  public void setName(String siji) {
    tf_sj.setText(siji);
  }

  class Al
      implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      if (e.getSource() == bt_img) {
        cx c = new cx(tj.this);
      }
      else if (e.getSource() == bt_save) {
        if (tf_cp.getText().equals("")) {
          JOptionPane.showMessageDialog(null, "车牌号不能为空!");
        }
        else {

          String s1 = tf_cp.getText();
          String s2 = tf_sj.getText();
          String s3 = bo.getSelectedItem().toString();
          String s4 = box.getSelectedItem().toString();
          String s5 =
              "insert into BusGuanli (BusPai,BusNum,BusColor,SiJi) values('" +
              s1 + "','" + s3 + "','" + s4 + "','" + s2 + "')";
          db.updateBus(s5);
          System.out.println(s5);
          tf_cp.setText("");
          tf_sj.setText("");
          ta.setText("");
        }
      }
      else if (e.getSource() == bt) {
        tj.this.setCursor(Cursor.HAND_CURSOR);
        tj.this.dispose();
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -