Example usage for javax.swing JMenuBar add

List of usage examples for javax.swing JMenuBar add

Introduction

In this page you can find the example usage for javax.swing JMenuBar add.

Prototype

public JMenu add(JMenu c) 

Source Link

Document

Appends the specified menu to the end of the menu bar.

Usage

From source file:es.darkhogg.hazelnutt.EditorFrame.java

private void initializeGui() {
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    setBounds(100, 100, 640, 480);/*w  w  w .  j  a v a2  s  .  com*/

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent arg0) {
            actionExit();
        }
    });

    fileChooser = new JFileChooser();
    //fileChooser.setFileFilter( hlfFileFilter );

    hlfFileChooser = new JFileChooser();
    hlfFileChooser.setFileFilter(hlfFileFilter);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic('F');
    menuBar.add(mnFile);

    menuLoadRom = new JMenuItem("Load ROM...");
    menuLoadRom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
    menuLoadRom.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionOpenRom(null);
        }
    });
    menuLoadRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_open.png")));
    menuLoadRom.setMnemonic('O');
    mnFile.add(menuLoadRom);

    menuSaveRom = new JMenuItem("Save ROM");
    menuSaveRom.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionSaveRom();
        }
    });
    menuSaveRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save.png")));
    menuSaveRom.setMnemonic('S');
    menuSaveRom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
    mnFile.add(menuSaveRom);

    menuSaveRomAs = new JMenuItem("Save ROM As...");
    menuSaveRomAs.setMnemonic('a');
    menuSaveRomAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK));
    menuSaveRomAs.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionSaveRomAs();
        }
    });
    menuSaveRomAs
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save_as.png")));
    mnFile.add(menuSaveRomAs);

    mnFile.addSeparator();

    menuLoadLevel = new JMenuItem("Load Level...");
    menuLoadLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
    menuLoadLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionLoadLevel();
        }
    });
    menuLoadLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_load_level.png")));
    menuLoadLevel.setMnemonic('L');
    mnFile.add(menuLoadLevel);

    menuReloadLevel = new JMenuItem("Reload Level");
    menuReloadLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0));
    menuReloadLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionReloadLevel();
        }
    });
    menuReloadLevel.setMnemonic('R');
    menuReloadLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_reload_level.png")));
    mnFile.add(menuReloadLevel);

    menuSaveLevel = new JMenuItem("Save Level");
    menuSaveLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0));
    menuSaveLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionSaveLevel();
        }
    });
    menuSaveLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save_level.png")));
    menuSaveLevel.setMnemonic('v');

    mnFile.add(menuSaveLevel);

    //*
    mnFile.addSeparator();

    menuImportLevel = new JMenuItem("Import Level...");
    menuImportLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
    menuImportLevel.setMnemonic('i');
    menuImportLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionImportLevel();
        }
    });
    menuImportLevel
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_import.png")));
    mnFile.add(menuImportLevel);

    menuExportLevel = new JMenuItem("Export Level...");
    menuExportLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0));
    menuExportLevel.setMnemonic('e');
    menuExportLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionExportLevel();
        }
    });
    menuExportLevel
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_export.png")));
    mnFile.add(menuExportLevel);
    //*/

    mnFile.addSeparator();

    menuExit = new JMenuItem("Exit");
    menuExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
    menuExit.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_exit.png")));
    menuExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            actionExit();
        }
    });

    menuRecentFiles = new JMenu("Recent Files...");
    mnFile.add(menuRecentFiles);

    mnFile.addSeparator();
    menuExit.setMnemonic('X');
    mnFile.add(menuExit);

    JMenu mnEdit = new JMenu("Edit");
    mnEdit.setMnemonic('E');
    menuBar.add(mnEdit);

    menuViewSpawn = new JCheckBoxMenuItem("View Spawn Point");
    menuViewSpawn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, 0));
    menuViewSpawn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(false);
        }
    });

    menuClearLevel = new JMenuItem("Clear Level");
    menuClearLevel.setMnemonic('c');
    menuClearLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    menuClearLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionClearLevel();
        }
    });
    menuClearLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_clear_level.png")));
    mnEdit.add(menuClearLevel);

    mnEdit.addSeparator();

    menuViewSpawn
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_spawn.png")));
    menuViewSpawn.setMnemonic('S');
    menuViewSpawn.setSelected(true);
    mnEdit.add(menuViewSpawn);

    menuViewItems = new JCheckBoxMenuItem("View Items");
    menuViewItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, 0));
    menuViewItems.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(false);
        }
    });
    menuViewItems.setSelected(true);
    menuViewItems
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_items.png")));
    menuViewItems.setMnemonic('I');
    mnEdit.add(menuViewItems);

    menuViewDoorItems = new JCheckBoxMenuItem("View Door Items");
    menuViewDoorItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, 0));
    menuViewDoorItems.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(false);
        }
    });
    menuViewDoorItems.setSelected(true);
    menuViewDoorItems.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_door_items.png")));
    menuViewDoorItems.setMnemonic('D');
    mnEdit.add(menuViewDoorItems);

    menuViewEnemies = new JCheckBoxMenuItem("View Enemies");
    menuViewEnemies.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, 0));
    menuViewEnemies.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(false);
        }
    });
    menuViewEnemies.setSelected(true);
    menuViewEnemies
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_enemies.png")));
    menuViewEnemies.setMnemonic('E');
    mnEdit.add(menuViewEnemies);

    menuViewTypes = new JCheckBoxMenuItem("View Combo Types");
    menuViewTypes.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5, 0));
    menuViewTypes.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(false);
        }
    });
    menuViewTypes.setSelected(true);
    menuViewTypes.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_combo_infos.png")));
    menuViewTypes.setMnemonic('C');
    mnEdit.add(menuViewTypes);

    mnEdit.addSeparator();

    scaleMenuItem = new JCheckBoxMenuItem("Scale Level Display");
    scaleMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_6, 0));
    scaleMenuItem.setMnemonic('l');
    scaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionScale(false);
        }
    });
    scaleMenuItem.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_x2.png")));
    mnEdit.add(scaleMenuItem);

    gridMenuItem = new JCheckBoxMenuItem("Display grid");
    gridMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_7, 0));
    gridMenuItem.setMnemonic('G');
    gridMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionGrid(false);
        }
    });
    gridMenuItem.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_grid.png")));
    mnEdit.add(gridMenuItem);

    //mnEdit.addSeparator();

    mntmPreferences = new JMenuItem("Preferences...");
    mntmPreferences.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionPreferences();
        }
    });
    mntmPreferences.setMnemonic('P');
    mntmPreferences.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_preferences.png")));
    //mnEdit.add(mntmPreferences);

    mnHelp = new JMenu("Help");
    mnHelp.setMnemonic('H');
    menuBar.add(mnHelp);

    mntmCheckUpdates = new JMenuItem("Check for Updates...");
    mntmCheckUpdates.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK));
    mntmCheckUpdates.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionCheckUpdates();
        }
    });
    mntmCheckUpdates.setMnemonic('c');
    mntmCheckUpdates
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_update.png")));
    mnHelp.add(mntmCheckUpdates);

    mntmAbout = new JMenuItem("Readme...");
    mntmAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
    mntmAbout.setMnemonic('r');
    mntmAbout.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/about.png")));
    mntmAbout.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionAbout();
        }
    });
    mnHelp.addSeparator();
    mnHelp.add(mntmAbout);

    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);

    JToolBar toolBar = new JToolBar();
    toolBar.setRollover(true);
    toolBar.setFloatable(false);
    contentPane.add(toolBar, BorderLayout.NORTH);

    barLoadRom = new JButton("");
    barLoadRom.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionOpenRom(null);
        }
    });
    barLoadRom.setToolTipText("Open");
    barLoadRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_open.png")));
    toolBar.add(barLoadRom);

    barSaveRom = new JButton("");
    barSaveRom.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionSaveRom();
        }
    });
    barSaveRom.setToolTipText("Save");
    barSaveRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save.png")));
    toolBar.add(barSaveRom);

    toolBar.addSeparator();

    barImportLevel = new JButton("");
    barImportLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionImportLevel();
        }
    });
    barImportLevel.setToolTipText("Import Level");
    barImportLevel
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_import.png")));
    toolBar.add(barImportLevel);

    barExportLevel = new JButton("");
    barExportLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionExportLevel();
        }
    });
    barExportLevel.setToolTipText("Export Level");
    barExportLevel
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_export.png")));
    toolBar.add(barExportLevel);

    toolBar.addSeparator();

    barLoadLevel = new JButton("");
    barLoadLevel.setToolTipText("Load Level");
    barLoadLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionLoadLevel();
        }
    });
    barLoadLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_load_level.png")));
    toolBar.add(barLoadLevel);

    barReloadLevel = new JButton("");
    barReloadLevel.setToolTipText("Reload Current Level");
    barReloadLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionReloadLevel();
        }
    });
    barReloadLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_reload_level.png")));
    toolBar.add(barReloadLevel);

    barSaveLevel = new JButton("");
    barSaveLevel.setToolTipText("Save Level");
    barSaveLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionSaveLevel();
        }
    });
    barSaveLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save_level.png")));
    toolBar.add(barSaveLevel);

    toolBar.addSeparator();

    barViewItems = new JToggleButton("");
    barViewItems.setToolTipText("Toggle View Items");
    barViewItems.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(true);
        }
    });

    barViewSpawn = new JToggleButton("");
    barViewSpawn.setToolTipText("Toggle View Spawn");
    barViewSpawn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(true);
        }
    });

    barClearLevel = new JButton("");
    barClearLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionClearLevel();
        }
    });
    barClearLevel.setToolTipText("Clear Level");
    barClearLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_clear_level.png")));
    toolBar.add(barClearLevel);

    toolBar.addSeparator();

    barViewSpawn.setSelected(true);
    barViewSpawn.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_spawn.png")));
    toolBar.add(barViewSpawn);
    barViewItems.setSelected(true);
    barViewItems.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_items.png")));
    toolBar.add(barViewItems);

    barViewDoorItems = new JToggleButton("");
    barViewDoorItems.setToolTipText("Toggle View Door Items");
    barViewDoorItems.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(true);
        }
    });
    barViewDoorItems.setSelected(true);
    barViewDoorItems.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_door_items.png")));
    toolBar.add(barViewDoorItems);

    barViewEnemies = new JToggleButton("");
    barViewEnemies.setToolTipText("toggle View Enemies");
    barViewEnemies.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(true);
        }
    });
    barViewEnemies.setSelected(true);
    barViewEnemies
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_enemies.png")));
    toolBar.add(barViewEnemies);

    barViewTypes = new JToggleButton("");
    barViewTypes.setToolTipText("Toggle view Combo Help");
    barViewTypes.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(true);
        }
    });
    barViewTypes.setSelected(true);
    barViewTypes.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_combo_infos.png")));
    toolBar.add(barViewTypes);

    barViewSpawn.setSelected(config.getBoolean("Hazelnutt.gui.viewSpawn", true));
    barViewItems.setSelected(config.getBoolean("Hazelnutt.gui.viewItems", true));
    barViewDoorItems.setSelected(config.getBoolean("Hazelnutt.gui.viewDoorItems", true));
    barViewEnemies.setSelected(config.getBoolean("Hazelnutt.gui.viewEnemies", true));
    barViewTypes.setSelected(config.getBoolean("Hazelnutt.gui.viewHelp", true));

    panel = new JPanel();
    contentPane.add(panel, BorderLayout.EAST);
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    selectorPanel = new SelectorPanel();
    selectorPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"),
            "Combo & Entity Selector", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213)));
    panel.add(selectorPanel);

    propertiesPanel = new PropertiesPanel(null);
    propertiesPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Level Properties",
            TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213)));
    panel.add(propertiesPanel);

    toolBar.addSeparator();

    scaleButton = new JToggleButton("");
    scaleButton.setToolTipText("Toggle Scale Display");
    scaleButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionScale(true);
        }
    });
    scaleButton.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_x2.png")));
    toolBar.add(scaleButton);

    scaleButton.setSelected(config.getBoolean("Hazelnutt.gui.scaled", false));

    gridButton = new JToggleButton("");
    gridButton.setToolTipText("Display Grid");
    gridButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionGrid(true);
        }
    });
    gridButton.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_grid.png")));
    toolBar.add(gridButton);

    gridButton.setSelected(config.getBoolean("Hazelnutt.gui.grid", false));

    Component horizontalGlue = Box.createHorizontalGlue();
    toolBar.add(horizontalGlue);

    Component verticalGlue = Box.createVerticalGlue();
    panel.add(verticalGlue);

    levelWrapper = new JPanel();
    levelWrapper.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Level",
            TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213)));
    contentPane.add(levelWrapper, BorderLayout.CENTER);
    levelWrapper.setLayout(new BorderLayout(0, 0));

    scrollPane = new JScrollPane();
    scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
    levelWrapper.add(scrollPane);

    levelDisplay = new LevelDisplay();
    levelDisplay.addEditListener(new EditListener() {
        @Override
        public void leftPressed(int x, int y) {
            SelectionType st = selectorPanel.getSelectionType();
            Object so = selectorPanel.getSelectedObject();

            if (st == SelectionType.COMBO) {
                paintComboAt(x, y, ((Byte) so).byteValue());
            } else if (st == SelectionType.SPAWN) {
                selectedLevel.getRomLevel().setSpawn(new IntVector(x, y));

                levelHasChanged = true;
            } else if (st == SelectionType.ITEM) {
                Item ent = new Item((ItemType) so, x, y);
                EntityCollection<Item> ents = selectedLevel.getRomLevel().getItems();
                for (Iterator<Item> it = ents.iterator(); it.hasNext();) {
                    Item item = it.next();
                    if (item.getX() == x && item.getY() == y) {
                        it.remove();
                    }
                }
                if (ents.size() <= ents.maxSize()) {
                    ents.add(ent);
                    levelHasChanged = true;
                }
            } else if (st == SelectionType.DOOR_ITEM) {
                Item ent = new Item((ItemType) so, x, y);
                EntityCollection<Item> ents = selectedLevel.getRomLevel().getDoorItems();
                for (Iterator<Item> it = ents.iterator(); it.hasNext();) {
                    Item item = it.next();
                    if (item.getX() == x && item.getY() == y) {
                        it.remove();
                    }
                }
                if (ents.size() <= ents.maxSize()) {
                    ents.add(ent);
                    levelHasChanged = true;
                }
            } else if (st == SelectionType.ENEMY) {
                Enemy ent = new Enemy((EnemyType) so, x, y);
                EntityCollection<Enemy> ents = selectedLevel.getRomLevel().getEnemies();
                for (Iterator<Enemy> it = ents.iterator(); it.hasNext();) {
                    Enemy enem = it.next();
                    if (enem.getX() == x && enem.getY() == y) {
                        it.remove();
                    }
                }
                if (ents.size() <= ents.maxSize()) {
                    ents.add(ent);
                    levelHasChanged = true;
                }
            }

            updateTitle();
            levelDisplay.repaint();
            levelHasChanged = true;
        }

        @Override
        public void centerPressed(int x, int y) {
            selectorPanel.forceComboSelection(selectedLevel.getRomLevel().getData()[x][y]);
        }

        @Override
        public void rightPressed(int x, int y) {
            deleteVisibleEntitiesAt(x, y);
        }

        @Override
        public void leftDragged(int x, int y) {
            if (selectorPanel.getSelectionType() == SelectionType.COMBO) {
                paintComboAt(x, y, ((Byte) selectorPanel.getSelectedObject()).byteValue());
            }
        }

        @Override
        public void centerDragged(int x, int y) {
            // Nothing to de here
        }

        @Override
        public void rightDragged(int x, int y) {
            deleteVisibleEntitiesAt(x, y);
        }

        // Utility methods
        /*private void selectComboAt ( int x, int y ) {
                   
        }/**/
        private void paintComboAt(int x, int y, byte value) {
            selectedLevel.getRomLevel().getData()[x][y] = value;
            levelHasChanged = true;

            updateTitle();
            levelDisplay.repaint();
        }

        private void deleteVisibleEntitiesAt(int x, int y) {
            Collection<Item> items = selectedLevel.getRomLevel().getItems();
            Collection<Item> doorItems = selectedLevel.getRomLevel().getDoorItems();
            Collection<Enemy> enemies = selectedLevel.getRomLevel().getEnemies();

            if (barViewItems.isSelected()) {
                for (Iterator<Item> it = items.iterator(); it.hasNext();) {
                    Item item = it.next();
                    if (item.getX() == x && item.getY() == y) {
                        it.remove();
                        levelHasChanged = true;
                    }
                }
            }

            if (barViewDoorItems.isSelected()) {
                for (Iterator<Item> it = doorItems.iterator(); it.hasNext();) {
                    Item doorItem = it.next();
                    if (doorItem.getX() == x && doorItem.getY() == y) {
                        it.remove();
                        levelHasChanged = true;
                    }
                }
            }

            if (barViewEnemies.isSelected()) {
                for (Iterator<Enemy> it = enemies.iterator(); it.hasNext();) {
                    Enemy enem = it.next();
                    if (enem.getX() == x && enem.getY() == y) {
                        it.remove();
                        levelHasChanged = true;
                    }
                }
            }

            updateTitle();
            levelDisplay.repaint();
        }
    });
    scrollPane.setViewportView(levelDisplay);

    updateTitle();
    actionToggle(true);
    actionScale(true);
    actionGrid(true);
    setIconImage(Toolkit.getDefaultToolkit()
            .getImage(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/witch_hazel_big.png")));
    setRomFeaturesEnabled(false);
    setLevelFeaturesEnabled(false);

    if (config.getBoolean("Hazelnutt.gui.maximum", false)) {
        setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
    } else {
        int x = config.getInt("Hazelnutt.gui.location.x", Integer.MIN_VALUE);
        int y = config.getInt("Hazelnutt.gui.location.y", Integer.MIN_VALUE);
        int w = config.getInt("Hazelnutt.gui.size.width", Integer.MIN_VALUE);
        int h = config.getInt("Hazelnutt.gui.size.height", Integer.MIN_VALUE);

        if (x == Integer.MIN_VALUE || x == Integer.MIN_VALUE || w == Integer.MIN_VALUE
                || h == Integer.MIN_VALUE) {
            setLocationRelativeTo(null);
        } else {
            setLocation(x, y);
            setSize(w, h);
        }
    }

    propertiesPanel.addApplyListener(new PropertiesPanel.ApplyListener() {
        @Override
        public void apply() {
            levelHasChanged = true;
            updateTitle();
            updateDisplay();
        }
    });

    if (config.containsKey("Hazelnutt.gui.lastDirectory")) {
        File lastDir = new File(config.getString("Hazelnutt.gui.lastDirectory"));
        if (lastDir.exists() && lastDir.isDirectory()) {
            //logger.debug( "Resetting the last directory: '" + lastDir + "'" );
            fileChooser.setCurrentDirectory(lastDir);
        }
    }

    // Configure the PgUp and PgDn shortcuts
    InputMap im = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "PgUp");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "PgDn");
    ActionMap am = contentPane.getActionMap();
    am.put("PgUp", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            actionLevelUp();
        }
    });
    am.put("PgDn", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            actionLevelDown();
        }
    });

    // Get the recent files
    recentFiles = new LinkedList<String>(Arrays.asList(config.getStringArray("Hazelnutt.gui.recentFiles")));
    updateRecentFiles();

}

