📄 mainframe.java~178~
字号:
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();
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.setFont(new java.awt.Font("Dialog", 0, 14));
mt1.setText("用户权限");
mt2.setFont(new java.awt.Font("Dialog", 0, 14));
mt2.setText("修改密码");
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.setFont(new java.awt.Font("Dialog", 0, 14));
mt4.setText("车辆登记");
mt5.setFont(new java.awt.Font("Dialog", 0, 14));
mt5.setText("品牌类型");
mt6.setFont(new java.awt.Font("Dialog", 0, 14));
mt6.setText("颜色类型");
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.setFont(new java.awt.Font("Dialog", 0, 14));
mt8.setText("车票收入");
mt9.setFont(new java.awt.Font("Dialog", 0, 14));
mt9.setText("维修费用");
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.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.setFont(new java.awt.Font("Dialog", 0, 14));
mt13.setText("金额大小写转换");
mt14.setFont(new java.awt.Font("Dialog", 0, 14));
mt14.setText("电话区号邮政编码");
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(SystemColor.activeCaptionText);
tr.setFont(new Font("宋体",Font.PLAIN,20));
//====================================
sp.setViewportView(tr);
pw.setLayout(borderLayout1);
pw.setFont(new java.awt.Font("Dialog", 0, 16));
pw.setPreferredSize(new Dimension(180, 30));
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(this);
pc.add(p, "Center");
pc.validate();
}
if (e.getSource() == mt1) {
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 (e.getSource() == mt2) {
pc.removeAll();
GaiMi gm = new GaiMi(this);
pc.add(gm, "Center");
pc.validate();
}
if (e.getSource() == mt3) {
System.exit(1);
}
if (e.getSource() == mt12) {
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();
}
}
//}
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();
}
}
}
}
class Pu
extends JPanel {
private Image image = null;
public Pu() {
image = Toolkit.getDefaultToolkit().getImage("3.jpg");
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0,160,600, this);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -