import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.
import java.awt.
import java.beans.PropertyVetoException;
import java.lang.reflect.Constructor;
import
import java.util.HashMap;
import java.util.Map;
import java.awt.event.*;
import java.awt.*;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.BevelBorder;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
public class JXCFrame
{
private JPanel sysManagePanel;
private JDesktopPane deskPane;
private JFrame fram;
private JLabel backlabel;
private Map<String ,JInternalFrame>
ifs=new HashMap<String,JInternalFrame>();
public JXCFrame()
{
fram=new JFrame("企业进销存管理系统");
fram.getContentPane().setBackground(new Color(170,188,120));
fram.addComponentListener(new FrameListener());
fram.getContentPane().setLayout(new BorderLayout());
fram.setBounds(100,100,800,600);
fram.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
backlabel=new JLabel();
backlabel.setVerticalAlignment(SwingConstants.TOP);
backlabel.setHorizontalAlignment(SwingConstants.CENTER);
updateBackImage();
deskPane=new JDesktopPane();
deskPane.add(backlabel,new Integer(Integer.MIN_VALUE));
fram.getContentPane().add(deskPane);
JTabbedPane navipane=createNavigationPane();
fram.getContentPane().add(navipane,BorderLayout.NORTH);
fram.setVisible(true);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
//new Login();
new JXCFrame();
}
});
}
private final class FrameListener extends ComponentAdapter {
public void componentResized(final ComponentEvent e) {
updateBackImage();
}
}
private void updateBackImage()
{
if(backlabel!=null)
{
int backw = JXCFrame.this.fram.getWidth();
int backh = fram.getHeight();
backlabel.setSize(backw, backh);
backlabel.setText("<html><body><image width='" + backw
+ "' height='" + (backh - 110) + "' src="
+ JXCFrame.this.getClass().getResource("welcome.jpg")
+ "'></img></body></html>");}
}
private JTabbedPane createNavigationPane()
{
JTabbedPane tabpane=new JTabbedPane();
tabpane.setFocusable(false);
tabpane.setBackground(new Color(200,110,189));
tabpane.setBorder(new BevelBorder(BevelBorder.RAISED));
JPanel baseManagerPane=new JPanel();
baseManagerPane.setLayout(new BoxLayout(baseManagerPane,BoxLayout.X_AXIS));
baseManagerPane.setBackground(new Color(220,110,230));
baseManagerPane.add(createFrameButton("客户信息管理","kehugl"));
baseManagerPane.add(createFrameButton("商品信息管理","shuangpigl"));
baseManagerPane.add(createFrameButton("供应商信息管理","gysgl"));
/*JButton jb=new JButton("test");
baseManagerPane.add(jb);
jb.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JPanel jp=new JPanel();
jp.setBounds(100,100,200,150);
jp.setVisible(true);
JInternalFrame jf=new QuanManager();
jf.setVisible(true);
try
{
jf.setSelected(true);
}
catch(Exception ex)
{
System.out.println("jF");
}
//JOptionPane.showMessageDialog(null,"ad","cd",JOptionPane.INFORMATION_MESSAGE);
}
});*/
JPanel kucunManager=new JPanel();
kucunManager.setLayout(new BoxLayout(kucunManager,BoxLayout.X_AXIS));
kucunManager.setBackground(new Color(220,110,230));
kucunManager.add(createFrameButton("库存盘点","kcpd"));
kucunManager.add(createFrameButton("价格调整","jgtz"));
JPanel sellManage=new JPanel();
sellManage.setLayout(new BoxLayout(sellManage,BoxLayout.X_AXIS));
sellManage.setBackground(new Color(220,110,230));
sellManage.add(createFrameButton("销售单","xsd"));
sellManage.add(createFrameButton("销售退货","xsth"));
JPanel chaxunManager=new JPanel();
chaxunManager.setLayout(new BoxLayout(chaxunManager,BoxLayout.X_AXIS));
chaxunManager.setBackground(new Color(220,110,230));
chaxunManager.add(createFrameButton("客户信息查询", "KeHuChaXun"));
chaxunManager.add(createFrameButton("商品信息查询", "SPhaXun"));
chaxunManager.add(createFrameButton("供应商信息查询", "GYSChaXun"));
chaxunManager.add(createFrameButton("销售信息查询", "XiaoShouChaXun"));
chaxunManager.add(createFrameButton("销售退货查询","XiaoShouTuiHuoChaXun"));
chaxunManager.add(createFrameButton("入库查询", "RuKuChaXun"));
chaxunManager.add(createFrameButton("入库退货查询", "RuKuTuiHuoChaXun"));
chaxunManager.add(createFrameButton("销售排行", "XiaoShouPaiHang"));
JPanel stockManagePanel = new JPanel();// 进货管理面板
stockManagePanel.setBackground(new Color(215, 223, 194));
stockManagePanel.setLayout(new BoxLayout(stockManagePanel,BoxLayout.X_AXIS));
stockManagePanel.add(createFrameButton("进货单", "JinHuoDan"));
stockManagePanel.add(createFrameButton("进货退货", "JinHuoTuiHuo"));
sysManagePanel = new JPanel();// 系统管理面板
sysManagePanel.setBackground(new Color(215, 223, 194));
sysManagePanel.setLayout(new BoxLayout(sysManagePanel, BoxLayout.X_AXIS));
sysManagePanel.add(createFrameButton("操作员管理", "CzyGL"));
sysManagePanel.add(createFrameButton("更改密码", "GengGaiMiMa"));
sysManagePanel.add(createFrameButton("权限管理", "QuanManager"));
tabpane.addTab("
基础信息管理
", null, baseManagerPane, "基础信息管理");
tabpane.addTab("
仓库信息管理
", null, kucunManager,
"仓库信息管理");
tabpane.addTab("
销售管理
",null,sellManage,"销售管理");
tabpane.addTab("
查询信息管理
",null,chaxunManager,"查询信息管理");
tabpane.addTab("
进货管理面板
",null,stockManagePanel,"进货管理面板");
tabpane.addTab("
系统管理面板
",null,sysManagePanel,"系统管理面板");
return tabpane;
}
private JButton createFrameButton(String fName,String cName)
{
String imgurl="res/ActionIcon/"+fName+".png";
String imgurl_roll="res/ActionIcon/"+fName+"_roll.png";
String imgurl_down="res/ActionIcon/"+fName+"_down.png";
Icon
icon=new ImageIcon(imgurl);
Icon icon_roll=null;
if(imgurl_roll==null)
icon_roll=new ImageIcon(imgurl_roll);
Icon icon_down=null;
if(icon_down==null)
icon_down=new ImageIcon(imgurl_down);
Action act=new openFrameAction(fName,cName,icon);
JButton but=new JButton(act);
but.setMargin(new Insets(0,0,0,0));
but.setHideActionText(true);
but.setFocusPainted(false);
but.setBorderPainted(false);
but.setContentAreaFilled(false);
if(icon_roll!=null)
but.setRolloverIcon(icon_roll);
if(icon_down!=null)
but.setRolloverIcon(icon_down);
return but;
}
protected final class openFrameAction
extends AbstractAction
{
private String framename=null;
private openFrameAction()
{
}
public openFrameAction(String cName,String framename,Icon icon)
{
this.framename=framename;
putValue(Action.NAME,cName);
putValue(Action.SHORT_DESCRIPTION,cName);
putValue(Action.SMALL_ICON,icon);
}
public void actionPerformed(final ActionEvent e)
{
JInternalFrame jf=getIFrame(framename);
jf.addInternalFrameListener(new InternalFrameAdapter()
{
public void internalFrameClosed(InternalFrameEvent e)
{
ifs.remove(framename);
}
});
if(deskPane==null)
{
deskPane.add(jf);
jf.setVisible(true);
}
try
{
jf.setSelected(true);
}
catch(Exception eee)
{
System.out.println("fail1");
}
}
}
private JInternalFrame getIFrame(String framename)
{
JInternalFrame jf=null;
if(!ifs.containsKey(framename))
{
try
{
Class jfclass=Class.forName(framename);
Constructor con=jfclass.getConstructor(null);
jf=(JInternalFrame)con.newInstance(null);
ifs.put(framename,jf);
}
catch(Exception eeee)
{
System.out.print("fail2");
}
}
else
{
jf=ifs.get(framename);
}
return jf;
}
static
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
System.out.println("fail3");
}
}
}
那我在点相应的按钮时弹不出内部窗体JInternalFrame