From source file:br.com.jinsync.view.FrmJInSync.java

/**
 * Initialize the contents of the frame.
 *///from w w  w  .j  ava 2  s. c om
private void initialize() {

    Language.loadParameters();

    setBounds(100, 100, 1136, 665);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 0, 0 };
    gridBagLayout.rowHeights = new int[] { 600, 53, 0, 0 };
    gridBagLayout.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gridBagLayout.rowWeights = new double[] { 1.0, 0.0, 0.0, Double.MIN_VALUE };
    getContentPane().setLayout(gridBagLayout);

    grpFontes = new JTabbedPane(SwingConstants.TOP);
    GridBagConstraints gbc_grpFontes = new GridBagConstraints();
    gbc_grpFontes.insets = new Insets(0, 0, 5, 0);
    gbc_grpFontes.fill = GridBagConstraints.BOTH;
    gbc_grpFontes.gridx = 0;
    gbc_grpFontes.gridy = 0;
    getContentPane().add(grpFontes, gbc_grpFontes);

    tabCopybook = new JPanel();
    tabCopybook.setBackground(Color.WHITE);
    grpFontes.addTab(Language.tabCopy, null, tabCopybook, null);

    GridBagLayout gbl_tabCopybook = new GridBagLayout();
    gbl_tabCopybook.columnWidths = new int[] { 10, 1, 0, 349, 0, 0, 62, 28, 71, 0, 0, 0 };
    gbl_tabCopybook.rowHeights = new int[] { 1, 0, 0, 0 };
    gbl_tabCopybook.columnWeights = new double[] { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            Double.MIN_VALUE };
    gbl_tabCopybook.rowWeights = new double[] { 0.0, 0.0, 1.0, Double.MIN_VALUE };
    tabCopybook.setLayout(gbl_tabCopybook);

    JLabel lblCopybook = new JLabel(Language.txtFilePds);
    GridBagConstraints gbc_lblCopybook = new GridBagConstraints();
    gbc_lblCopybook.anchor = GridBagConstraints.EAST;
    gbc_lblCopybook.insets = new Insets(0, 0, 5, 5);
    gbc_lblCopybook.gridx = 1;
    gbc_lblCopybook.gridy = 1;
    tabCopybook.add(lblCopybook, gbc_lblCopybook);

    txtPath = new JTextField();
    GridBagConstraints gbc_txtPath = new GridBagConstraints();
    gbc_txtPath.gridwidth = 4;
    gbc_txtPath.insets = new Insets(0, 0, 5, 5);
    gbc_txtPath.fill = GridBagConstraints.HORIZONTAL;
    gbc_txtPath.gridx = 2;
    gbc_txtPath.gridy = 1;
    tabCopybook.add(txtPath, gbc_txtPath);
    txtPath.setColumns(10);

    JButton btnDiretorio = new JButton("");
    btnDiretorio.setIcon(new ImageIcon(FrmJInSync.class.getResource("/resources/folder.png")));
    btnDiretorio.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            openDirectory();
        }
    });
    GridBagConstraints gbc_btnDiretorio = new GridBagConstraints();
    gbc_btnDiretorio.insets = new Insets(0, 0, 5, 5);
    gbc_btnDiretorio.gridx = 6;
    gbc_btnDiretorio.gridy = 1;
    tabCopybook.add(btnDiretorio, gbc_btnDiretorio);

    btnClearCopy = new JButton("");
    btnClearCopy.setEnabled(false);
    btnClearCopy.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            tableCopy = new JTable();
            scrCopy.setViewportView(tableCopy);
            tableString = new JTable();
            scrTableString.setViewportView(tableString);

            btnExcelString.setEnabled(false);
            btnClearString.setEnabled(false);
            textAreaString.setText("");

            console.removeAllElements();
            btnExcel.setEnabled(false);
            btnClearCopy.setEnabled(false);
            grpFontes.setEnabledAt(1, false);

            tableFile = new JTable();
            scrFile.setViewportView(tableFile);
            btnExcelFile.setEnabled(false);
            btnClearFile.setEnabled(false);
            grpFontes.setEnabledAt(2, false);

        }
    });
    btnClearCopy.setIcon(new ImageIcon(FrmJInSync.class.getResource("/resources/cancel.png")));
    GridBagConstraints gbc_btnLimpar = new GridBagConstraints();
    gbc_btnLimpar.fill = GridBagConstraints.BOTH;
    gbc_btnLimpar.insets = new Insets(0, 0, 5, 5);
    gbc_btnLimpar.gridx = 9;
    gbc_btnLimpar.gridy = 1;
    tabCopybook.add(btnClearCopy, gbc_btnLimpar);

    JButton btnProcessarBook = new JButton("");
    btnProcessarBook.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            loadData();
            btnClearCopy.setEnabled(true);
            grpFontes.setEnabledAt(1, true);
            grpFontes.setEnabledAt(2, true);
        }
    });
    btnProcessarBook.setIcon(new ImageIcon(FrmJInSync.class.getResource("/resources/engine.png")));
    GridBagConstraints gbc_btnProcessarBook = new GridBagConstraints();
    gbc_btnProcessarBook.fill = GridBagConstraints.VERTICAL;
    gbc_btnProcessarBook.insets = new Insets(0, 0, 5, 5);
    gbc_btnProcessarBook.gridx = 7;
    gbc_btnProcessarBook.gridy = 1;
    tabCopybook.add(btnProcessarBook, gbc_btnProcessarBook);

    btnExcel = new JButton("");
    btnExcel.setEnabled(false);
    btnExcel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            expExcelBook();
            // exportarExcelBook(tableCopy, txtPath.getText(),
            // "Horizontal");
        }
    });
    btnExcel.setIcon(new ImageIcon(FrmJInSync.class.getResource("/resources/excel.png")));
    GridBagConstraints gbc_btnExcel = new GridBagConstraints();
    gbc_btnExcel.insets = new Insets(0, 0, 5, 5);
    gbc_btnExcel.gridx = 8;
    gbc_btnExcel.gridy = 1;
    tabCopybook.add(btnExcel, gbc_btnExcel);

    // JScrollPane scrCopy = new JScrollPane();
    gbc_scrCopy = new GridBagConstraints();
    gbc_scrCopy.gridwidth = 9;
    gbc_scrCopy.insets = new Insets(0, 0, 0, 5);
    gbc_scrCopy.fill = GridBagConstraints.BOTH;
    gbc_scrCopy.gridx = 1;
    gbc_scrCopy.gridy = 2;
    // tabCopybook.add(scrCopy, gbc_scrCopy);

    panelConsole = new Panel();
    GridBagConstraints gbc_panelConsole = new GridBagConstraints();
    gbc_panelConsole.insets = new Insets(0, 0, 5, 0);
    gbc_panelConsole.fill = GridBagConstraints.BOTH;
    gbc_panelConsole.gridx = 0;
    gbc_panelConsole.gridy = 1;
    getContentPane().add(panelConsole, gbc_panelConsole);
    panelConsole.setLayout(new BorderLayout(0, 0));

    listTerminal = new JList<String>();
    listTerminal.setFont(new Font("Courier New", Font.PLAIN, 11));
    listTerminal.setModel(console);

    scrConsole = new JScrollPane(listTerminal);
    panelConsole.add(scrConsole);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnNewMenu = new JMenu(Language.menuParam);
    menuBar.add(mnNewMenu);

    JMenuItem mnItemUsuario = new JMenuItem(Language.menuParamUser);
    mnItemUsuario.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FrmUser frmUsuar = new FrmUser();
            frmUsuar.setLocationRelativeTo(null);
            frmUsuar.setVisible(true);
            setUser();
        }
    });
    mnNewMenu.add(mnItemUsuario);

    JMenuItem mnItemFtp = new JMenuItem(Language.menuParamFtp);
    mnItemFtp.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FrmFtp frmFtp = new FrmFtp();
            frmFtp.setLocationRelativeTo(null);
            frmFtp.setVisible(true);
            setFtp();
        }
    });

    mnNewMenu.add(mnItemFtp);

    JMenu mnAjuda = new JMenu(Language.menuHelp);
    menuBar.add(mnAjuda);

    JMenuItem mntmNewMenuItem = new JMenuItem(Language.menuHelpAbout);
    mntmNewMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            FrmAbout frmSobre = new FrmAbout();
            frmSobre.setLocationRelativeTo(null);
            frmSobre.setVisible(true);
        }
    });
    mnAjuda.add(mntmNewMenuItem);

    tabCopybook.setFont(new Font("Arial", Font.PLAIN, 12));
    tabCopybook.add(scrCopy, gbc_scrCopy);

    tabString = new JPanel();
    tabString.setFont(new Font("Arial", Font.PLAIN, 12));
    tabString.setBackground(Color.WHITE);
    grpFontes.addTab(Language.tabString, null, tabString, null);
    grpFontes.setEnabledAt(1, false);
    GridBagLayout gbl_tabString = new GridBagLayout();
    gbl_tabString.columnWidths = new int[] { 10, 1, 346, 349, 0, 0, 62, 28, 71, 0, 0, 0 };
    gbl_tabString.rowHeights = new int[] { 1, 0, 0, 17, 22, 0, 259, 0 };
    gbl_tabString.columnWeights = new double[] { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            Double.MIN_VALUE };
    gbl_tabString.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE };
    tabString.setLayout(gbl_tabString);

    JLabel lblString = new JLabel("String:");
    GridBagConstraints gbc_lblString = new GridBagConstraints();
    gbc_lblString.anchor = GridBagConstraints.WEST;
    gbc_lblString.insets = new Insets(0, 0, 5, 5);
    gbc_lblString.gridx = 1;
    gbc_lblString.gridy = 1;
    tabString.add(lblString, gbc_lblString);

    textAreaString = new JTextArea();

    JScrollPane scrStringData = new JScrollPane(textAreaString);
    GridBagConstraints gbc_scrString = new GridBagConstraints();
    gbc_scrString.gridheight = 3;
    gbc_scrString.gridwidth = 8;
    gbc_scrString.insets = new Insets(0, 0, 5, 5);
    gbc_scrString.fill = GridBagConstraints.BOTH;
    gbc_scrString.gridx = 1;
    gbc_scrString.gridy = 2;
    tabString.add(scrStringData, gbc_scrString);

    btnClearString = new JButton("");
    btnClearString.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            scrTableString.setViewportView(tableString);
            btnExcelString.setEnabled(false);
            btnClearString.setEnabled(false);
            textAreaString.setText("");
            tableString = new JTable();
            scrTableString.setViewportView(tableString);
        }
    });

    btnExcelString = new JButton("");
    btnExcelString.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            expExcelString();
        }
    });

    JButton btnProcessarArq = new JButton("");
    btnProcessarArq.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            processString();
        }
    });
    btnProcessarArq.setIcon(new ImageIcon(FrmJInSync.class.getResource("/resources/engine.png")));
    GridBagConstraints gbc_btnProcessarArq = new GridBagConstraints();
    gbc_btnProcessarArq.fill = GridBagConstraints.VERTICAL;
    gbc_btnProcessarArq.insets = new Insets(0, 0, 5, 5);
    gbc_btnProcessarArq.gridx = 9;
    gbc_btnProcessarArq.gridy = 2;
    tabString.add(btnProcessarArq, gbc_btnProcessarArq);
    btnExcelString.setIcon(new ImageIcon(FrmJInSync.class.getResource("/resources/excel.png")));
    btnExcelString.setEnabled(false);
    GridBagConstraints gbc_btnExcelString = new GridBagConstraints();
    gbc_btnExcelString.fill = GridBagConstraints.VERTICAL;
    gbc_btnExcelString.insets = new Insets(0, 0, 5, 5);
    gbc_btnExcelString.gridx = 9;
    gbc_btnExcelString.gridy = 3;
    tabString.add(btnExcelString, gbc_btnExcelString);
    btnClearString.setIcon(new ImageIcon(FrmJInSync.class.getResource("/resources/cancel.png")));
    btnClearString.setEnabled(false);
    GridBagConstraints gbc_btnClearString = new GridBagConstraints();
    gbc_btnClearString.fill = GridBagConstraints.VERTICAL;
    gbc_btnClearString.insets = new Insets(0, 0, 5, 5);
    gbc_btnClearString.gridx = 9;
    gbc_btnClearString.gridy = 4;
    tabString.add(btnClearString, gbc_btnClearString);

    JLabel lblSaida = new JLabel(Language.txtOutput);
    GridBagConstraints gbc_lblSaida = new GridBagConstraints();
    gbc_lblSaida.insets = new Insets(0, 0, 5, 5);
    gbc_lblSaida.gridx = 1;
    gbc_lblSaida.gridy = 5;
    tabString.add(lblSaida, gbc_lblSaida);

    GridBagConstraints gbc_scrArquivo = new GridBagConstraints();
    gbc_scrArquivo.fill = GridBagConstraints.BOTH;
    gbc_scrArquivo.gridwidth = 9;
    gbc_scrArquivo.insets = new Insets(0, 0, 0, 5);
    gbc_scrArquivo.gridx = 1;
    gbc_scrArquivo.gridy = 6;
    tabString.add(scrTableString, gbc_scrArquivo);

    tabFile = new JPanel();
    tabFile.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub
            if (isProcessStarted) {
                int key = e.getKeyCode();
                if (key == KeyEvent.VK_ESCAPE) {
                    int opc = JOptionPane.showConfirmDialog(null, Language.msgCancelProcess, Language.msgInf,
                            JOptionPane.OK_CANCEL_OPTION);
                    if (opc == JOptionPane.OK_OPTION) {
                        escProcessFile();
                    }
                }
            }

        }

        @Override
        public void keyReleased(KeyEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void keyTyped(KeyEvent arg0) {
            // TODO Auto-generated method stub

        }

    });

    tabFile.setFont(new Font("Arial", Font.PLAIN, 12));
    tabFile.setBackground(Color.WHITE);
    grpFontes.addTab(Language.tabFile, null, tabFile, null);
    grpFontes.setEnabledAt(2, false);
    GridBagLayout gbl_tabFile = new GridBagLayout();
    gbl_tabFile.columnWidths = new int[] { 10, 1, 49, 459, 0, 0, 62, 28, 0, 71, 0, 0, 0, 0 };
    gbl_tabFile.rowHeights = new int[] { 1, 0, 0, 17, 22, 0, 259, 0, 0 };
    gbl_tabFile.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            Double.MIN_VALUE };
    gbl_tabFile.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE };
    tabFile.setLayout(gbl_tabFile);

    JLabel lblFile = new JLabel(Language.txtFilePds);
    GridBagConstraints gbc_lblFile = new GridBagConstraints();
    gbc_lblFile.anchor = GridBagConstraints.EAST;
    gbc_lblFile.insets = new Insets(0, 0, 5, 5);
    gbc_lblFile.gridx = 1;
    gbc_lblFile.gridy = 1;
    tabFile.add(lblFile, gbc_lblFile);

    txtFile = new JTextField();
    txtFile.setColumns(10);
    GridBagConstraints gbc_txtFile = new GridBagConstraints();
    gbc_txtFile.gridwidth = 5;
    gbc_txtFile.insets = new Insets(0, 0, 5, 5);
    gbc_txtFile.fill = GridBagConstraints.HORIZONTAL;
    gbc_txtFile.gridx = 2;
    gbc_txtFile.gridy = 1;
    tabFile.add(txtFile, gbc_txtFile);

    btnClearFile = new JButton("");
    btnClearFile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {

            tableFile = new JTable();
            scrFile.setViewportView(tableFile);
            btnExcelFile.setEnabled(false);
            btnClearFile.setEnabled(false);
            progressBar.setStringPainted(true);
            progressBar.setValue(0);
            progressBar.setString("");

        }
    });

    btnExcelFile = new JButton("");
    btnExcelFile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            expExcelFile();
        }
    });

    btnProcFile = new JButton("");
    btnProcFile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            loadFile();
        }
    });

    btnDirFile = new JButton("");
    btnDirFile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            openDirFile();
        }
    });
    btnDirFile.setIcon(new ImageIcon(FrmJInSync.class.getResource("/resources/folder.png")));
    GridBagConstraints gbc_btnDirFile = new GridBagConstraints();
    gbc_btnDirFile.fill = GridBagConstraints.VERTICAL;
    gbc_btnDirFile.insets = new Insets(0, 0, 5, 5);
    gbc_btnDirFile.gridx = 7;
    gbc_btnDirFile.gridy = 1;
    tabFile.add(btnDirFile, gbc_btnDirFile);
    btnProcFile.setIcon(new ImageIcon(FrmJInSync.class.getResource("/resources/engine.png")));
    GridBagConstraints gbc_btnProcFile = new GridBagConstraints();
    gbc_btnProcFile.fill = GridBagConstraints.VERTICAL;
    gbc_btnProcFile.insets = new Insets(0, 0, 5, 5);
    gbc_btnProcFile.gridx = 8;
    gbc_btnProcFile.gridy = 1;
    tabFile.add(btnProcFile, gbc_btnProcFile);
    btnExcelFile.setIcon(new ImageIcon(FrmJInSync.class.getResource("/resources/excel.png")));
    btnExcelFile.setEnabled(false);
    GridBagConstraints gbc_btnExcelFile = new GridBagConstraints();
    gbc_btnExcelFile.insets = new Insets(0, 0, 5, 5);
    gbc_btnExcelFile.gridx = 9;
    gbc_btnExcelFile.gridy = 1;
    tabFile.add(btnExcelFile, gbc_btnExcelFile);
    btnClearFile.setIcon(new ImageIcon(FrmJInSync.class.getResource("/resources/cancel.png")));
    btnClearFile.setEnabled(false);
    GridBagConstraints gbc_btnLimparFile = new GridBagConstraints();
    gbc_btnLimparFile.fill = GridBagConstraints.VERTICAL;
    gbc_btnLimparFile.insets = new Insets(0, 0, 5, 5);
    gbc_btnLimparFile.gridx = 10;
    gbc_btnLimparFile.gridy = 1;
    tabFile.add(btnClearFile, gbc_btnLimparFile);

    JLabel lblTamanho = new JLabel(Language.txtFileLength);
    GridBagConstraints gbc_lblTamanho = new GridBagConstraints();
    gbc_lblTamanho.anchor = GridBagConstraints.WEST;
    gbc_lblTamanho.insets = new Insets(0, 0, 5, 5);
    gbc_lblTamanho.gridx = 1;
    gbc_lblTamanho.gridy = 2;
    tabFile.add(lblTamanho, gbc_lblTamanho);

    txtLength = new JTextField();
    GridBagConstraints gbc_txtTamanho = new GridBagConstraints();
    gbc_txtTamanho.fill = GridBagConstraints.HORIZONTAL;
    gbc_txtTamanho.insets = new Insets(0, 0, 5, 5);
    gbc_txtTamanho.gridx = 2;
    gbc_txtTamanho.gridy = 2;
    tabFile.add(txtLength, gbc_txtTamanho);
    txtLength.setColumns(10);

    JLabel label_1 = new JLabel(Language.txtOutput);
    GridBagConstraints gbc_label_1 = new GridBagConstraints();
    gbc_label_1.anchor = GridBagConstraints.WEST;
    gbc_label_1.insets = new Insets(0, 0, 5, 5);
    gbc_label_1.gridx = 1;
    gbc_label_1.gridy = 3;
    tabFile.add(label_1, gbc_label_1);

    GridBagConstraints gbc_scrFile = new GridBagConstraints();
    gbc_scrFile.gridheight = 3;
    gbc_scrFile.fill = GridBagConstraints.BOTH;
    gbc_scrFile.gridwidth = 10;
    gbc_scrFile.insets = new Insets(0, 0, 5, 5);
    gbc_scrFile.gridx = 1;
    gbc_scrFile.gridy = 4;
    tabFile.add(scrFile, gbc_scrFile);

    progressBar = new JProgressBar();
    GridBagConstraints gbc_progressBar = new GridBagConstraints();
    gbc_progressBar.fill = GridBagConstraints.HORIZONTAL;
    gbc_progressBar.gridwidth = 10;
    gbc_progressBar.insets = new Insets(0, 0, 0, 5);
    gbc_progressBar.gridx = 1;
    gbc_progressBar.gridy = 7;
    tabFile.add(progressBar, gbc_progressBar);

    JLabel lblNewLabel = new JLabel(Language.txtDeveloped + " Rodrigo Augusto Silva dos Santos - 2016");
    GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
    gbc_lblNewLabel.gridx = 0;
    gbc_lblNewLabel.gridy = 2;
    getContentPane().add(lblNewLabel, gbc_lblNewLabel);

    loadParameters();

}

