import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.beans.PropertyVetoException;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;import net.hlj.hqtt.listerner.AddMoneyListerner;
import net.hlj.hqtt.listerner.UserCedeListerner;public class Main {
public static JDesktopPane desktopPane; private static JFrame frame; private JLabel backLabel; public static Map<String, JInternalFrame> ifs = new HashMap<String, JInternalFrame>(); public Main() { frame = new JFrame("管理系统");
frame.setBounds(0, 0, 1000, 700);
frame.getContentPane().setBackground(new Color(170, 188, 120)); frame.getContentPane().setLayout(new BorderLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("管理系统");
JMenuBar menubar1 = new JMenuBar();// 添加菜单条组件
frame.setJMenuBar(menubar1);// 将菜单条添加到顶层容器中
JMenu menu1 = new JMenu("会员卡管理"); // 设置菜单组件
JMenu menu2 = new JMenu("商品管理");
JMenu menu4 = new JMenu("会员卡管理 ");
JMenu menu3 = new JMenu("系统管理");
menubar1.add(menu1);// 将菜单组件添加到菜单条组件中
menubar1.add(menu2);
menubar1.add(menu4);
menubar1.add(menu3);

// JMenuItem item1 = new JMenuItem("网上会员开卡");// 创建菜单项组件 JMenuItem item3 = new JMenuItem("会员过户");
JMenuItem item4 = new JMenuItem("充值");
menu1.add(createFrameButton("老会员开卡", "user.OldUserCardFrame"));
menu1.add(createFrameButton("新会员开卡", "user.NewUserCardFrame"));
menu1.add(createFrameButton("挂失", "user.UserCardLossFrame"));
menu1.add(createFrameButton("解除挂失", "user.UserCardUnLossFrame"));
menu1.add(createFrameButton("补卡", "user.UserSecondCardFrame"));
menu1.add(createFrameButton("消卡", "user.UserCardCancelFrame"));
menu1.add(createFrameButton("积分转存", "user.UserScoreTrunFrame"));
  // menu1.add(item1); // 将菜单项组件添加到相应的菜单组件中去 menu1.addSeparator();// 菜单项之间的分割线组件
menu1.add(item3);
menu1.add(item4);
menu1.addSeparator(); // JMenuItem item2_1 = new JMenuItem("购买商品");
// menu2.add(createFrameButton("购买商品", "goods.BuyGoodsFrame")); menu2.add(createFrameButton("添加商品", "goods.AddGoodsFrame")); menu2.add(createFrameButton("退货管理", "goods.BackGoodsFrame")); JMenuItem item2_4 = new JMenuItem("购买商品");
menu2.add(createFrameButton("销售查询", "goods.QuerySaleFrame"));
item2_4.addActionListener(new BuyGoodsListerner());
item3.addActionListener(new UserCedeListerner());
item4.addActionListener(new AddMoneyListerner());
menu2.add(createFrameButton("商品管理", "goods.QueryGoodsFrame"));
JMenuItem item2_6 = new JMenuItem("购买商品3");
menu3.add(createFrameButton("关于我们", "sys.AboutFrame"));
menu3.add(createFrameButton("更新数据", "sys.UpdateSQL"));
menu2.add(item2_4);
menu4.add(createFrameButton("充值记录", "goods.QueryCardListFrame"));
menu4.add(createFrameButton("消费记录", "goods.QueryCardSaleListFrame")); // menu2.add(item2_6); backLabel = new JLabel();// 背景标签
backLabel.setVerticalAlignment(SwingConstants.TOP);
backLabel.setHorizontalAlignment(SwingConstants.CENTER);
updateBackImage(); // 更新或初始化背景图片
desktopPane = new JDesktopPane();
desktopPane.add(backLabel, new Integer(Integer.MIN_VALUE));
frame.getContentPane().add(desktopPane);
frame.setVisible(true);
} public static void main(String args[]) { SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Main();
}
});
} /** *********************辅助方法************************* */
// 为内部窗体添加Action的方法
private JMenuItem 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 (imgUrl_down != null)
icon_down = new ImageIcon(imgUrl_down);
Action action = new openFrameAction(fName, cname, icon);
JMenuItem button = new JMenuItem(action);
button.setMargin(new Insets(0, 0, 0, 0)); button.setFocusPainted(false);
button.setBorderPainted(false);
button.setContentAreaFilled(false);
if (icon_roll != null)
button.setRolloverIcon(icon_roll);
if (icon_down != null)
button.setPressedIcon(icon_down);
return button;
} // 获取内部窗体的唯一实例对象
private JInternalFrame getIFrame(String frameName) {
JInternalFrame jf = null;
if (!ifs.containsKey(frameName)) {
try {
Class fClass = Class.forName("net.hlj.hqtt.frame." + frameName);
Constructor constructor = fClass.getConstructor(null);
jf = (JInternalFrame) constructor.newInstance(null);
jf.setClosable(true);
jf.setMaximizable(true);
jf.setResizable(true);
jf.isOpaque();
ifs.put(frameName, jf);
} catch (Exception e) {
e.printStackTrace();
}
} else
jf = ifs.get(frameName);
jf.setClosable(true);
jf.setMaximizable(true);
jf.setResizable(true);
jf.isOpaque();

return jf;
} // 更新背景图片的方法
private void updateBackImage() {
if (backLabel != null) {
int backw = Main.this.frame.getWidth();
int backh = frame.getHeight();
backLabel.setSize(backw, backh);
backLabel.setText("<html><body><image width='" + backw
+ "' height='" + (backh - 61) + "' src="
+ Main.this.getClass().getResource("welcome.jpg")
+ "'></img></body></html>");
System.out.println(Main.this.getClass().getResource("welcome.jpg"));
}
} // 窗体监听器
private final class FrameListener extends ComponentAdapter {
public void componentResized(final ComponentEvent e) {
updateBackImage();
}
} // 主窗体菜单项的单击事件监听器
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);
// 在内部窗体闭关时,从内部窗体容器ifs对象中清除该窗体。
jf.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosed(InternalFrameEvent e) {
ifs.remove(frameName);
}
});
if (jf.getDesktopPane() == null) {
desktopPane.add(jf);
jf.setVisible(true);
}
try {
jf.setSelected(true);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
}
}
} static {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
}swing Jframe