📄 8099a02e8a30001d14bca828f5ee0475
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.*;
import javax.swing.JSplitPane;
import javax.swing.tree.*;
import java.util.*;
public class JFrameMain extends JFrame implements TreeSelectionListener {
/**
* @param args
*/
JScrollPane jScrollPane1 = new JScrollPane();
JSplitPane jSplitPane1 = new JSplitPane();
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("汽车修理管理系统");
JTree jtree = new JTree(rootNode);
WelcomePane wel = new WelcomePane();
Thread thread;
UserInfo user;
CarInfo car;
QueryUser Quser;
PrintMenu printMenu;
PersonMoney personMoney;
PartQuery partQuery;
InputProduct inputproduct;
BuyProduct buyproduct;
SaleQuery salequery;
public JFrameMain() {
super("汽车修理管理系统");
this.setSize(800, 400);
this.getContentPane().add(jSplitPane1);// 添加一个分割面板
jSplitPane1.setLeftComponent(jScrollPane1);
// 在左侧的分割面板中添加一个滚动面板
jSplitPane1.setRightComponent(wel);
// 在右侧的分割面板中添加一个欢迎面板
jScrollPane1
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane1
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
// 设置滚动水平、垂直滚动条
jScrollPane1.getViewport().setView(jtree);
jtree.setBackground(Color.YELLOW);
this.initTree();
jtree.expandRow(0);// 显示根节点
jtree.expandRow(1);// 显示数据登记节点
jtree.expandRow(6);// 显示查询功能节点
jtree.expandRow(13);// 季度零件订货计划节点
jtree.expandRow(15);// 打印发票节点
jtree.expandRow(17);// 打印修理工工资月报表:
jtree.addTreeSelectionListener(this);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
}
public void initTree() {
DefaultMutableTreeNode childNode1 = new DefaultMutableTreeNode("数据登记");
rootNode.add(childNode1);
DefaultMutableTreeNode childNode2 = new DefaultMutableTreeNode("用户登记");
childNode1.add(childNode2);
childNode2 = new DefaultMutableTreeNode("汽车维修");
childNode1.add(childNode2);
childNode2 = new DefaultMutableTreeNode("进货登记");
childNode1.add(childNode2);
childNode2 = new DefaultMutableTreeNode("销售查询");
childNode1.add(childNode2);
// 完成数据登记模块
childNode1 = new DefaultMutableTreeNode("功能查询");
rootNode.add(childNode1);
childNode2 = new DefaultMutableTreeNode("用户信息查询");
childNode1.add(childNode2);
childNode2 = new DefaultMutableTreeNode("维修信息查询");
childNode1.add(childNode2);
childNode2 = new DefaultMutableTreeNode("零件库存查询");
childNode1.add(childNode2);
// 完成查询功能操作
childNode1 = new DefaultMutableTreeNode("季度零件订货计划");
rootNode.add(childNode1);
childNode2 = new DefaultMutableTreeNode("订货具体操作");
childNode1.add(childNode2);
// 完成季度零件订货计划
childNode1 = new DefaultMutableTreeNode("发票信息打印");
rootNode.add(childNode1);
childNode2 = new DefaultMutableTreeNode("客户发票打印");
childNode1.add(childNode2);
// 发票信息打印
childNode1 = new DefaultMutableTreeNode("修理工工资月报表打印");
rootNode.add(childNode1);
childNode2 = new DefaultMutableTreeNode("修理工月工资报表操作");
childNode1.add(childNode2);
}
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jtree
.getLastSelectedPathComponent();
if (selectedNode.toString() == "用户登记") {
user = new UserInfo();
jSplitPane1.setRightComponent(user);
} else if (selectedNode.toString() == "汽车维修") {
car = new CarInfo();
jSplitPane1.setRightComponent(car);
} else if (selectedNode.toString() == "进货登记") {
inputproduct = new InputProduct();
jSplitPane1.setRightComponent(inputproduct);
} else if (selectedNode.toString() == "销售查询") {
salequery=new SaleQuery();
jSplitPane1.setRightComponent(salequery);
} else if (selectedNode.toString() == "用户信息查询") {
Quser = new QueryUser();
jSplitPane1.setRightComponent(Quser);
} else if (selectedNode.toString() == "维修信息查询") {
} else if (selectedNode.toString() == "零件库存查询") {
partQuery = new PartQuery();
jSplitPane1.setRightComponent(partQuery);
} else if (selectedNode.toString() == "订货具体操作") {
buyproduct = new BuyProduct();
jSplitPane1.setRightComponent(buyproduct);
} else if (selectedNode.toString() == "客户发票打印") {
printMenu = new PrintMenu();
jSplitPane1.setRightComponent(printMenu);
} else if (selectedNode.toString() == "修理工月工资报表操作") {
personMoney = new PersonMoney();
jSplitPane1.setRightComponent(personMoney);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new JFrameMain();
}
}
class WelcomePane extends JPanel implements Runnable {
JLabel lbShow = new JLabel("欢迎测试", JLabel.CENTER);
JPanel panel;
Thread thread;
ImageIcon icon = new ImageIcon("6.jpg");
JLabel lbImg = new JLabel(icon);
JLabel lbTime = new JLabel("");
JLabel lbZ=new JLabel("中");
JLabel lbG=new JLabel("国");
JLabel lbJ=new JLabel("加");
JLabel lbY=new JLabel("油");
JLabel lbS=new JLabel("四");
JLabel lbC=new JLabel("川");
JLabel lbX=new JLabel("雄");
JLabel lbQ=new JLabel("起");
public WelcomePane() {
thread = new Thread(this);
thread.start();
init();
}
public void init() {
Font font2 = new Font("楷体", Font.BOLD, 30);
lbShow.setFont(font2);
lbShow.setBounds(300, 100, 200, 70);
lbTime.setBounds(391, 307, 40, 40);
Font f=new Font("楷体",Font.BOLD,20);
lbZ.setBounds(200, 140, 40, 40);
lbG.setBounds(200, 220, 40, 40);
lbJ.setBounds(200, 300, 40, 40);
lbY.setBounds(200, 380, 40, 40);
lbZ.setFont(f);
lbG.setFont(f);
lbJ.setFont(f);
lbY.setFont(f);
lbS.setBounds(580, 140, 40, 40);
lbC.setBounds(580, 220, 40, 40);
lbX.setBounds(580, 300, 40, 40);
lbQ.setBounds(580, 380, 40, 40);
lbS.setFont(f);
lbC.setFont(f);
lbX.setFont(f);
lbQ.setFont(f);
lbImg.add(lbZ);
lbImg.add(lbG);
lbImg.add(lbJ);
lbImg.add(lbY);
lbImg.add(lbS);
lbImg.add(lbC);
lbImg.add(lbX);
lbImg.add(lbQ);
lbImg.add(lbShow);
lbImg.add(lbTime);
add(lbImg, SwingConstants.CENTER);
}
public void run() {
try {
Thread.sleep(1500);
} catch (Exception e) {
e.printStackTrace();
}
for (int i = 10; i >= 0; i--) {
Random rand = new Random();
int r = rand.nextInt(255);
int g = rand.nextInt(255);
int b = rand.nextInt(255);
Color color = new Color(r, g, b);
Color color2 = new Color(g, r, b);
lbZ.setForeground(color);
lbG.setForeground(color2);
lbJ.setForeground(color);
lbY.setForeground(color2);
lbS.setForeground(color);
lbC.setForeground(color2);
lbX.setForeground(color);
lbQ.setForeground(color2);
Random rand1 = new Random();
int size = rand1.nextInt(8) + 25;
Font font2 = new Font("楷体", Font.BOLD, size);
lbShow.setForeground(color2);
lbTime.setForeground(color);
lbTime.setFont(font2);
lbTime.setText(i + " ");
try {
Thread.sleep(1000);
} catch (Exception e) {
System.out.println("发生意外!");
e.printStackTrace();
}
}
lbShow.setText("右边窗口测试");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -