mainframe.java~207~

来自「cs结构的一个公交车系统好有使用价值啊下吧--- --- ---」· JAVA~207~ 代码 · 共 403 行

JAVA~207~
403
字号
package bus;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*;
import javax.swing.tree.*;

class MainFrame
    extends JFrame
    implements ActionListener {
  JMenuBar jMenuBar1 = new JMenuBar();
  JMenu mi_xitong = new JMenu();
  JMenuItem mt1 = new JMenuItem();
  JMenuItem mt2 = new JMenuItem();
  JMenuItem mt3 = new JMenuItem();
  JMenu mi_cheliang = new JMenu();
  JMenuItem mt4 = new JMenuItem();
  JMenuItem mt5 = new JMenuItem();
  JMenuItem mt6 = new JMenuItem();
  JMenuItem mt7 = new JMenuItem();
  JMenu mi_feiyong = new JMenu();
  JMenuItem mt8 = new JMenuItem();
  JMenuItem mt9 = new JMenuItem();
  JMenuItem mt10 = new JMenuItem();
  JMenu mi_xianlu = new JMenu();
  JMenuItem mt12 = new JMenuItem();
  JMenu mi_gongju = new JMenu();
  JMenuItem mt13 = new JMenuItem();
  JMenuItem mt14 = new JMenuItem();
  JMenuItem mt15 = new JMenuItem();
  MainPc pc = new MainPc();
  MainPw pw = new MainPw();
  MainPn pn = new MainPn();
  BusManager bm = new BusManager();
  JTree tr = new JTree();

  BorderLayout borderLayout1 = new BorderLayout();
  public static void main(String[] arg) {
    new MainFrame();
  }

  MainFrame() {
    int w = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
    int h = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
    this.setSize(800, 550);
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    this.setTitle("系统主窗口");
    //Container ct=this.getContentPane();
    mi_xitong.setBackground(SystemColor.activeCaptionText);
    mi_xitong.setFont(new java.awt.Font("Dialog", 0, 16));
    mi_xitong.setText("【系统】");
    mt1.setBackground(SystemColor.activeCaptionText);
    mt1.setFont(new java.awt.Font("Dialog", 0, 14));
    mt1.setText("用户权限");
    mt2.setBackground(SystemColor.activeCaptionText);
    mt2.setFont(new java.awt.Font("Dialog", 0, 14));
    mt2.setText("修改密码");
    mt3.setBackground(SystemColor.activeCaptionText);
    mt3.setFont(new java.awt.Font("Dialog", 0, 14));
    mt3.setText("系统退出");
    mi_cheliang.setBackground(SystemColor.activeCaptionText);
    mi_cheliang.setFont(new java.awt.Font("Dialog", 0, 16));
    mi_cheliang.setText("【车辆管理】");
    mt4.setBackground(SystemColor.activeCaptionText);
    mt4.setFont(new java.awt.Font("Dialog", 0, 14));
    mt4.setText("车辆登记");
    mt5.setBackground(SystemColor.activeCaptionText);
    mt5.setFont(new java.awt.Font("Dialog", 0, 14));
    mt5.setText("品牌类型");
    mt6.setBackground(SystemColor.activeCaptionText);
    mt6.setFont(new java.awt.Font("Dialog", 0, 14));
    mt6.setText("车辆类型");
    mt7.setBackground(SystemColor.activeCaptionText);
    mt7.setFont(new java.awt.Font("Dialog", 0, 14));
    mt7.setText("颜色类型");
    mi_feiyong.setBackground(SystemColor.activeCaptionText);
    mi_feiyong.setFont(new java.awt.Font("Dialog", 0, 16));
    mi_feiyong.setText("【费用管理】");
    mt8.setBackground(SystemColor.activeCaptionText);
    mt8.setFont(new java.awt.Font("Dialog", 0, 14));
    mt8.setText("车票收入");
    mt9.setBackground(SystemColor.activeCaptionText);
    mt9.setFont(new java.awt.Font("Dialog", 0, 14));
    mt9.setText("维修费用");
    mt10.setBackground(SystemColor.activeCaptionText);
    mt10.setFont(new java.awt.Font("Dialog", 0, 14));
    mt10.setText("工资支出");
    mi_xianlu.setBackground(SystemColor.activeCaptionText);
    mi_xianlu.setFont(new java.awt.Font("Dialog", 0, 16));
    mi_xianlu.setText("【线路管理】");
    mt12.setBackground(SystemColor.activeCaptionText);
    mt12.setFont(new java.awt.Font("Dialog", 0, 14));
    mt12.setText("公交线路设置");
    mi_gongju.setBackground(SystemColor.activeCaptionText);
    mi_gongju.setFont(new java.awt.Font("Dialog", 0, 16));
    mi_gongju.setText("【小工具】");
    mt13.setBackground(SystemColor.activeCaptionText);
    mt13.setFont(new java.awt.Font("Dialog", 0, 14));
    mt13.setText("金额大小写转换");
    mt14.setBackground(SystemColor.activeCaptionText);
    mt14.setFont(new java.awt.Font("Dialog", 0, 14));
    mt14.setText("电话区号邮政编码");
    mt15.setBackground(SystemColor.activeCaptionText);
    mt15.setFont(new java.awt.Font("Dialog", 0, 14));
    mt15.setText("线路查询");
    JScrollPane sp = new JScrollPane();
    //===树=========
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("西西公交公司");
    DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("线路管理");
    DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("线路查询");
    DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("车辆管理");
    DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("系统维护");
    DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("费用管理");
    DefaultMutableTreeNode node6 = new DefaultMutableTreeNode("小工具");
    DefaultTreeModel treemodel = new DefaultTreeModel(root);
    treemodel.insertNodeInto(node1, root, root.getChildCount());
    treemodel.insertNodeInto(node2, root, root.getChildCount());
    treemodel.insertNodeInto(node3, root, root.getChildCount());
    treemodel.insertNodeInto(node4, root, root.getChildCount());
    treemodel.insertNodeInto(node5, root, root.getChildCount());
    treemodel.insertNodeInto(node6, root, root.getChildCount());
    DefaultMutableTreeNode line = new DefaultMutableTreeNode("公交线路设置");
    treemodel.insertNodeInto(line, node1, node1.getChildCount());
    line = new DefaultMutableTreeNode("车辆登记");
    treemodel.insertNodeInto(line, node3, node3.getChildCount());
    line = new DefaultMutableTreeNode("品牌类型");
    treemodel.insertNodeInto(line, node3, node3.getChildCount());
    line = new DefaultMutableTreeNode("颜色类型");
    treemodel.insertNodeInto(line, node3, node3.getChildCount());
    line = new DefaultMutableTreeNode("车辆类型");
    treemodel.insertNodeInto(line, node3, node3.getChildCount());
    line = new DefaultMutableTreeNode("车票收入");
    treemodel.insertNodeInto(line, node5, node5.getChildCount());
    line = new DefaultMutableTreeNode("维修费用");
    treemodel.insertNodeInto(line, node5, node5.getChildCount());
    line = new DefaultMutableTreeNode("加油支出");
    treemodel.insertNodeInto(line, node5, node5.getChildCount());
    line = new DefaultMutableTreeNode("公司注册");
    treemodel.insertNodeInto(line, node4, node4.getChildCount());
    line = new DefaultMutableTreeNode("修改密码");
    treemodel.insertNodeInto(line, node4, node4.getChildCount());
    line = new DefaultMutableTreeNode("用户权限");
    treemodel.insertNodeInto(line, node4, node4.getChildCount());
    line = new DefaultMutableTreeNode("计算器");
    treemodel.insertNodeInto(line, node6, node6.getChildCount());
    line = new DefaultMutableTreeNode("电话区号邮政编码");
    treemodel.insertNodeInto(line, node6, node6.getChildCount());
    tr.setModel(treemodel);
    tr.setBackground(Color.pink);
    tr.setBackground(new Color(245, 245, 245));
    tr.setFont(new Font("宋体", Font.PLAIN, 20));
    tr.setForeground(new Color(245, 245, 245));
    //====================================
    sp.setViewportView(tr);
    pw.setLayout(borderLayout1);
    pw.setBackground(new Color(224, 224, 254));
    pw.setFont(new java.awt.Font("Dialog", 0, 16));
    pw.setPreferredSize(new Dimension(180, 30));
    sp.getViewport().setBackground(new Color(224, 224, 254));
    sp.setFont(new java.awt.Font("Dialog", 0, 16));
    pn.setBackground(new Color(171, 255, 255));
    pn.setPreferredSize(new Dimension(10, 80));
    jMenuBar1.setBackground(SystemColor.activeCaptionText);
    jMenuBar1.setFont(new java.awt.Font("Dialog", 0, 16));
    this.getContentPane().add(pc, BorderLayout.CENTER);
    this.getContentPane().add(pw, BorderLayout.WEST);
    this.getContentPane().add(pn, BorderLayout.NORTH);
    pw.add(sp, BorderLayout.CENTER);
    sp.setViewportView(tr);
    this.setJMenuBar(jMenuBar1);
    jMenuBar1.add(mi_xitong);
    jMenuBar1.add(mi_cheliang);
    jMenuBar1.add(mi_feiyong);
    jMenuBar1.add(mi_xianlu);
    jMenuBar1.add(mi_gongju);
    mi_xitong.add(mt1);
    mi_xitong.add(mt2);
    mi_xitong.add(mt3);
    mi_cheliang.add(mt4);
    mi_cheliang.add(mt5);
    mi_cheliang.add(mt6);
    mi_cheliang.add(mt7);
    mi_feiyong.add(mt8);
    mi_feiyong.add(mt9);
    mi_feiyong.add(mt10);
    mi_xianlu.add(mt12);
    mi_xianlu.add(mt15);
    mi_gongju.add(mt13);
    mi_gongju.add(mt14);
    mt1.addActionListener(this);
    mt2.addActionListener(this);
    mt3.addActionListener(this);
    mt4.addActionListener(this);
    mt5.addActionListener(this);
    mt6.addActionListener(this);
    mt7.addActionListener(this);
    mt8.addActionListener(this);
    mt9.addActionListener(this);
    mt10.addActionListener(this);
    mt12.addActionListener(this);
    mt13.addActionListener(this);
    mt14.addActionListener(this);
    mt15.addActionListener(this);
    tr.addTreeSelectionListener(new AL());
    this.setVisible(true);
  }

  //class BL implements ActionListener
  //{
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == mt15) {
      pc.removeAll();
      pt p = new pt();
      pc.add(p, "Center");
      pc.validate();
    }
    if (e.getSource() == mt1) {
      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 {
        pc.removeAll();
        QuanXian qx = new QuanXian();
        pc.add(qx, "Center");
        pc.validate();
      }
    }
    if (e.getSource() == mt2) {
      pc.removeAll();
      GaiMi gm = new GaiMi();
      pc.add(gm, "Center");
      pc.validate();
    }
    if (e.getSource() == mt3) {
      System.exit(1);
    }
    if (e.getSource() == mt12) {
      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 {
        pc.removeAll();
        luxian lx = new luxian();
        pc.add(lx, "Center");
        pc.validate();
      }

    }
    if (e.getSource() == mt4) {
      pc.removeAll();
      cd c = new cd();
      pc.add(c, "Center");
      pc.validate();
    }
    if (e.getSource() == mt5) {
      pc.removeAll();
      DL cl = new DL();
      pc.add(cl, "Center");
      pc.validate();
    }
    if (e.getSource() == mt6) {
      pc.removeAll();
      CL cl = new CL();
      pc.add(cl, "Center");
      pc.validate();
    }
    if (e.getSource() == mt7) {
      pc.removeAll();
      EL el = new EL();
      pc.add(el, "Center");
      pc.validate();
    }
    if (e.getSource() == mt8) {
      pc.removeAll();
      ChepPanel cp = new ChepPanel();
      pc.add(cp, "Center");
      pc.validate();
    }
    if (e.getSource() == mt9) {
      pc.removeAll();
      weixiu wx = new weixiu();
      pc.add(wx, "Center");
      pc.validate();
    }
    if (e.getSource() == mt10) {
      pc.removeAll();
      ChepPanel cp = new ChepPanel();
      pc.add(cp, "Center");
      pc.validate();
    }
  }

  //}
  class AL
      implements TreeSelectionListener {
    public void valueChanged(TreeSelectionEvent e) {
      DefaultMutableTreeNode node =
          (DefaultMutableTreeNode) tr.getLastSelectedPathComponent();
      if (node == null) {
        return;
      }
      Object info = node.getUserObject();
      System.out.println(info.toString());
      if (info.equals("公交线路设置")) {
        pc.removeAll();
        luxian lx = new luxian();
        pc.add(lx, "Center");
        pc.validate();
      }
      if (info.equals("用户权限")) {
        String s2 = "select Dengji from QuanXian where People='" + Login.s1 +
            "'";
        Vector vt = bm.selectBus(s2);
        String s3 = ( (Vector) vt.get(0)).get(0).toString();
        int a = Integer.parseInt(s3);
        if (a < 100) {
          JOptionPane.showMessageDialog(null, "您的权限太低,不能进行此项操作");
        }
        else {
          pc.removeAll();
          QuanXian qx = new QuanXian();
          pc.add(qx, "Center");
          pc.validate();
        }
      }
      if (info.equals("修改密码")) {
        pc.removeAll();
        GaiMi gm = new GaiMi();
        pc.add(gm, "Center");
        pc.validate();
      }
      if (info.equals("系统退出")) {
        System.exit(1);
      }
      if (info.equals("车辆登记")) {
        pc.removeAll();
        cd c = new cd();
        pc.add(c, "Center");
        pc.validate();
      }
      if (info.equals("品牌类型")) {
        pc.removeAll();
        DL cl = new DL();
        pc.add(cl, "Center");
        pc.validate();
      }
      if (info.equals("颜色类型")) {
        pc.removeAll();
        EL el = new EL();
        pc.add(el, "Center");
        pc.validate();
      }
      if (info.equals("车辆类型")) {
        pc.removeAll();
        CL cl = new CL();
        pc.add(cl, "Center");
        pc.validate();
      }
      if (info.equals("线路查询")) {
        pc.removeAll();
        pt p = new pt();
        pc.add(p, "Center");
        pc.validate();
      }
      if (info.equals("车票收入")) {
        pc.removeAll();
        ChepPanel cp = new ChepPanel();
        pc.add(cp, "Center");
        pc.validate();
      }
      if (info.equals("维修费用")) {
        pc.removeAll();
        weixiu wx = new weixiu();
        pc.add(wx, "Center");
        pc.validate();
      }
      if (info.equals("工资支出")) {
        pc.removeAll();
        ChepPanel cp = new ChepPanel();
        pc.add(cp, "Center");
        pc.validate();
      }
    }
  }
}

⌨️ 快捷键说明

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