From source file:chisquarecalculator.ChisqCal.java

public ChisqCal() {
    final JFrame jfrm = new JFrame("Chi Square Calculator");
    jfrm.setSize(400, 550);/* w  w  w  .  java  2 s  .  co m*/
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jfrm.setResizable(false);

    // panel 1
    JPanel pn1 = new JPanel();
    pn1.setOpaque(true);
    pn1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 2"));

    JLabel jlab1 = new JLabel("class 1");
    JLabel jlab2 = new JLabel("class 2");
    JLabel jlab3 = new JLabel("case");
    JLabel jlab4 = new JLabel("control");

    jtf1 = new JTextField();
    jtf2 = new JTextField();
    jtf3 = new JTextField();
    jtf4 = new JTextField();

    // pn1 layout all
    GridBagLayout CalLayout1 = new GridBagLayout();
    GridBagConstraints gbc1 = new GridBagConstraints();
    pn1.setLayout(CalLayout1);
    gbc1.weightx = 1.0; //default 0.0
    gbc1.weighty = 1.0; //default 0.0      
    gbc1.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc1.fill = GridBagConstraints.BOTH;

    gbc1.gridwidth = 1;

    gbc1.gridx = 1;
    gbc1.gridy = 0;
    CalLayout1.setConstraints(jlab1, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 0;
    CalLayout1.setConstraints(jlab2, gbc1);

    gbc1.gridx = 0;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jlab3, gbc1);

    gbc1.gridx = 1;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jtf1, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jtf2, gbc1);

    gbc1.gridx = 0;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jlab4, gbc1);

    gbc1.gridx = 1;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jtf3, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jtf4, gbc1);

    pn1.add(jlab1);
    pn1.add(jlab2);
    pn1.add(jlab3);
    pn1.add(jlab4);
    pn1.add(jtf1);
    pn1.add(jtf2);
    pn1.add(jtf3);
    pn1.add(jtf4);

    // panel 2
    JPanel pn2 = new JPanel();
    pn2.setOpaque(true);
    pn2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 3"));

    JLabel jlab5 = new JLabel("class 1");
    JLabel jlab6 = new JLabel("class 2");
    JLabel jlab7 = new JLabel("class 3");
    JLabel jlab8 = new JLabel("case");
    JLabel jlab9 = new JLabel("control");

    jtf5 = new JTextField();
    jtf6 = new JTextField();
    jtf7 = new JTextField();
    jtf8 = new JTextField();
    jtf9 = new JTextField();
    jtf10 = new JTextField();

    // pn2 layout all
    GridBagLayout CalLayout2 = new GridBagLayout();
    GridBagConstraints gbc2 = new GridBagConstraints();
    pn2.setLayout(CalLayout2);
    gbc2.weightx = 1.0; //default 0.0
    gbc2.weighty = 1.0; //default 0.0      
    gbc2.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc2.fill = GridBagConstraints.BOTH;

    gbc2.gridwidth = 1;

    gbc2.gridx = 1;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab5, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab6, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab7, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jlab8, gbc2);

    gbc2.gridx = 1;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf5, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf6, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf7, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jlab9, gbc2);

    gbc2.gridx = 1;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf8, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf9, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf10, gbc2);

    pn2.add(jlab5);
    pn2.add(jlab6);
    pn2.add(jlab7);
    pn2.add(jlab8);
    pn2.add(jlab9);
    pn2.add(jtf5);
    pn2.add(jtf6);
    pn2.add(jtf7);
    pn2.add(jtf8);
    pn2.add(jtf9);
    pn2.add(jtf10);

    // panel 3      
    JPanel pn3 = new JPanel();
    pn3.setOpaque(true);
    pn3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "statistic"));

    JLabel jlab10 = new JLabel("chi-square");
    JLabel jlab11 = new JLabel("degree of freedom");

    jtf11 = new JTextField();
    jtf12 = new JTextField();

    GridBagLayout CalLayout3 = new GridBagLayout();
    GridBagConstraints gbc3 = new GridBagConstraints();
    pn3.setLayout(CalLayout3);
    gbc3.weightx = 1.0; //default 0.0
    gbc3.weighty = 1.0; //default 0.0      
    gbc3.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc3.fill = GridBagConstraints.BOTH;

    gbc3.gridwidth = 1;

    gbc3.gridx = 0;
    gbc3.gridy = 0;
    CalLayout3.setConstraints(jlab10, gbc3);

    gbc3.gridwidth = 3;

    gbc3.gridx = 1;
    gbc3.gridy = 0;
    CalLayout3.setConstraints(jtf11, gbc3);

    gbc3.gridwidth = 2;

    gbc3.gridx = 0;
    gbc3.gridy = 1;
    CalLayout3.setConstraints(jlab11, gbc3);

    gbc3.gridx = 2;
    gbc3.gridy = 1;
    CalLayout3.setConstraints(jtf12, gbc3);

    pn3.add(jlab10);
    pn3.add(jlab11);
    pn3.add(jtf11);
    pn3.add(jtf12);

    JPanel pn4 = new JPanel();
    pn4.setOpaque(true);
    pn4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "result"));

    JLabel jlab12 = new JLabel("p-value");
    final JLabel jlab13 = new JLabel("odds ratio");
    final JLabel jlab14 = new JLabel("standard error");
    final JLabel jlab15 = new JLabel("confidence interval 95%");

    jtf13 = new JTextField();
    jtf14 = new JTextField();
    jtf15 = new JTextField();
    jtf16 = new JTextField();
    jtf17 = new JTextField();

    jlab13.setEnabled(false);
    jlab14.setEnabled(false);
    jlab15.setEnabled(false);
    jtf14.setEnabled(false);
    jtf15.setEnabled(false);
    jtf16.setEnabled(false);
    jtf17.setEnabled(false);

    JButton jbtn1 = new JButton("Run 2x2");
    jbtn1.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            long number1, number2, number3, number4;
            try {
                number1 = Long.parseLong(jtf1.getText());
                number2 = Long.parseLong(jtf2.getText());
                number3 = Long.parseLong(jtf3.getText());
                number4 = Long.parseLong(jtf4.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!");
                return;
            }

            long[][] obs = new long[2][2];

            obs[0][0] = number1;
            obs[0][1] = number2;
            obs[1][0] = number3;
            obs[1][1] = number4;

            ChiSquareTest mychiSquare = new ChiSquareTest();

            final java.text.DecimalFormat mydf = new java.text.DecimalFormat("0.0000");

            double stats = mychiSquare.chiSquare(obs);
            jtf11.setText(String.valueOf(mydf.format(stats)));
            jtf12.setText(String.valueOf(1));

            double pvalue = mychiSquare.chiSquareTest(obs);
            jtf13.setText(String.valueOf(pvalue));

            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");

            jlab13.setEnabled(true);
            jlab14.setEnabled(true);
            jlab15.setEnabled(true);
            jtf14.setEnabled(true);
            jtf15.setEnabled(true);
            jtf16.setEnabled(true);
            jtf17.setEnabled(true);

            double or = (double) (number2 * number3) / (number1 * number4);
            double se = Math.sqrt(
                    (double) 1 / number1 + (double) 1 / number2 + (double) 1 / number3 + (double) 1 / number4);
            double logOR = Math.log(or);
            double logU95 = logOR + 1.96 * se;
            double logL95 = logOR - 1.96 * se;
            double U95 = Math.exp(logU95);
            double L95 = Math.exp(logL95);

            jtf14.setText(String.valueOf(mydf.format(or)));
            jtf15.setText(String.valueOf(mydf.format(se)));
            jtf16.setText(String.valueOf(mydf.format(L95)));
            jtf17.setText(String.valueOf(mydf.format(U95)));

        }
    });

    JButton jbtn2 = new JButton("Run 2x3");
    jbtn2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            long number1, number2, number3, number4, number5, number6;
            try {
                number1 = Long.parseLong(jtf5.getText());
                number2 = Long.parseLong(jtf6.getText());
                number3 = Long.parseLong(jtf7.getText());
                number4 = Long.parseLong(jtf8.getText());
                number5 = Long.parseLong(jtf9.getText());
                number6 = Long.parseLong(jtf10.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!");
                return;
            }

            long[][] obs = new long[2][3];

            obs[0][0] = number1;
            obs[0][1] = number2;
            obs[0][2] = number3;
            obs[1][0] = number4;
            obs[1][1] = number5;
            obs[1][2] = number6;

            ChiSquareTest mychiSquare = new ChiSquareTest();

            final java.text.DecimalFormat mydf = new java.text.DecimalFormat("0.0000");

            double stats = mychiSquare.chiSquare(obs);
            jtf11.setText(String.valueOf(mydf.format(stats)));
            jtf12.setText(String.valueOf(2));

            double pvalue = mychiSquare.chiSquareTest(obs);
            jtf13.setText(String.valueOf(pvalue));

            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);

        }
    });

    JButton jbtn3 = new JButton("Run Statistic");
    jbtn3.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            double stat, df;
            try {
                stat = Double.parseDouble(jtf11.getText());
                df = Double.parseDouble(jtf12.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only number is acceptable!");
                return;
            }
            ChiSquaredDistribution distribution = new ChiSquaredDistribution(df);
            double pvalue = 1 - distribution.cumulativeProbability(stat);
            jtf13.setText(String.valueOf(pvalue));

            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);
        }
    });

    JButton jbtn4 = new JButton("clear");
    jbtn4.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");
            jtf11.setText("");
            jtf12.setText("");
            jtf13.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);
        }
    });

    GridBagLayout CalLayout4 = new GridBagLayout();
    GridBagConstraints gbc4 = new GridBagConstraints();
    pn4.setLayout(CalLayout4);
    gbc4.weightx = 1.0; //default 0.0
    gbc4.weighty = 1.0; //default 0.0      
    // gbc4.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc4.insets = new Insets(1, 1, 1, 1);
    gbc4.fill = GridBagConstraints.BOTH;

    gbc4.gridwidth = 1;

    gbc4.gridx = 0;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn1, gbc4);

    gbc4.gridx = 1;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn2, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn3, gbc4);

    gbc4.gridx = 3;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn4, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 1;
    CalLayout4.setConstraints(jlab12, gbc4);

    gbc4.gridwidth = 3;

    gbc4.gridx = 1;
    gbc4.gridy = 1;
    CalLayout4.setConstraints(jtf13, gbc4);

    gbc4.gridwidth = 2;

    gbc4.gridx = 0;
    gbc4.gridy = 2;
    CalLayout4.setConstraints(jlab13, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 2;
    CalLayout4.setConstraints(jtf14, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 3;
    CalLayout4.setConstraints(jlab14, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 3;
    CalLayout4.setConstraints(jtf15, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jlab15, gbc4);

    gbc4.gridwidth = 1;

    gbc4.gridx = 2;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jtf16, gbc4);

    gbc4.gridx = 3;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jtf17, gbc4);

    pn4.add(jlab12);
    pn4.add(jlab13);
    pn4.add(jlab14);
    pn4.add(jlab15);
    pn4.add(jtf13);
    pn4.add(jtf14);
    pn4.add(jtf15);
    pn4.add(jtf16);
    pn4.add(jtf17);
    pn4.add(jbtn1);
    pn4.add(jbtn2);
    pn4.add(jbtn3);
    pn4.add(jbtn4);

    // jfrm layout all
    GridBagLayout CalLayout = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    jfrm.setLayout(CalLayout);

    gbc.weightx = 1.0; //default 0.0
    gbc.weighty = 1.0; //default 0.0

    gbc.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc.fill = GridBagConstraints.BOTH;

    gbc.gridwidth = 4;

    gbc.gridx = 0;
    gbc.gridy = 0;
    CalLayout.setConstraints(pn1, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    CalLayout.setConstraints(pn2, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    CalLayout.setConstraints(pn3, gbc);

    gbc.gridx = 0;
    gbc.gridy = 3;
    CalLayout.setConstraints(pn4, gbc);

    jfrm.add(pn1);
    jfrm.add(pn2);
    jfrm.add(pn3);
    jfrm.add(pn4);

    // Help Menu Bar
    JMenuBar jmb = new JMenuBar();
    JMenu jmh = new JMenu("Help");
    JMenuItem jmiAbout = new JMenuItem("About");
    jmiAbout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            JOptionPane.showMessageDialog(jfrm,
                    "Name:          Chi Square Calculator\n" + "Version:       1.0\n"
                            + "Author:         Felix Yanhui Fan\n" + "EMail:          felixfanyh@gmail.com\n"
                            + "Website:     http://felixfan.github.io/ChiSquareCalculator\n");
        }
    });
    JMenuItem jmiLisence = new JMenuItem("Lisence");
    jmiLisence.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(jfrm,
                    "This program is licensed under the terms of \n"
                            + "the GNU General Public License version 3 \n" + "Available online under: \n"
                            + "http://www.gnu.org/licenses/gpl-3.0.html\n");
        }
    });

    jmh.add(jmiAbout);
    jmh.add(jmiLisence);

    jmb.add(Box.createHorizontalGlue()); // Aligning JMenu on the right corner of JMenuBar
    jmb.add(jmh);

    jfrm.setJMenuBar(jmb);

    jfrm.setVisible(true);
}

