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 panel = new HashMap(); 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(); } }