shichongfu
2023-02-14 aba34133ba4635b7a7c83879550e4d8d98664530
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.lx.product.seal.frame;
 
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.HashMap;
import java.util.Map;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
 
 
public class MasterFrame extends JFrame {
    // 得到显示器屏幕的宽高
    public int width = Toolkit.getDefaultToolkit().getScreenSize().width;
    public int height = Toolkit.getDefaultToolkit().getScreenSize().height - 40;
    // 定义窗体的宽高
    public int windowsWedth = 698;
    public int windowsHeight = 548;
    private Map<String, JPanel> panel = new HashMap<String, JPanel>();
 
    public JPanel getPanel(String name) {
        return panel.get(name);
    }
    public void setPanel(String name, JPanel panel) {
        this.panel.put(name, panel);
    }
   
    JPanel mpanel = new JPanel(new BorderLayout());
 
    public JPanel getMpanel() {
        return mpanel;
    }
 
    public void setMpanel(JPanel mpanel) {
        this.mpanel = mpanel;
    }
 
    private static MasterFrame master;
 
    JPanel current = null;
 
    public MasterFrame() {
        this.setTitle("企业运营管理平台——产品封版");
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        // 设置窗体位置和大小
        this.setBounds((width - windowsWedth) / 2, (height - windowsHeight) / 2, windowsWedth, windowsHeight);
        Toolkit tool = this.getToolkit(); //得到一个Toolkit对象
        Image myimage = tool.getImage("./images/logo.png"); //由tool获取图像
        this.setIconImage(myimage);
        try {
            MasterPanel mp = new MasterPanel(this);
            this.setContentPane(mp);
            this.setResizable(false);
            this.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
    
    public void changedCenterPanel(String name) {
        JPanel p = panel.get(name);
        if (current == null || !p.getName().equals(current.getName())) {
            if (current != null) {
                mpanel.remove(current);
                mpanel.updateUI();
                mpanel.repaint();
                this.repaint();
            }
            mpanel.add(p, BorderLayout.CENTER);
            mpanel.updateUI();
            mpanel.repaint();
            this.repaint();
            current = p;
        }
    }
 
    /**
     * 关闭主界面
     */
    public static void close() {
        master.dispose();
    }
 
    public static void main(String args[]) {
        master = new MasterFrame();
    }
}