From source file:ChiSquareCalculator.java

ChiSquareCalculator() {
    final JFrame jfrm = new JFrame("Chi Square Calculator");
    jfrm.setSize(400, 550);//w  ww  .j a v a2s  .  c om
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jfrm.setResizable(false);

    // panel 1
    JPanel pn1 = new JPanel();
    pn1.setOpaque(true);
    pn1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 2"));

    JLabel jlab1 = new JLabel("class 1");
    JLabel jlab2 = new JLabel("class 2");
    JLabel jlab3 = new JLabel("case");
    JLabel jlab4 = new JLabel("control");

    jtf1 = new JTextField();
    jtf2 = new JTextField();
    jtf3 = new JTextField();
    jtf4 = new JTextField();

    // pn1 layout all
    GridBagLayout CalLayout1 = new GridBagLayout();
    GridBagConstraints gbc1 = new GridBagConstraints();
    pn1.setLayout(CalLayout1);
    gbc1.weightx = 1.0; //default 0.0
    gbc1.weighty = 1.0; //default 0.0      
    gbc1.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc1.fill = GridBagConstraints.BOTH;

    gbc1.gridwidth = 1;

    gbc1.gridx = 1;
    gbc1.gridy = 0;
    CalLayout1.setConstraints(jlab1, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 0;
    CalLayout1.setConstraints(jlab2, gbc1);

    gbc1.gridx = 0;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jlab3, gbc1);

    gbc1.gridx = 1;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jtf1, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jtf2, gbc1);

    gbc1.gridx = 0;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jlab4, gbc1);

    gbc1.gridx = 1;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jtf3, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jtf4, gbc1);

    pn1.add(jlab1);
    pn1.add(jlab2);
    pn1.add(jlab3);
    pn1.add(jlab4);
    pn1.add(jtf1);
    pn1.add(jtf2);
    pn1.add(jtf3);
    pn1.add(jtf4);

    // panel 2
    JPanel pn2 = new JPanel();
    pn2.setOpaque(true);
    pn2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 3"));

    JLabel jlab5 = new JLabel("class 1");
    JLabel jlab6 = new JLabel("class 2");
    JLabel jlab7 = new JLabel("class 3");
    JLabel jlab8 = new JLabel("case");
    JLabel jlab9 = new JLabel("control");

    jtf5 = new JTextField();
    jtf6 = new JTextField();
    jtf7 = new JTextField();
    jtf8 = new JTextField();
    jtf9 = new JTextField();
    jtf10 = new JTextField();

    // pn2 layout all
    GridBagLayout CalLayout2 = new GridBagLayout();
    GridBagConstraints gbc2 = new GridBagConstraints();
    pn2.setLayout(CalLayout2);
    gbc2.weightx = 1.0; //default 0.0
    gbc2.weighty = 1.0; //default 0.0      
    gbc2.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc2.fill = GridBagConstraints.BOTH;

    gbc2.gridwidth = 1;

    gbc2.gridx = 1;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab5, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab6, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab7, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jlab8, gbc2);

    gbc2.gridx = 1;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf5, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf6, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf7, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jlab9, gbc2);

    gbc2.gridx = 1;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf8, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf9, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf10, gbc2);

    pn2.add(jlab5);
    pn2.add(jlab6);
    pn2.add(jlab7);
    pn2.add(jlab8);
    pn2.add(jlab9);
    pn2.add(jtf5);
    pn2.add(jtf6);
    pn2.add(jtf7);
    pn2.add(jtf8);
    pn2.add(jtf9);
    pn2.add(jtf10);

    // panel 3      
    JPanel pn3 = new JPanel();
    pn3.setOpaque(true);
    pn3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "statistic"));

    JLabel jlab10 = new JLabel("chi-square");
    JLabel jlab11 = new JLabel("degree of freedom");

    jtf11 = new JTextField();
    jtf12 = new JTextField();

    GridBagLayout CalLayout3 = new GridBagLayout();
    GridBagConstraints gbc3 = new GridBagConstraints();
    pn3.setLayout(CalLayout3);
    gbc3.weightx = 1.0; //default 0.0
    gbc3.weighty = 1.0; //default 0.0      
    gbc3.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc3.fill = GridBagConstraints.BOTH;

    gbc3.gridwidth = 1;

    gbc3.gridx = 0;
    gbc3.gridy = 0;
    CalLayout3.setConstraints(jlab10, gbc3);

    gbc3.gridwidth = 3;

    gbc3.gridx = 1;
    gbc3.gridy = 0;
    CalLayout3.setConstraints(jtf11, gbc3);

    gbc3.gridwidth = 2;

    gbc3.gridx = 0;
    gbc3.gridy = 1;
    CalLayout3.setConstraints(jlab11, gbc3);

    gbc3.gridx = 2;
    gbc3.gridy = 1;
    CalLayout3.setConstraints(jtf12, gbc3);

    pn3.add(jlab10);
    pn3.add(jlab11);
    pn3.add(jtf11);
    pn3.add(jtf12);

    JPanel pn4 = new JPanel();
    pn4.setOpaque(true);
    pn4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "result"));

    JLabel jlab12 = new JLabel("p-value");
    final JLabel jlab13 = new JLabel("odds ratio");
    final JLabel jlab14 = new JLabel("standard error");
    final JLabel jlab15 = new JLabel("confidence interval 95%");

    jtf13 = new JTextField();
    jtf14 = new JTextField();
    jtf15 = new JTextField();
    jtf16 = new JTextField();
    jtf17 = new JTextField();

    jlab13.setEnabled(false);
    jlab14.setEnabled(false);
    jlab15.setEnabled(false);
    jtf14.setEnabled(false);
    jtf15.setEnabled(false);
    jtf16.setEnabled(false);
    jtf17.setEnabled(false);

    JButton jbtn1 = new JButton("Run 2x2");
    jbtn1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            long number1, number2, number3, number4;
            try {
                number1 = Long.parseLong(jtf1.getText());
                number2 = Long.parseLong(jtf2.getText());
                number3 = Long.parseLong(jtf3.getText());
                number4 = Long.parseLong(jtf4.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!");
                return;
            }

            long[][] obs = new long[2][2];

            obs[0][0] = number1;
            obs[0][1] = number2;
            obs[1][0] = number3;
            obs[1][1] = number4;

            ChiSquareTest mychiSquare = new ChiSquareTest();

            double stats = mychiSquare.chiSquare(obs);
            jtf11.setText(String.valueOf(stats));
            jtf12.setText(String.valueOf(1));

            double pvalue = mychiSquare.chiSquareTest(obs);
            jtf13.setText(String.valueOf(pvalue));

            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");

            jlab13.setEnabled(true);
            jlab14.setEnabled(true);
            jlab15.setEnabled(true);
            jtf14.setEnabled(true);
            jtf15.setEnabled(true);
            jtf16.setEnabled(true);
            jtf17.setEnabled(true);

            double or = (double) (number2 * number3) / (number1 * number4);
            double se = Math.sqrt(
                    (double) 1 / number1 + (double) 1 / number2 + (double) 1 / number3 + (double) 1 / number4);
            double logOR = Math.log(or);
            double logU95 = logOR + 1.96 * se;
            double logL95 = logOR - 1.96 * se;
            double U95 = Math.exp(logU95);
            double L95 = Math.exp(logL95);

            final java.text.DecimalFormat mydf = new java.text.DecimalFormat("0.000000");

            jtf14.setText(String.valueOf(or));
            jtf15.setText(String.valueOf(se));
            jtf16.setText(String.valueOf(mydf.format(L95)));
            jtf17.setText(String.valueOf(mydf.format(U95)));

        }
    });

    JButton jbtn2 = new JButton("Run 2x3");
    jbtn2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            long number1, number2, number3, number4, number5, number6;
            try {
                number1 = Long.parseLong(jtf5.getText());
                number2 = Long.parseLong(jtf6.getText());
                number3 = Long.parseLong(jtf7.getText());
                number4 = Long.parseLong(jtf8.getText());
                number5 = Long.parseLong(jtf9.getText());
                number6 = Long.parseLong(jtf10.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!");
                return;
            }

            long[][] obs = new long[2][3];

            obs[0][0] = number1;
            obs[0][1] = number2;
            obs[0][2] = number3;
            obs[1][0] = number4;
            obs[1][1] = number5;
            obs[1][2] = number6;

            ChiSquareTest mychiSquare = new ChiSquareTest();

            double stats = mychiSquare.chiSquare(obs);
            jtf11.setText(String.valueOf(stats));
            jtf12.setText(String.valueOf(2));

            double pvalue = mychiSquare.chiSquareTest(obs);
            jtf13.setText(String.valueOf(pvalue));

            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);

        }
    });

    JButton jbtn3 = new JButton("Run Statistic");
    jbtn3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            double stat, df;
            try {
                stat = Double.parseDouble(jtf11.getText());
                df = Double.parseDouble(jtf12.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only number is acceptable!");
                return;
            }
            ChiSquaredDistribution distribution = new ChiSquaredDistribution(df);
            double pvalue = 1 - distribution.cumulativeProbability(stat);
            jtf13.setText(String.valueOf(pvalue));

            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);
        }
    });

    JButton jbtn4 = new JButton("clear");
    jbtn4.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");
            jtf11.setText("");
            jtf12.setText("");
            jtf13.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);
        }
    });

    GridBagLayout CalLayout4 = new GridBagLayout();
    GridBagConstraints gbc4 = new GridBagConstraints();
    pn4.setLayout(CalLayout4);
    gbc4.weightx = 1.0; //default 0.0
    gbc4.weighty = 1.0; //default 0.0      
    gbc4.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc4.fill = GridBagConstraints.BOTH;

    gbc4.gridwidth = 1;

    gbc4.gridx = 0;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn1, gbc4);

    gbc4.gridx = 1;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn2, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn3, gbc4);

    gbc4.gridx = 3;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn4, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 1;
    CalLayout4.setConstraints(jlab12, gbc4);

    gbc4.gridwidth = 3;

    gbc4.gridx = 1;
    gbc4.gridy = 1;
    CalLayout4.setConstraints(jtf13, gbc4);

    gbc4.gridwidth = 2;

    gbc4.gridx = 0;
    gbc4.gridy = 2;
    CalLayout4.setConstraints(jlab13, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 2;
    CalLayout4.setConstraints(jtf14, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 3;
    CalLayout4.setConstraints(jlab14, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 3;
    CalLayout4.setConstraints(jtf15, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jlab15, gbc4);

    gbc4.gridwidth = 1;

    gbc4.gridx = 2;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jtf16, gbc4);

    gbc4.gridx = 3;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jtf17, gbc4);

    pn4.add(jlab12);
    pn4.add(jlab13);
    pn4.add(jlab14);
    pn4.add(jlab15);
    pn4.add(jtf13);
    pn4.add(jtf14);
    pn4.add(jtf15);
    pn4.add(jtf16);
    pn4.add(jtf17);
    pn4.add(jbtn1);
    pn4.add(jbtn2);
    pn4.add(jbtn3);
    pn4.add(jbtn4);

    // jfrm layout all
    GridBagLayout CalLayout = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    jfrm.setLayout(CalLayout);

    gbc.weightx = 1.0; //default 0.0
    gbc.weighty = 1.0; //default 0.0

    gbc.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc.fill = GridBagConstraints.BOTH;

    gbc.gridwidth = 4;

    gbc.gridx = 0;
    gbc.gridy = 0;
    CalLayout.setConstraints(pn1, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    CalLayout.setConstraints(pn2, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    CalLayout.setConstraints(pn3, gbc);

    gbc.gridx = 0;
    gbc.gridy = 3;
    CalLayout.setConstraints(pn4, gbc);

    jfrm.add(pn1);
    jfrm.add(pn2);
    jfrm.add(pn3);
    jfrm.add(pn4);

    // Help Menu Bar
    JMenuBar jmb = new JMenuBar();
    JMenu jmh = new JMenu("Help");
    JMenuItem jmiAbout = new JMenuItem("About");
    jmiAbout.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JOptionPane.showMessageDialog(jfrm,
                    "Name:          Chi Square Calculator\n" + "Version:       1.0\n"
                            + "Author:         Felix Yanhui Fan\n" + "EMail:           nolanfyh@gmail.com\n"
                            + "Website:     http://felixfan.github.io/ChiSquareCalculator\n");

        }
    });
    JMenuItem jmiLisence = new JMenuItem("Lisence");
    jmiLisence.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(jfrm,
                    "This program is licensed under the terms of \n"
                            + "the GNU General Public License version 3 \n" + "Available online under: \n"
                            + "http://www.gnu.org/licenses/gpl-3.0.html\n");

        }
    });

    jmh.add(jmiAbout);
    jmh.add(jmiLisence);

    jmb.add(Box.createHorizontalGlue()); // Aligning JMenu on the right corner of JMenuBar
    jmb.add(jmh);

    jfrm.setJMenuBar(jmb);

    jfrm.setVisible(true);
}

