JF_main.java
上传用户:whbcdz
上传日期:2008-08-04
资源大小:7683k
文件大小:10k
源码类别:

JavaScript

开发平台:

Java

  1. package appjxc.view;
  2. import java.awt.BorderLayout;
  3. import java.awt.Dimension;
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.*;
  7. import javax.swing.border.*;
  8. import appjxc.constrol.MenuBarEvent;
  9. import java.awt.Font;
  10. import java.awt.SystemColor;
  11. import java.awt.Toolkit;
  12. import java.awt.Color;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ActionEvent;
  15. public class JF_main extends JFrame {
  16.     JPanel contentPane;
  17.     BorderLayout borderLayout1 = new BorderLayout();
  18.     public static JDesktopPane desktop = new JDesktopPane();
  19.     //自定义事件类处理
  20.     MenuBarEvent _MenuBarEvent = new MenuBarEvent();
  21.     JMenuBar jMenuBarMain = new JMenuBar();
  22.     JToolBar jToolBarMain = new JToolBar();
  23.     Border border1;
  24.     JLabel jLabel1 = new JLabel();
  25.     Border border2;
  26.     public JF_main() {
  27.         try {
  28.             setDefaultCloseOperation(EXIT_ON_CLOSE);
  29.             //根据两个方法buildMenu()和buildToolBar()建立菜单和工具栏
  30.             BuildMenuBar();
  31.             BuildToolBar();
  32.             jbInit();
  33.             loadBackgroundImage();
  34.         } catch (Exception exception) {
  35.             exception.printStackTrace();
  36.         }
  37.     }
  38.     /**
  39.      * Component initialization.
  40.      *
  41.      * @throws java.lang.Exception
  42.      */
  43.     private void jbInit() throws Exception {
  44.         contentPane = (JPanel) this.getContentPane();
  45.         border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white, Color.red);
  46.         border2 = BorderFactory.createLineBorder(new Color(255, 55, 166), 1);
  47.         contentPane.setLayout(borderLayout1);
  48.         jMenuBarMain.setFont(new Font("宋体", 0, 12));
  49.         jLabel1.setFont(new java.awt.Font("新宋体", 0, 12));
  50.         jLabel1.setForeground(new Color(255, 104, 69));
  51.         jLabel1.setBorder(border2);
  52.         _MenuBarEvent.setDeskTop(this.desktop);
  53.         jToolBarMain.setBorder(border1);
  54.         this.setJMenuBar(jMenuBarMain);
  55.         this.setResizable(false);
  56.         jToolBarMain.setFloatable(false);
  57.         desktop.setBackground(SystemColor.desktop);
  58.         contentPane.add(jToolBarMain, BorderLayout.NORTH);
  59.         contentPane.add(desktop, BorderLayout.CENTER);
  60.         contentPane.add(jLabel1, BorderLayout.SOUTH);
  61.         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  62.         Dimension frameSize = getSize();
  63.         if (frameSize.height > screenSize.height) {
  64.             frameSize.height = screenSize.height;
  65.         }
  66.         if (frameSize.width > screenSize.width) {
  67.             frameSize.width = screenSize.width;
  68.         }
  69.         setLocation((screenSize.width - frameSize.width) / 2,
  70.                           (screenSize.height - frameSize.height) / 2);
  71.          setVisible(true);
  72.          this.setSize(new Dimension(900, 700));
  73.          setTitle("医药进销存管理系统");
  74.     }
  75.     protected void loadBackgroundImage(){
  76.         ImageIcon icon = new ImageIcon(".\images\main.jpg");
  77.         //ImageIcon icon = new ImageIcon(JF_main.class.getResource("main_bg.jpg"));
  78.         JLabel jl = new JLabel(icon);
  79.         jl.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());
  80.         desktop.add(jl,new Integer(Integer.MIN_VALUE));
  81.         //desktop.add(jl,BorderLayout.CENTER);
  82.     }
  83.     private void BuildMenuBar(){
  84.         JMenu[] _jMenu = {new JMenu("【基本信息】"), new JMenu("【业务管理】"),
  85.                          new JMenu("【业务查询】"), new JMenu("【用户管理】"),
  86.                          new JMenu("【系统管理】")};
  87.         /*设置菜单相目JMenuItem元素*/
  88.         JMenuItem[] _jMenuItem0 = {new JMenuItem("【药品情况】"),
  89.                                   new JMenuItem("【客户情况】"),
  90.                                   new JMenuItem("【供应商情况】")};
  91.         String[] _jMenuItem0Name = {"JF_view_medicine", "JF_view_client","JF_view_gys"};
  92.         JMenuItem[] _jMenuItem1 = {new JMenuItem("【药品采购】"),
  93.                                   new JMenuItem("【药品销售】"),
  94.                                   new JMenuItem("【库存盘点】"),
  95.                                   new JMenuItem("【销售退货】"),
  96.                                   new JMenuItem("【客户回款】")};
  97.         String[] _jMenuItem1Name = {"JF_view_buy", "JF_view_sell","JF_view_stock", "JF_view_xstk","JF_view_hkgl"};
  98.         JMenuItem[] _jMenuItem3 = {new JMenuItem("【增加用户】"),
  99.                                   new JMenuItem("【用户维护】")};
  100.         String[] _jMenuItem3Name = {"sys_user_add", "sys_user_modify"};
  101.         JMenuItem[] _jMenuItem4 = {
  102.                                   new JMenuItem("【系统退出】")};//new JMenuItem("【重新登陆】"),
  103.         String[] _jMenuItem4Name = {"JB_EXIT"};//"JB_LOGIN",
  104.         JMenuItem[] _jMenuItem2 = {new JMenuItem("【基本信息】"),
  105.                                       new JMenuItem("【入库明细】"),
  106.                                       new JMenuItem("【销售明细】"),
  107.                                       new JMenuItem("【回款信息】")};
  108.                                       //new JMenuItem("【退库信息】")};
  109.         String[] _jMenuItem2Name = {"JF_view_query_jbqk", "JF_view_query_rkqk", "JF_view_query_kcmx_ck",
  110.                                        "JF_view_query_kcmx_hk", ""};
  111.         /*设置菜单、菜单项字体风格*/
  112.         Font _MenuItemFont = new Font("宋体", 0, 12);
  113.         for (int i = 0; i < _jMenu.length; i++) {
  114.             _jMenu[i].setFont(_MenuItemFont);
  115.             jMenuBarMain.add(_jMenu[i]);
  116.         }
  117.         for (int j = 0; j < _jMenuItem0.length; j++) {
  118.             _jMenuItem0[j].setFont(_MenuItemFont);
  119.             final String EventName1 = _jMenuItem0Name[j];
  120. //            _jMenuItem0[j].addActionListener(_MenuBarEvent);
  121.             _jMenuItem0[j].addActionListener(new ActionListener() {
  122.                 public void actionPerformed(ActionEvent e) {
  123.                     _MenuBarEvent.setEventName(EventName1);
  124.                     _MenuBarEvent.actionPerformed(e);
  125.                 }
  126.             });
  127.             _jMenu[0].add(_jMenuItem0[j]);
  128.             if (j == 1) {
  129.                 _jMenu[0].addSeparator();
  130.             }
  131.         }
  132.         for (int j = 0; j < _jMenuItem1.length; j++) {
  133.             _jMenuItem1[j].setFont(_MenuItemFont);
  134.             final String EventName1 = _jMenuItem1Name[j];
  135.             _jMenuItem1[j].addActionListener(_MenuBarEvent);
  136.             _jMenuItem1[j].addActionListener(new ActionListener() {
  137.                 public void actionPerformed(ActionEvent e) {
  138.                     _MenuBarEvent.setEventName(EventName1);
  139.                 }
  140.             });
  141.             _jMenu[1].add(_jMenuItem1[j]);
  142.             if (j == 1) {
  143.                 _jMenu[1].addSeparator();
  144.             }
  145.             if (j == 2) {
  146.                 _jMenu[1].addSeparator();
  147.             }
  148.         }
  149.         for (int j = 0; j < _jMenuItem2.length; j++) {
  150.             _jMenuItem2[j].setFont(_MenuItemFont);
  151.             final String EventName2 = _jMenuItem2Name[j];
  152.             _jMenuItem2[j].addActionListener(_MenuBarEvent);
  153.             _jMenuItem2[j].addActionListener(new ActionListener() {
  154.                 public void actionPerformed(ActionEvent e) {
  155.                     _MenuBarEvent.setEventName(EventName2);
  156.                     // _MenuBarEvent.getName();
  157.                 }
  158.             });
  159.             _jMenu[2].add(_jMenuItem2[j]);
  160.             if ((j == 0 )||(j==2)) {
  161.                 _jMenu[2].addSeparator();
  162.             }
  163.         }
  164.         for (int j = 0; j < _jMenuItem3.length; j++) {
  165.             _jMenuItem3[j].setFont(_MenuItemFont);
  166.             final String EventName3 = _jMenuItem3Name[j];
  167.             _jMenuItem3[j].addActionListener(_MenuBarEvent);
  168.             _jMenuItem3[j].addActionListener(new ActionListener() {
  169.                 public void actionPerformed(ActionEvent e) {
  170.                     _MenuBarEvent.setEventName(EventName3);
  171.                     // _MenuBarEvent.getName();
  172.                 }
  173.             });
  174.             _jMenu[3].add(_jMenuItem3[j]);
  175.             if (j == 0) {
  176.                 _jMenu[3].addSeparator();
  177.             }
  178.         }
  179.         for (int j = 0; j < _jMenuItem4.length; j++) {
  180.             _jMenuItem4[j].setFont(_MenuItemFont);
  181.             final String EventName4 = _jMenuItem4Name[j];
  182.             _jMenuItem4[j].addActionListener(_MenuBarEvent);
  183.             _jMenuItem4[j].addActionListener(new ActionListener() {
  184.                 public void actionPerformed(ActionEvent e) {
  185.                     _MenuBarEvent.setEventName(EventName4);
  186.                     // _MenuBarEvent.getName();
  187.                 }
  188.             });
  189.             _jMenu[4].add(_jMenuItem4[j]);
  190.         }
  191.   }
  192.     private void BuildToolBar(){
  193.       JToolBar toolbar = new JToolBar();
  194.       //String ImageName[] = {"借出管理.gif","移动管理.gif","维修管理.gif","折旧管理.gif","报表管理.gif","增加.gif","删除.gif","修改.gif","打印.gif","查询.gif","刷新.gif","退出.gif"};
  195.       String ImageName[] = {"药品录入.gif","供应商录入.gif","药品采购.gif","药品销售.GIF","库存盘点.GIF",
  196.                             "销售退货.GIF","客户回款.GIF","基本查询.GIF","入库明细.GIF","销售明细.GIF","用户管理.GIF","系统退出.GIF"};
  197.        String TipString[] = {"药品录入","供应商录入","药品采购","药品销售","库存盘点",
  198.                             "销售退货","客户回款","基本查询","入库明细","销售明细","用户管理","系统退出"};
  199.        String ComandString[] = {"JF_view_medicine","JF_view_gys","JF_view_buy", "JF_view_sell","JF_view_stock",
  200.                                "JF_view_xstk","JF_view_hkgl","JF_view_query_jbqk", "JF_view_query_rkqk",
  201.                                "JF_view_query_kcmx_ck","sys_user_modify","JB_EXIT"};
  202.       for(int i = 0 ; i < ComandString.length; i++){
  203.           JButton jb = new JButton();
  204.          // ImageIcon image = new ImageIcon(JF_main.class.getResource(ImageName[i]));
  205.           ImageIcon image = new ImageIcon(".\images\" + ImageName[i]);
  206.           jb.setIcon(image);
  207.           jb.setToolTipText(TipString[i]);
  208.           jb.setActionCommand(ComandString[i]);
  209.           jb.addActionListener(_MenuBarEvent);
  210.           jToolBarMain.add(jb);
  211.       }
  212.   }
  213.   private JMenuBar buildmenu(){
  214.     JMenuBar jMenuBar = new JMenuBar();
  215.     Font _menuFont = new Font("宋体", 0, 12);
  216.     JMenu jMenu = new JMenu("参数设置") ;
  217.     jMenuBar.add(jMenu);
  218.     return jMenuBar;
  219.   }
  220. }