From source file:direccion.Reportes.java

public Reportes() {

    String titulo = "Reportes";
    jFrame = new JFrame(titulo);
    jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    jFrame.setSize(800, 600);//from  ww w  .  j  a  v a 2  s .  c om

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screenSize.width / 2) - (jFrame.getSize().width / 2);
    int y = (screenSize.height / 2) - (jFrame.getSize().height / 2);
    jFrame.setLocation(x, y);

    JLabel etiqueta = new JLabel("Reportes");
    etiqueta.setBounds(300, 25, 200, 50);
    etiqueta.setFont(new Font("Verdana", Font.BOLD, 30));
    etiqueta.setForeground(Color.BLACK);

    JMenuBar jMenuBar = new JMenuBar();

    JMenu acceso = new JMenu("Acceso a");
    JMenu ayuda = new JMenu("Ayuda");

    JMenuItem rec_hum = new JMenuItem("Recursos Humanos");
    JMenuItem conta = new JMenuItem("Contabilidad");
    JMenuItem ventas = new JMenuItem("Ventas");
    JMenuItem compras = new JMenuItem("Compras");
    JMenuItem inventario = new JMenuItem("Inventario");

    JMenuItem acerca_de = new JMenuItem("Acerca de");
    acerca_de.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "Ayuda", "Ayuda", 3);
        }
    });

    acceso.add(rec_hum);
    acceso.add(conta);
    acceso.add(ventas);
    acceso.add(compras);
    acceso.add(inventario);

    ayuda.add(acerca_de);

    jMenuBar.add(acceso);
    jMenuBar.add(ayuda);

    JCalendar cal1 = new JCalendar();
    cal1.setBounds(250, 150, 400, 300);
    JCalendarCombo cal2 = new JCalendarCombo();
    cal2.setBounds(250, 150, 400, 300);

    String reportes[] = { "Mantenimiento", "Compras", "Ventas", "Inventario", "Contabilidad",
            "Recursos Humanos" };
    JComboBox combobox = new JComboBox(reportes);
    combobox.setBounds(300, 100, 150, 30);

    JLabel calendario = new JLabel("Fecha de Operacin:");
    calendario.setBounds(60, 150, 150, 30);

    JButton aceptar = new JButton("Aceptar");
    aceptar.setBounds(50, 200, 150, 30);
    aceptar.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (combobox.getSelectedIndex() == 0) {

                datos_mantenimiento.setValue("Recursos Humanos", d_mant_rh);
                datos_mantenimiento.setValue("Contabilidad", d_mant_cont);
                datos_mantenimiento.setValue("Ventas", d_mant_vent);
                datos_mantenimiento.setValue("Compras", d_mant_comp);
                datos_mantenimiento.setValue("Inventario", d_mant_inv);
                datos_mantenimiento.setValue("Mantenimiento", d_mant_mant);

                Grafica = ChartFactory.createPieChart3D("Mantenimiento", datos_mantenimiento, true, true, true);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Mantenimiento.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Mantenimiento");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Mantenimiento.xls");
                        Cell celda;

                        String[] titulos = { "Recursos Humanos", "Contabilidad", "Ventas", "Compras",
                                "Inventario", "Mantenimiento" };
                        Double[] datos = { d_mant_rh, d_mant_cont, d_mant_vent, d_mant_comp, d_mant_inv,
                                d_mant_mant };

                        int i;
                        for (i = 0; i < titulos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(titulos[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < datos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(datos[i]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 1) {

                datos_compras.setValue("Nomina", d_comp_nom);
                datos_compras.setValue("Compras", d_comp_comp);
                datos_compras.setValue("Gastos Fijos", d_comp_gf);
                datos_compras.setValue("Gastos Variables", d_comp_gv);
                datos_compras.setValue("Gastos Otros", d_comp_go);

                Grafica = ChartFactory.createPieChart3D("Compras", datos_compras, true, true, true);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Compras.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        menu.setVisible(false);
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(850, 850);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Compras");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Compras.xls");
                        Cell celda;

                        String[] titulos = { "Nomina", "Compras", "Gastos Fijos", "Gastos Variables",
                                "Gastos Otros" };
                        Double[] datos = { d_comp_nom, d_comp_comp, d_comp_gf, d_comp_gv, d_comp_go };

                        int i;
                        for (i = 0; i < titulos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(titulos[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < datos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(datos[i]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 2) {

                datos_ventas.addValue(d_vent_s1_lu, "Semana 1", "Lunes");
                datos_ventas.addValue(d_vent_s1_ma, "Semana 1", "Martes");
                datos_ventas.addValue(d_vent_s1_mi, "Semana 1", "Mircoles");
                datos_ventas.addValue(d_vent_s1_ju, "Semana 1", "Jueves");
                datos_ventas.addValue(d_vent_s1_vi, "Semana 1", "Viernes");
                datos_ventas.addValue(d_vent_s1_sa, "Semana 1", "Sbado");
                datos_ventas.addValue(d_vent_s1_do, "Semana 1", "Domingo");

                datos_ventas.addValue(d_vent_s2_lu, "Semana 2", "Lunes");
                datos_ventas.addValue(d_vent_s2_ma, "Semana 2", "Martes");
                datos_ventas.addValue(d_vent_s2_mi, "Semana 2", "Mircoles");
                datos_ventas.addValue(d_vent_s2_ju, "Semana 2", "Jueves");
                datos_ventas.addValue(d_vent_s2_vi, "Semana 2", "Viernes");
                datos_ventas.addValue(d_vent_s2_sa, "Semana 2", "Sbado");
                datos_ventas.addValue(d_vent_s2_do, "Semana 2", "Domingo");

                Grafica = ChartFactory.createLineChart3D("Ventas", "Das", "Ingresos", datos_ventas,
                        PlotOrientation.VERTICAL, true, true, false);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Ventas.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Ventas");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Ventas.xls");
                        Cell celda;

                        String[] titulos1 = { "S1 lunes", "S1 martes", "S1 miercoles", "S1 jueves",
                                "S1 viernes", "S1 sabado", "S1 domingo" };
                        String[] titulos2 = { "S2 lunes", "S2 martes", "S2 miercoles", "S2 jueves",
                                "S2 viernes", "S2 sabado", "S2 domingo" };
                        Double[] datos1 = { d_vent_s1_lu, d_vent_s1_ma, d_vent_s1_mi, d_vent_s1_ju,
                                d_vent_s1_vi, d_vent_s1_sa, d_vent_s1_do };
                        Double[] datos2 = { d_vent_s2_lu, d_vent_s2_ma, d_vent_s2_mi, d_vent_s2_ju,
                                d_vent_s2_vi, d_vent_s2_sa, d_vent_s2_do };

                        int i, j;
                        for (i = 0; i < titulos1.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(titulos1[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < datos1.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(datos1[i]);
                        }
                        fila = sheet.createRow(3);
                        for (j = 0; j < titulos2.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(titulos2[j]);
                        }
                        fila = sheet.createRow(4);
                        for (j = 0; j < datos2.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(datos2[j]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 3) {

                datos_inventario.setValue("Producto 1", d_inv_p1);
                datos_inventario.setValue("Producto 2", d_inv_p2);
                datos_inventario.setValue("Producto 3", d_inv_p3);
                datos_inventario.setValue("Producto 4", d_inv_p4);
                datos_inventario.setValue("Producto 5", d_inv_p5);

                Grafica = ChartFactory.createPieChart3D("Inventario", datos_inventario, true, true, true);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Inventario.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Inventario");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Inventario.xls");
                        Cell celda;

                        String[] titulos = { "Producto 1", "Producto 2", "Prroducto 3", "Producto 4",
                                "Producto 5" };
                        Double[] datos = { d_inv_p1, d_inv_p2, d_inv_p3, d_inv_p4, d_inv_p5 };

                        int i;
                        for (i = 0; i < titulos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(titulos[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < datos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(datos[i]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 4) {

                datos_contabilidad.addValue(d_cont_e_lu, "Entradas", "Lunes");
                datos_contabilidad.addValue(d_cont_e_ma, "Entradas", "Martes");
                datos_contabilidad.addValue(d_cont_e_mi, "Entradas", "Mircoles");
                datos_contabilidad.addValue(d_cont_e_ju, "Entradas", "Jueves");
                datos_contabilidad.addValue(d_cont_e_vi, "Entradas", "Viernes");
                datos_contabilidad.addValue(d_cont_e_sa, "Entradas", "Sbado");
                datos_contabilidad.addValue(d_cont_e_do, "Entradas", "Domingo");

                datos_contabilidad.addValue(d_cont_s_lu, "Salidas", "Lunes");
                datos_contabilidad.addValue(d_cont_s_ma, "Salidas", "Martes");
                datos_contabilidad.addValue(d_cont_s_mi, "Salidas", "Mircoles");
                datos_contabilidad.addValue(d_cont_s_ju, "Salidas", "Jueves");
                datos_contabilidad.addValue(d_cont_s_vi, "Salidas", "Viernes");
                datos_contabilidad.addValue(d_cont_s_sa, "Salidas", "Sbado");
                datos_contabilidad.addValue(d_cont_s_do, "Salidas", "Domingo");

                datos_contabilidad.addValue(d_cont_u_lu, "Utilidades", "Lunes");
                datos_contabilidad.addValue(d_cont_u_ma, "Utilidades", "Martes");
                datos_contabilidad.addValue(d_cont_u_mi, "Utilidades", "Mircoles");
                datos_contabilidad.addValue(d_cont_u_ju, "Utilidades", "Jueves");
                datos_contabilidad.addValue(d_cont_u_vi, "Utilidades", "Viernes");
                datos_contabilidad.addValue(d_cont_u_sa, "Utilidades", "Sbado");
                datos_contabilidad.addValue(d_cont_u_do, "Utilidades", "Domingo");

                Grafica = ChartFactory.createLineChart3D("Contabilidad", "Das", "Ingresos",
                        datos_contabilidad, PlotOrientation.VERTICAL, true, true, false);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Contabilidad.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Contabilidad");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Contabilidad.xls");
                        Cell celda;

                        String[] t_ent = { "E lunes", "E martes", "E miercoles", "E jueves", "E viernes",
                                "E sabado", "E domingo" };
                        String[] t_sal = { "S lunes", "S martes", "S miercoles", "S jueves", "S viernes",
                                "S sabado", "S domingo" };
                        String[] t_uti = { "U lunes", "U martes", "U miercoles", "U jueves", "U viernes",
                                "U sabado", "U domingo" };
                        Double[] d_ent = { d_cont_e_lu, d_cont_e_ma, d_cont_e_mi, d_cont_e_ju, d_cont_e_vi,
                                d_cont_e_sa, d_cont_e_do };
                        Double[] d_sal = { d_cont_s_lu, d_cont_s_ma, d_cont_s_mi, d_cont_s_ju, d_cont_s_vi,
                                d_cont_s_sa, d_cont_s_do };
                        Double[] d_uti = { d_cont_u_lu, d_cont_u_ma, d_cont_u_mi, d_cont_u_ju, d_cont_u_vi,
                                d_cont_u_sa, d_cont_u_do };

                        int i, j, k;
                        for (i = 0; i < t_ent.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(t_ent[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < d_ent.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(d_ent[i]);
                        }
                        fila = sheet.createRow(3);
                        for (j = 0; j < t_sal.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(t_sal[j]);
                        }
                        fila = sheet.createRow(4);
                        for (j = 0; j < d_sal.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(d_sal[j]);
                        }
                        fila = sheet.createRow(6);
                        for (k = 0; k < t_uti.length; k++) {
                            celda = fila.createCell(k);
                            celda.setCellValue(t_uti[k]);
                        }
                        fila = sheet.createRow(7);
                        for (k = 0; k < d_uti.length; k++) {
                            celda = fila.createCell(k);
                            celda.setCellValue(d_uti[k]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 5) {

                datos_rec_hum.addValue(d_rh_a_lu, "Asistencias", "Lunes");
                datos_rec_hum.addValue(d_rh_a_ma, "Asistencias", "Martes");
                datos_rec_hum.addValue(d_rh_a_mi, "Asistencias", "Mircoles");
                datos_rec_hum.addValue(d_rh_a_ju, "Asistencias", "Jueves");
                datos_rec_hum.addValue(d_rh_a_vi, "Asistencias", "Viernes");
                datos_rec_hum.addValue(d_rh_a_sa, "Asistencias", "Sbado");
                datos_rec_hum.addValue(d_rh_a_do, "Asistencias", "Domingo");

                datos_rec_hum.addValue(d_rh_r_lu, "Retardos", "Lunes");
                datos_rec_hum.addValue(d_rh_r_ma, "Retardos", "Martes");
                datos_rec_hum.addValue(d_rh_r_mi, "Retardos", "Mircoles");
                datos_rec_hum.addValue(d_rh_r_ju, "Retardos", "Jueves");
                datos_rec_hum.addValue(d_rh_r_vi, "Retardos", "Viernes");
                datos_rec_hum.addValue(d_rh_r_sa, "Retardos", "Sbado");
                datos_rec_hum.addValue(d_rh_r_do, "Retardos", "Domingo");

                datos_rec_hum.addValue(d_rh_f_lu, "Faltas", "Lunes");
                datos_rec_hum.addValue(d_rh_f_ma, "Faltas", "Martes");
                datos_rec_hum.addValue(d_rh_f_mi, "Faltas", "Mircoles");
                datos_rec_hum.addValue(d_rh_f_ju, "Faltas", "Jueves");
                datos_rec_hum.addValue(d_rh_f_vi, "Faltas", "Viernes");
                datos_rec_hum.addValue(d_rh_f_sa, "Faltas", "Sbado");
                datos_rec_hum.addValue(d_rh_f_do, "Faltas", "Domingo");

                Grafica = ChartFactory.createBarChart3D("Recursos Humanos", "Das", "Nmero de Empleados",
                        datos_rec_hum, PlotOrientation.VERTICAL, true, true, false);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Recursos Humanos.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Recursos Humanos");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Recursos Humanos.xls");
                        Cell celda;

                        String[] t_asi = { "A lunes", "A martes", "A miercoles", "A jueves", "A viernes",
                                "A sabado", "A domingo" };
                        String[] t_ret = { "R lunes", "R martes", "R miercoles", "R jueves", "R viernes",
                                "R sabado", "R domingo" };
                        String[] t_fal = { "F lunes", "F martes", "F miercoles", "F jueves", "F viernes",
                                "F sabado", "F domingo" };
                        int[] d_asi = { d_rh_a_lu, d_rh_a_ma, d_rh_a_mi, d_rh_a_ju, d_rh_a_vi, d_rh_a_sa,
                                d_rh_a_do };
                        int[] d_ret = { d_rh_r_lu, d_rh_r_ma, d_rh_r_mi, d_rh_r_ju, d_rh_r_vi, d_rh_r_sa,
                                d_rh_r_do };
                        int[] d_fal = { d_rh_f_lu, d_rh_r_ma, d_rh_r_mi, d_rh_r_ju, d_rh_r_vi, d_rh_r_sa,
                                d_rh_r_do };

                        int i, j, k;
                        for (i = 0; i < t_asi.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(t_asi[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < d_asi.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(d_asi[i]);
                        }
                        fila = sheet.createRow(3);
                        for (j = 0; j < t_ret.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(t_ret[j]);
                        }
                        fila = sheet.createRow(4);
                        for (j = 0; j < d_ret.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(d_ret[j]);
                        }
                        fila = sheet.createRow(6);
                        for (k = 0; k < t_fal.length; k++) {
                            celda = fila.createCell(k);
                            celda.setCellValue(t_fal[k]);
                        }
                        fila = sheet.createRow(7);
                        for (k = 0; k < d_fal.length; k++) {
                            celda = fila.createCell(k);
                            celda.setCellValue(d_fal[k]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
        }
    });

    jPanel = new JPanel();
    jPanel.setLayout(null);

    jPanel.add(cal1);
    jPanel.add(cal2);
    jPanel.add(etiqueta);
    jPanel.add(combobox);
    jPanel.add(calendario);
    jPanel.add(aceptar);
    jFrame.setJMenuBar(jMenuBar);
    jFrame.add(jPanel);

    jFrame.setVisible(true);
}

From source file:edu.ku.brc.specify.utilapps.RegisterApp.java

/**
 * //w  w  w.  j av a2s .co  m
 */
protected void doStart() {
    frame = new JFrame();
    JMenuBar mb = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    JMenu rptMenu = new JMenu("Reports");
    //JMenu     chrtMenu   = new JMenu("Charts");

    frame.setTitle(title);

    JMenuItem doISARegReportMI = new JMenuItem("ISA Reg Report");
    rptMenu.add(doISARegReportMI);

    JMenuItem doStatsMI = new JMenuItem("Registration");
    rptMenu.add(doStatsMI);

    //JMenuItem doMiscMI = new JMenuItem("Misc");
    //chrtMenu.add(doMiscMI);

    //menu.addSeparator();
    JMenuItem doSetVersionMI = new JMenuItem("Set Version");
    fileMenu.add(doSetVersionMI);

    if (!UIHelper.isMacOS()) {
        fileMenu.addSeparator();
        JMenuItem doExitMI = new JMenuItem("Exit");
        fileMenu.add(doExitMI);
        doExitMI.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                doExit(true);
            }
        });
    }

    mb.add(fileMenu);
    mb.add(rptMenu);
    //mb.add(chrtMenu);

    frame.setJMenuBar(mb);
    frame.setContentPane(this);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(0, 0, 600, 768);
    UIHelper.centerAndShow(frame);

    doISARegReportMI.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            createRegReport();
        }
    });

    doStatsMI.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            createStatsReport();
        }
    });

    doSetVersionMI.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doSetVersion();
        }
    });
}

From source file:de.dmarcini.submatix.pclogger.gui.MainCommGUI.java

/**
 * Initialize the contents of the frame.
 * /*from www  . j  a  v a  2s.  c  o  m*/
 * @throws ClassNotFoundException
 * @throws SQLException
 */
private void initializeGUI() throws SQLException, ClassNotFoundException {
    frmMainWindow = new JFrame();
    frmMainWindow.setFont(new Font("Arial", Font.PLAIN, 12));
    frmMainWindow.setSize(new Dimension(810, 600));
    frmMainWindow.setResizable(false);
    frmMainWindow.setIconImage(Toolkit.getDefaultToolkit()
            .getImage(MainCommGUI.class.getResource("/de/dmarcini/submatix/pclogger/res/112.png")));
    frmMainWindow.setTitle(LangStrings.getString("MainCommGUI.frmMainWindow.title")); //$NON-NLS-1$
    frmMainWindow.setBounds(100, 100, 800, 600);
    frmMainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frmMainWindow.getContentPane().setLayout(new BorderLayout(0, 0));
    frmMainWindow.addWindowListener(new MainWindowListener());
    statusTextField = new JTextField();
    statusTextField.setEditable(false);
    statusTextField.setText("-");
    frmMainWindow.getContentPane().add(statusTextField, BorderLayout.SOUTH);
    statusTextField.setColumns(10);
    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    frmMainWindow.getContentPane().add(tabbedPane, BorderLayout.CENTER);
    tabbedPane.addMouseMotionListener(this);
    // Connection Panel
    connectionPanel = new spx42ConnectPanel(databaseUtil);
    tabbedPane.addTab("CONNECTION", null, connectionPanel, null);
    tabbedPane.setEnabledAt(programTabs.TAB_CONNECT.ordinal(), true);
    // config Panel
    configPanel = new spx42ConfigPanel();
    tabbedPane.addTab("CONFIG", null, configPanel, null);
    tabbedPane.setEnabledAt(programTabs.TAB_CONFIG.ordinal(), true);
    // GASPANEL
    gasConfigPanel = new spx42GaslistEditPanel(databaseUtil);
    tabbedPane.addTab("GAS", null, gasConfigPanel, null);
    tabbedPane.setEnabledAt(programTabs.TAB_GASLIST.ordinal(), true);
    // Loglisten Panel
    logListPanel = new spx42LoglistPanel(this, databaseUtil);
    tabbedPane.addTab("LOG", null, logListPanel, null);
    tabbedPane.setEnabledAt(programTabs.TAB_LOGREAD.ordinal(), true);
    // Grafik Panel
    logGraphPanel = new spx42LogGraphPanel(databaseUtil);
    tabbedPane.addTab("GRAPH", null, logGraphPanel, null);
    tabbedPane.setEnabledAt(programTabs.TAB_LOGGRAPH.ordinal(), true);
    // import/export Panel
    fileManagerPanel = new spx42FileManagerPanel(this, databaseUtil);
    tabbedPane.addTab("EXPORT", null, fileManagerPanel, null);
    tabbedPane.setEnabledAt(programTabs.TAB_FILEMANAGER.ordinal(), true);
    // MEN
    JMenuBar menuBar = new JMenuBar();
    frmMainWindow.setJMenuBar(menuBar);
    mnFile = new JMenu(LangStrings.getString("MainCommGUI.mnFile.text")); //$NON-NLS-1$
    menuBar.add(mnFile);
    mntmExit = new JMenuItem(LangStrings.getString("MainCommGUI.mntmExit.text")); //$NON-NLS-1$
    mntmExit.setIcon(
            new ImageIcon(MainCommGUI.class.getResource("/de/dmarcini/submatix/pclogger/res/176.png")));
    mntmExit.setActionCommand("exit");
    mntmExit.addActionListener(this);
    mntmExit.addMouseMotionListener(this);
    mntmExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    mnFile.add(mntmExit);
    mnLanguages = new JMenu(LangStrings.getString("MainCommGUI.mnLanguages.text")); //$NON-NLS-1$
    mnLanguages.addMouseMotionListener(this);
    menuBar.add(mnLanguages);
    mnOptions = new JMenu(LangStrings.getString("MainCommGUI.mnOptions.text")); //$NON-NLS-1$
    mnOptions.addMouseMotionListener(this);
    menuBar.add(mnOptions);
    mntmOptions = new JMenuItem(LangStrings.getString("MainCommGUI.mntmOptions.text")); //$NON-NLS-1$
    mntmOptions.addMouseMotionListener(this);
    mntmOptions.addActionListener(this);
    mntmOptions.setActionCommand("set_propertys");
    mnOptions.add(mntmOptions);
    mnHelp = new JMenu(LangStrings.getString("MainCommGUI.mnHelp.text")); //$NON-NLS-1$
    mnHelp.addMouseMotionListener(this);
    menuBar.add(mnHelp);
    mntmHelp = new JMenuItem(LangStrings.getString("MainCommGUI.mntmHelp.text")); //$NON-NLS-1$
    mntmHelp.addActionListener(this);
    mntmHelp.setActionCommand("help");
    mntmHelp.addMouseMotionListener(this);
    mnHelp.add(mntmHelp);
    mntmInfo = new JMenuItem(LangStrings.getString("MainCommGUI.mntmInfo.text")); //$NON-NLS-1$
    mntmInfo.addActionListener(this);
    mntmInfo.setActionCommand("info");
    mntmInfo.addMouseMotionListener(this);
    mntmInfo.setIcon(
            new ImageIcon(MainCommGUI.class.getResource("/javax/swing/plaf/metal/icons/ocean/expanded.gif")));
    mntmInfo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_MASK));
    mnHelp.add(mntmInfo);
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Create a menu.//  ww w.ja  va 2s.  c om
 * @param menuBar the menubar
 * @param labelKey the label key to be localized
 * @param mneuKey the mneu key to be localized
 * @return returns a menu
 */
public static JMenu createLocalizedMenu(final JMenuBar menuBar, final String labelKey, final String mneuKey) {
    return menuBar.add(createLocalizedMenu(labelKey, mneuKey));
}

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

private JMenuBar initMenuBar() {
    JMenuBar menubar = new JMenuBar();
    {/*from ww w. ja  v  a  2s. co m*/
        JMenu menu = new JMenu("Synchronisation");
        {
            JMenuItem m = new JMenuItem("Kurse auswhlen");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    chooseCourses();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Automatische Synchronisation");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    showAutoSyncSettings();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Neue Dateien zeigen");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    showNewFiles();
                }
            });
            menu.add(m);
        }
        menubar.add(menu);
    }
    {
        JMenu menu = new JMenu("Einstellungen");
        {
            JMenuItem m = new JMenuItem("Speicherpfad ndern");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    changeBaseDir();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Speicherpfad ffnen");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openBaseDir();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Maximale Dateigre ndern");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    changeMaxFileSize();
                }
            });
            menu.add(m);
        }
        {
            final JCheckBoxMenuItem menuitem = new JCheckBoxMenuItem(
                    "Benachrichtigungen im Systemtray anzeigen");
            menuitem.setSelected(iliasProperties.isShowNotifications());
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    iliasProperties.setShowNotifications(!iliasProperties.isShowNotifications());
                    saveProperties(iliasProperties);
                    menuitem.setSelected(iliasProperties.isShowNotifications());
                }
            });
            menu.add(menuitem);
        }
        {
            menu.add(new JSeparator());
        }
        {
            JMenuItem m = new JMenuItem("Design ndern");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    changeLookAndFeel();
                }
            });
            menu.add(m);
        }
        {
            menu.add(new JSeparator());
        }
        {
            JMenuItem m = new JMenuItem("Server einstellen");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    chooseServer();
                }
            });
            menu.add(m);
        }
        menubar.add(menu);
    }
    {
        JMenu menu = new JMenu("Hilfe");
        {
            JMenuItem m = new JMenuItem("Fehler melden, Feedback geben");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openFeedbackPage();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Webseite");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openWebsite();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Android App");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openAndroidWebsite();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Info");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    showInfo();
                }
            });
            menu.add(m);
        }
        menubar.add(menu);
    }
    return menubar;
}

From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerFrame.java

/**
 * //  w  w w  .  j  av a 2s .  c o  m
 */
protected void buildUI() {
    SchemaLocalizerXMLHelper slxh = new SchemaLocalizerXMLHelper(schemaType, tableMgr);
    localizableIO = slxh;
    localizableIO.load(false);

    //stripToSingleLocale("pt", slxh);

    LocalizableStrFactory localizableStrFactory = new LocalizableStrFactory() {
        public LocalizableStrIFace create() {
            SpLocaleItemStr str = new SpLocaleItemStr();
            str.initialize();
            return str;
        }

        public LocalizableStrIFace create(String text, Locale locale) {
            return new SpLocaleItemStr(text, locale); // no initialize needed for this constructor
        }
    };

    LocalizerBasePanel.setLocalizableStrFactory(localizableStrFactory);
    SchemaLocalizerXMLHelper.setLocalizableStrFactory(localizableStrFactory);

    schemaLocPanel = new SchemaLocalizerPanel(null, dataObjFieldFormatMgrCache, uiFieldFormatterMgrCache,
            webLinkMgrCache, schemaType);
    schemaLocPanel.setLocalizableIO(localizableIO);
    schemaLocPanel.setStatusBar(statusBar);

    boolean useDisciplines = AppPreferences.getLocalPrefs().getBoolean("SCHEMA_DISP", false);
    schemaLocPanel.setUseDisciplines(useDisciplines);

    // rods - for now 
    //schemaLocPanel.setIncludeHiddenUI(true);
    schemaLocPanel.buildUI();
    schemaLocPanel.setHasChanged(localizableIO.didModelChangeDuringLoad());

    statusBar.setSectionText(1,
            schemaType == SpLocaleContainer.CORE_SCHEMA ? getResourceString("SchemaLocalizerFrame.FULL_SCHEMA") //$NON-NLS-1$
                    : getResourceString("SchemaLocalizerFrame.WB_SCHEMA")); //$NON-NLS-1$

    UIRegistry.setStatusBar(statusBar);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    String title = "File"; //$NON-NLS-1$
    String mneu = "F"; //$NON-NLS-1$
    JMenu fileMenu = UIHelper.createLocalizedMenu(menuBar, title, mneu);

    title = "Save"; //$NON-NLS-1$
    mneu = "S"; //$NON-NLS-1$
    JMenuItem saveMenuItem = UIHelper.createLocalizedMenuItem(fileMenu, title, mneu, "", false, //$NON-NLS-1$
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    write();
                }
            });
    saveMenuItem.setEnabled(false);

    title = "Export"; //$NON-NLS-1$
    mneu = "E"; //$NON-NLS-1$
    UIHelper.createLocalizedMenuItem(fileMenu, title, mneu, "", true, new ActionListener() //$NON-NLS-1$
    {
        public void actionPerformed(ActionEvent e) {
            export();
        }
    });

    title = "SchemaLocalizerFrame.ExportLOCALE"; //$NON-NLS-1$
    mneu = "SchemaLocalizerFrame.ExportLOCALEMnu"; //$NON-NLS-1$
    UIHelper.createLocalizedMenuItem(fileMenu, title, mneu, "", true, new ActionListener() //$NON-NLS-1$
    {
        public void actionPerformed(ActionEvent e) {
            exportSingleLocale();
        }
    });

    title = "Exit"; //$NON-NLS-1$
    mneu = "x"; //$NON-NLS-1$
    if (!UIHelper.isMacOS()) {
        fileMenu.addSeparator();

        UIHelper.createLocalizedMenuItem(fileMenu, title, mneu, "", true, new ActionListener() //$NON-NLS-1$
        {
            public void actionPerformed(ActionEvent e) {
                shutdown();
            }
        });
    }
    /*
    JMenu toolMenu = UIHelper.createMenu(menuBar, "Tools", "T");
    UIHelper.createMenuItem(toolMenu, "Create Resource Files", "C", "", true, new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
        createResourceFiles();
    }
    });
    */

    menuBar.add(SchemaI18NService.getInstance().createLocaleMenu(this, new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("locale")) //$NON-NLS-1$
            {
                schemaLocPanel.localeChanged((Locale) evt.getNewValue());
                statusBar.setSectionText(0, SchemaI18NService.getCurrentLocale().getDisplayName());
            }
        }
    }));

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    setSize(800, 600);

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(schemaLocPanel, BorderLayout.CENTER);
    mainPanel.add(statusBar, BorderLayout.SOUTH);

    mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    setContentPane(mainPanel);

    statusBar.setSectionText(0, SchemaI18NService.getCurrentLocale().getDisplayName());

    schemaLocPanel.setSaveMenuItem(saveMenuItem);

    schemaLocPanel.getContainerList().setEnabled(true);

    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    localPrefs.setDirPath(UIRegistry.getAppDataDir());

    ImageIcon helpIcon = IconManager.getIcon("AppIcon", IconSize.Std16); //$NON-NLS-1$
    HelpMgr.initializeHelp("SpecifyHelp", helpIcon.getImage()); //$NON-NLS-1$

    AppPrefsCache.setUseLocalOnly(true);
    SpecifyAppPrefs.loadColorAndFormatPrefs();

    if (localizableIO.didModelChangeDuringLoad()) {
        saveMenuItem.setEnabled(true);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame(getResourceString("SchemaLocalizerFrame.CHG_TO_SCHEMA")); //$NON-NLS-1$
                frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

                JTextPane tp = new JTextPane();
                JScrollPane js = new JScrollPane();
                js.getViewport().add(tp);

                tp.setContentType("text/html");
                tp.setText(((SchemaLocalizerXMLHelper) localizableIO).getChangesBuffer());

                frame.setContentPane(js);
                frame.pack();
                frame.setSize(400, 500);
                frame.setVisible(true);
            }
        });
    }
}