Example usage for javax.swing JComboBox setBounds

List of usage examples for javax.swing JComboBox setBounds

Introduction

In this page you can find the example usage for javax.swing JComboBox setBounds.

Prototype

public void setBounds(int x, int y, int width, int height) 

Source Link

Document

Moves and resizes this component.

Usage

From source file:hspc.submissionsprogram.AppDisplay.java

AppDisplay() {
    this.setTitle("Dominion High School Programming Contest");
    this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    this.setResizable(false);

    WindowListener exitListener = new WindowAdapter() {
        @Override/* w  w  w .j  a  va  2 s .c o  m*/
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    this.addWindowListener(exitListener);

    JTabbedPane pane = new JTabbedPane();
    this.add(pane);

    JPanel submitPanel = new JPanel(null);
    submitPanel.setPreferredSize(new Dimension(500, 500));

    UIManager.put("FileChooser.readOnly", true);
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setBounds(0, 0, 500, 350);
    fileChooser.setVisible(true);
    FileNameExtensionFilter javaFilter = new FileNameExtensionFilter("Java files (*.java)", "java");
    fileChooser.setFileFilter(javaFilter);
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setControlButtonsAreShown(false);
    submitPanel.add(fileChooser);

    JSeparator separator1 = new JSeparator();
    separator1.setBounds(12, 350, 476, 2);
    separator1.setForeground(new Color(122, 138, 152));
    submitPanel.add(separator1);

    JLabel problemChooserLabel = new JLabel("Problem:");
    problemChooserLabel.setBounds(12, 360, 74, 25);
    submitPanel.add(problemChooserLabel);

    String[] listOfProblems = Main.Configuration.get("problem_names")
            .split(Main.Configuration.get("name_delimiter"));
    JComboBox problems = new JComboBox<>(listOfProblems);
    problems.setBounds(96, 360, 393, 25);
    submitPanel.add(problems);

    JButton submit = new JButton("Submit");
    submit.setBounds(170, 458, 160, 30);
    submit.addActionListener(e -> {
        try {
            File file = fileChooser.getSelectedFile();
            try {
                CloseableHttpClient httpClient = HttpClients.createDefault();
                HttpPost uploadFile = new HttpPost(Main.Configuration.get("submit_url"));

                MultipartEntityBuilder builder = MultipartEntityBuilder.create();
                builder.addTextBody("accountID", Main.accountID, ContentType.TEXT_PLAIN);
                builder.addTextBody("problem", String.valueOf(problems.getSelectedItem()),
                        ContentType.TEXT_PLAIN);
                builder.addBinaryBody("submission", file, ContentType.APPLICATION_OCTET_STREAM, file.getName());
                HttpEntity multipart = builder.build();

                uploadFile.setEntity(multipart);

                CloseableHttpResponse response = httpClient.execute(uploadFile);
                HttpEntity responseEntity = response.getEntity();
                String inputLine;
                BufferedReader br = new BufferedReader(new InputStreamReader(responseEntity.getContent()));
                try {
                    if ((inputLine = br.readLine()) != null) {
                        int rowIndex = Integer.parseInt(inputLine);
                        new ResultWatcher(rowIndex);
                    }
                    br.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(this, "No file selected.\nPlease select a java file.", "Error",
                    JOptionPane.WARNING_MESSAGE);
        }
    });
    submitPanel.add(submit);

    JPanel clarificationsPanel = new JPanel(null);
    clarificationsPanel.setPreferredSize(new Dimension(500, 500));

    cList = new JList<>();
    cList.setBounds(12, 12, 476, 200);
    cList.setBorder(new CompoundBorder(BorderFactory.createLineBorder(new Color(122, 138, 152)),
            BorderFactory.createEmptyBorder(8, 8, 8, 8)));
    cList.setBackground(new Color(254, 254, 255));
    clarificationsPanel.add(cList);

    JButton viewC = new JButton("View");
    viewC.setBounds(12, 224, 232, 25);
    viewC.addActionListener(e -> {
        if (cList.getSelectedIndex() != -1) {
            int id = Integer.parseInt(cList.getSelectedValue().split("\\.")[0]);
            clarificationDatas.stream().filter(data -> data.getId() == id).forEach(
                    data -> new ClarificationDisplay(data.getProblem(), data.getText(), data.getResponse()));
        }
    });
    clarificationsPanel.add(viewC);

    JButton refreshC = new JButton("Refresh");
    refreshC.setBounds(256, 224, 232, 25);
    refreshC.addActionListener(e -> updateCList(true));
    clarificationsPanel.add(refreshC);

    JSeparator separator2 = new JSeparator();
    separator2.setBounds(12, 261, 476, 2);
    separator2.setForeground(new Color(122, 138, 152));
    clarificationsPanel.add(separator2);

    JLabel problemChooserLabelC = new JLabel("Problem:");
    problemChooserLabelC.setBounds(12, 273, 74, 25);
    clarificationsPanel.add(problemChooserLabelC);

    JComboBox problemsC = new JComboBox<>(listOfProblems);
    problemsC.setBounds(96, 273, 393, 25);
    clarificationsPanel.add(problemsC);

    JTextArea textAreaC = new JTextArea();
    textAreaC.setLineWrap(true);
    textAreaC.setWrapStyleWord(true);
    textAreaC.setBorder(new CompoundBorder(BorderFactory.createLineBorder(new Color(122, 138, 152)),
            BorderFactory.createEmptyBorder(8, 8, 8, 8)));
    textAreaC.setBackground(new Color(254, 254, 255));

    JScrollPane areaScrollPane = new JScrollPane(textAreaC);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    areaScrollPane.setBounds(12, 312, 477, 134);
    clarificationsPanel.add(areaScrollPane);

    JButton submitC = new JButton("Submit Clarification");
    submitC.setBounds(170, 458, 160, 30);
    submitC.addActionListener(e -> {
        if (textAreaC.getText().length() > 2048) {
            JOptionPane.showMessageDialog(this,
                    "Clarification body is too long.\nMaximum of 2048 characters allowed.", "Error",
                    JOptionPane.WARNING_MESSAGE);
        } else if (textAreaC.getText().length() < 20) {
            JOptionPane.showMessageDialog(this,
                    "Clarification body is too short.\nClarifications must be at least 20 characters, but no more than 2048.",
                    "Error", JOptionPane.WARNING_MESSAGE);
        } else {
            Connection conn = null;
            PreparedStatement stmt = null;
            try {
                Class.forName(JDBC_DRIVER);

                conn = DriverManager.getConnection(Main.Configuration.get("jdbc_mysql_address"),
                        Main.Configuration.get("mysql_user"), Main.Configuration.get("mysql_pass"));

                String sql = "INSERT INTO clarifications (team, problem, text) VALUES (?, ?, ?)";
                stmt = conn.prepareStatement(sql);

                stmt.setInt(1, Integer.parseInt(String.valueOf(Main.accountID)));
                stmt.setString(2, String.valueOf(problemsC.getSelectedItem()));
                stmt.setString(3, String.valueOf(textAreaC.getText()));

                textAreaC.setText("");

                stmt.executeUpdate();

                stmt.close();
                conn.close();

                updateCList(false);
            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                try {
                    if (stmt != null) {
                        stmt.close();
                    }
                } catch (Exception ex2) {
                    ex2.printStackTrace();
                }
                try {
                    if (conn != null) {
                        conn.close();
                    }
                } catch (Exception ex2) {
                    ex2.printStackTrace();
                }
            }
        }
    });
    clarificationsPanel.add(submitC);

    pane.addTab("Submit", submitPanel);
    pane.addTab("Clarifications", clarificationsPanel);

    Timer timer = new Timer();
    TimerTask updateTask = new TimerTask() {
        @Override
        public void run() {
            updateCList(false);
        }
    };
    timer.schedule(updateTask, 10000, 10000);

    updateCList(false);

    this.pack();
    this.setLocationRelativeTo(null);
    this.setVisible(true);
}

From source file:App.java

/**
 * Initialize the contents of the frame.
 *//*from www  .j a v  a2 s.c  o  m*/
private void initialize() {

    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(1000, 750);
    frame.getContentPane().setLayout(null);

    FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "jpeg", "png");
    fc = new JFileChooser();
    fc.setFileFilter(filter);
    frame.getContentPane().add(fc);

    stepOne = new JLabel("");
    stepOne.setToolTipText("here comes something");
    stepOne.setIcon(new ImageIcon("img/stepOne.png"));
    stepOne.setBounds(266, -4, 67, 49);
    frame.getContentPane().add(stepOne);

    btnBrowse = new JButton("Browse");
    btnBrowse.setBounds(66, 6, 117, 29);
    frame.getContentPane().add(btnBrowse);

    btnTurnWebcamOn = new JButton("Take a picture with webcam");
    btnTurnWebcamOn.setBounds(66, 34, 212, 29);
    frame.getContentPane().add(btnTurnWebcamOn);

    JButton btnTakePictureWithWebcam = new JButton("Take a picture");
    btnTakePictureWithWebcam.setBounds(430, 324, 117, 29);
    frame.getContentPane().add(btnTakePictureWithWebcam);
    btnTakePictureWithWebcam.setVisible(false);

    JButton btnCancel = new JButton("Cancel");
    btnCancel.setBounds(542, 324, 117, 29);
    frame.getContentPane().add(btnCancel);
    btnCancel.setVisible(false);

    JButton btnSaveImage = new JButton("Save image");
    btnSaveImage.setBounds(497, 357, 117, 29);
    frame.getContentPane().add(btnSaveImage);
    btnSaveImage.setVisible(false);

    urlField = new JTextField();
    urlField.setBounds(66, 67, 220, 26);
    frame.getContentPane().add(urlField);
    urlField.setColumns(10);

    originalImageLabel = new JLabel();
    originalImageLabel.setHorizontalAlignment(SwingConstants.CENTER);
    originalImageLabel.setBounds(33, 98, 300, 300);
    frame.getContentPane().add(originalImageLabel);

    stepTwo = new JLabel("");
    stepTwo.setToolTipText("here comes something else");
    stepTwo.setIcon(new ImageIcon("img/stepTwo.png"));
    stepTwo.setBounds(266, 413, 67, 49);
    frame.getContentPane().add(stepTwo);

    btnAnalyse = new JButton("Analyse image");
    btnAnalyse.setBounds(68, 423, 196, 29);
    frame.getContentPane().add(btnAnalyse);

    tagsField = new JTextArea();
    tagsField.setBounds(23, 479, 102, 89);
    tagsField.setLineWrap(true);
    tagsField.setWrapStyleWord(true);
    frame.getContentPane().add(tagsField);
    tagsField.setColumns(10);

    lblTags = new JLabel("Tags:");
    lblTags.setBounds(46, 451, 61, 16);
    frame.getContentPane().add(lblTags);

    descriptionField = new JTextArea();
    descriptionField.setLineWrap(true);
    descriptionField.setWrapStyleWord(true);
    descriptionField.setBounds(137, 479, 187, 89);
    frame.getContentPane().add(descriptionField);
    descriptionField.setColumns(10);

    lblDescription = new JLabel("Description:");
    lblDescription.setBounds(163, 451, 77, 16);
    frame.getContentPane().add(lblDescription);

    stepThree = new JLabel("");
    stepThree.setToolTipText("here comes something different");
    stepThree.setIcon(new ImageIcon("img/stepThree.png"));
    stepThree.setBounds(266, 685, 67, 49);
    frame.getContentPane().add(stepThree);

    JLabel lblImageType = new JLabel("Image type");
    lblImageType.setBounds(23, 580, 102, 16);
    frame.getContentPane().add(lblImageType);

    String[] imageTypes = { "unspecified", "AnimategGif", "Clipart", "Line", "Photo" };
    JComboBox imageTypeBox = new JComboBox(imageTypes);
    imageTypeBox.setBounds(137, 580, 187, 23);
    frame.getContentPane().add(imageTypeBox);

    JLabel lblSizeType = new JLabel("Size");
    lblSizeType.setBounds(23, 608, 102, 16);
    frame.getContentPane().add(lblSizeType);

    String[] sizeTypes = { "unspecified", "Small", "Medium", "Large", "Wallpaper" };
    JComboBox sizeBox = new JComboBox(sizeTypes);
    sizeBox.setBounds(137, 608, 187, 23);
    frame.getContentPane().add(sizeBox);

    JLabel lblLicenseType = new JLabel("License");
    lblLicenseType.setBounds(23, 636, 102, 16);
    frame.getContentPane().add(lblLicenseType);

    String[] licenseTypes = { "unspecified", "Public", "Share", "ShareCommercially", "Modify" };
    JComboBox licenseBox = new JComboBox(licenseTypes);
    licenseBox.setBounds(137, 636, 187, 23);
    frame.getContentPane().add(licenseBox);

    JLabel lblSafeSearchType = new JLabel("Safe search");
    lblSafeSearchType.setBounds(23, 664, 102, 16);
    frame.getContentPane().add(lblSafeSearchType);

    String[] safeSearchTypes = { "Strict", "Moderate", "Off" };
    JComboBox safeSearchBox = new JComboBox(safeSearchTypes);
    safeSearchBox.setBounds(137, 664, 187, 23);
    frame.getContentPane().add(safeSearchBox);

    btnSearchForSimilar = new JButton("Search for similar images");
    btnSearchForSimilar.setVisible(true);
    btnSearchForSimilar.setBounds(66, 695, 189, 29);
    frame.getContentPane().add(btnSearchForSimilar);

    // label to try urls to display images, not shown on the main frame
    labelTryLinks = new JLabel();
    labelTryLinks.setBounds(0, 0, 100, 100);

    foundImagesLabel1 = new JLabel();
    foundImagesLabel1.setHorizontalAlignment(SwingConstants.CENTER);
    foundImagesLabel1.setBounds(400, 49, 250, 250);
    frame.getContentPane().add(foundImagesLabel1);

    foundImagesLabel2 = new JLabel();
    foundImagesLabel2.setHorizontalAlignment(SwingConstants.CENTER);
    foundImagesLabel2.setBounds(400, 313, 250, 250);
    frame.getContentPane().add(foundImagesLabel2);

    foundImagesLabel3 = new JLabel();
    foundImagesLabel3.setHorizontalAlignment(SwingConstants.CENTER);
    foundImagesLabel3.setBounds(673, 49, 250, 250);
    frame.getContentPane().add(foundImagesLabel3);

    foundImagesLabel4 = new JLabel();
    foundImagesLabel4.setHorizontalAlignment(SwingConstants.CENTER);
    foundImagesLabel4.setBounds(673, 313, 250, 250);
    frame.getContentPane().add(foundImagesLabel4);

    progressBar = new JProgressBar();
    progressBar.setIndeterminate(true);
    progressBar.setStringPainted(true);
    progressBar.setBounds(440, 602, 440, 29);

    Border border = BorderFactory
            .createTitledBorder("We are checking every image, pixel by pixel, it may take a while...");
    progressBar.setBorder(border);
    frame.getContentPane().add(progressBar);
    progressBar.setVisible(false);

    btnHelp = new JButton("");
    btnHelp.setBorderPainted(false);
    ImageIcon btnIcon = new ImageIcon("img/helpRed.png");
    btnHelp.setIcon(btnIcon);
    btnHelp.setBounds(917, 4, 77, 59);
    frame.getContentPane().add(btnHelp);

    // all action listeners
    btnBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
                openFilechooser();
            }
        }
    });

    btnTurnWebcamOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            setAllFoundImagesLabelsAndPreviewsToNull();
            btnTakePictureWithWebcam.setVisible(true);
            btnCancel.setVisible(true);
            turnCameraOn();
        }
    });

    btnTakePictureWithWebcam.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            btnSaveImage.setVisible(true);
            // take a photo with web camera
            imageWebcam = webcam.getImage();
            originalImage = imageWebcam;

            // to mirror the image we create a temporary file, flip it
            // horizontally and then delete

            // get user's name to store file in the user directory
            String user = System.getProperty("user.home");
            String fileName = user + "/webCamPhoto.jpg";
            File newFile = new File(fileName);

            try {
                ImageIO.write(originalImage, "jpg", newFile);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            try {
                originalImage = (BufferedImage) ImageIO.read(newFile);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            newFile.delete();
            originalImage = mirrorImage(originalImage);
            icon = scaleBufferedImage(originalImage, originalImageLabel);
            originalImageLabel.setIcon(icon);
        }
    });

    btnSaveImage.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                try {

                    file = fc.getSelectedFile();
                    File output = new File(file.toString());
                    // check if image already exists
                    if (output.exists()) {
                        int response = JOptionPane.showConfirmDialog(null, //
                                "Do you want to replace the existing file?", //
                                "Confirm", JOptionPane.YES_NO_OPTION, //
                                JOptionPane.QUESTION_MESSAGE);
                        if (response != JOptionPane.YES_OPTION) {
                            return;
                        }
                    }
                    ImageIO.write(toBufferedImage(originalImage), "jpg", output);
                    System.out.println("Your image has been saved in the folder " + file.getPath());
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
    });

    btnCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            btnTakePictureWithWebcam.setVisible(false);
            btnCancel.setVisible(false);
            btnSaveImage.setVisible(false);
            webcam.close();
            panel.setVisible(false);
        }
    });

    urlField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (urlField.getText().length() > 0) {
                String linkNew = urlField.getText();
                getImageFromHttp(linkNew, originalImageLabel);
                originalImage = imageResponses;
            }
        }
    });

    btnAnalyse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            Token computerVisionToken = new Token();
            String computerVisionTokenFileName = "APIToken.txt";

            try {
                computerVisionImageToken = computerVisionToken.getApiToken(computerVisionTokenFileName);
                try {
                    analyse();
                } catch (NullPointerException e1) {
                    // if user clicks on "analyze" button without uploading
                    // image or posts a broken link
                    JOptionPane.showMessageDialog(null, "Please choose an image");
                    e1.printStackTrace();
                }
            } catch (NullPointerException e1) {
                e1.printStackTrace();
            }
        }
    });

    btnSearchForSimilar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            // clear labels in case there were results of previous search
            setAllFoundImagesLabelsAndPreviewsToNull();

            System.out.println("==========================================");
            System.out.println("new search");
            System.out.println("==========================================");

            Token bingImageToken = new Token();
            String bingImageTokenFileName = "SearchApiToken.txt";

            bingToken = bingImageToken.getApiToken(bingImageTokenFileName);

            // in case user edited description or tags, update it and
            // replace new line character, spaces and breaks with %20
            text = descriptionField.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20");
            String tagsString = tagsField.getText().replace(" ", "%20").replace("\r", "%20").replace("\n",
                    "%20");

            imageTypeString = imageTypeBox.getSelectedItem().toString();
            sizeTypeString = sizeBox.getSelectedItem().toString();
            licenseTypeString = licenseBox.getSelectedItem().toString();
            safeSearchTypeString = safeSearchBox.getSelectedItem().toString();

            searchParameters = tagsString + text;
            System.out.println("search parameters: " + searchParameters);

            if (searchParameters.length() != 0) {

                // add new thread for searching, so that progress bar and
                // searching could run simultaneously
                Thread t1 = new Thread(new Runnable() {
                    @Override
                    public void run() {

                        progressBar.setVisible(true);
                        searchForSimilarImages(searchParameters, imageTypeString, sizeTypeString,
                                licenseTypeString, safeSearchTypeString);
                    }

                });
                // start searching for similar images in a separate thread
                t1.start();
            } else {
                JOptionPane.showMessageDialog(null,
                        "Please choose first an image to analyse or insert search parameters");
            }
        }
    });

    foundImagesLabel1.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (foundImagesLabel1.getIcon() != null) {
                if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    saveFileChooser(firstImageUrl);
                }
            }
        }
    });

    foundImagesLabel2.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (foundImagesLabel2.getIcon() != null) {
                if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    saveFileChooser(secondImageUrl);
                }
            }
        }
    });

    foundImagesLabel3.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (foundImagesLabel3.getIcon() != null) {
                if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    saveFileChooser(thirdImageUrl);
                }
            }
        }
    });

    foundImagesLabel4.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (foundImagesLabel4.getIcon() != null) {
                if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    saveFileChooser(fourthImageUrl);
                }
            }
        }
    });

    btnHelp.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // TODO write help
            HelpFrame help = new HelpFrame();
        }
    });
}

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);//  w ww  . 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:it.imtech.metadata.MetaUtility.java

/**
 * Metodo adibito alla creazione dinamica ricorsiva dell'interfaccia dei
 * metadati//www. j av  a  2s  .c  o  m
 *
 * @param submetadatas Map contente i metadati e i sottolivelli di metadati
 * @param vocabularies Map contenente i dati contenuti nel file xml
 * vocabulary.xml
 * @param parent Jpanel nel quale devono venir inseriti i metadati
 * @param level Livello corrente
 */
public void create_metadata_view(Map<Object, Metadata> submetadatas, JPanel parent, int level,
        final String panelname) throws Exception {
    ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader);
    int lenght = submetadatas.size();
    int labelwidth = 220;
    int i = 0;
    JButton addcontribute = null;

    for (Map.Entry<Object, Metadata> kv : submetadatas.entrySet()) {
        ArrayList<Component> tabobjects = new ArrayList<Component>();

        if (kv.getValue().MID == 17 || kv.getValue().MID == 23 || kv.getValue().MID == 18
                || kv.getValue().MID == 137) {
            continue;
        }

        //Crea un jpanel nuovo e fa appen su parent
        JPanel innerPanel = new JPanel(new MigLayout("fillx, insets 1 1 1 1"));
        innerPanel.setName("pannello" + level + i);

        i++;
        String datatype = kv.getValue().datatype.toString();

        if (kv.getValue().MID == 45) {
            JPanel choice = new JPanel(new MigLayout());

            JComboBox combo = addClassificationChoice(choice, kv.getValue().sequence, panelname);

            JLabel labelc = new JLabel();
            labelc.setText(Utility.getBundleString("selectclassif", bundle));
            labelc.setPreferredSize(new Dimension(100, 20));

            choice.add(labelc);

            findLastClassification(panelname);
            if (last_classification != 0 && classificationRemoveButton == null) {
                logger.info("Removing last clasification");
                classificationRemoveButton = new JButton("-");

                classificationRemoveButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent event) {
                        BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        removeClassificationToMetadata(panelname);
                        BookImporter.getInstance().refreshMetadataTab(false, panelname);
                        findLastClassification(panelname); //update last_classification
                        BookImporter.getInstance().setCursor(null);
                    }
                });
                if (Integer.parseInt(kv.getValue().sequence) == last_classification) {
                    choice.add(classificationRemoveButton, "wrap, width :50:");
                }
            }

            if (classificationAddButton == null) {
                logger.info("Adding a new classification");
                choice.add(combo, "width 100:600:600");

                classificationAddButton = new JButton("+");

                classificationAddButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent event) {
                        BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        addClassificationToMetadata(panelname);
                        BookImporter.getInstance().refreshMetadataTab(false, panelname);
                        BookImporter.getInstance().setCursor(null);
                    }
                });

                choice.add(classificationAddButton, "width :50:");
            } else {
                //choice.add(combo, "wrap,width 100:700:700");
                choice.add(combo, "width 100:700:700");
                if (Integer.parseInt(kv.getValue().sequence) == last_classification) {
                    choice.add(classificationRemoveButton, "wrap, width :50");
                }
            }
            parent.add(choice, "wrap,width 100:700:700");
            classificationMID = kv.getValue().MID;

            innerPanel.setName(panelname + "---ImPannelloClassif---" + kv.getValue().sequence);
            try {

                addClassification(innerPanel, classificationMID, kv.getValue().sequence, panelname);
            } catch (Exception ex) {
                logger.error("Errore nell'aggiunta delle classificazioni");
            }
            parent.add(innerPanel, "wrap, growx");
            BookImporter.policy.addIndexedComponent(combo);

            continue;
        }

        if (datatype.equals("Node")) {
            JLabel label = new JLabel();
            label.setText(kv.getValue().description);
            label.setPreferredSize(new Dimension(100, 20));

            int size = 16 - (level * 2);
            Font myFont = new Font("MS Sans Serif", Font.PLAIN, size);
            label.setFont(myFont);

            if (Integer.toString(kv.getValue().MID).equals("11")) {
                JPanel temppanel = new JPanel(new MigLayout());

                //update last_contribute
                findLastContribute(panelname);

                if (last_contribute != 0 && removeContribute == null) {
                    logger.info("Removing last contribute");
                    removeContribute = new JButton("-");

                    removeContribute.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent event) {
                            BookImporter.getInstance()
                                    .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                            removeContributorToMetadata(panelname);
                            BookImporter.getInstance().refreshMetadataTab(false, panelname);
                            BookImporter.getInstance().setCursor(null);
                        }
                    });

                    if (!kv.getValue().sequence.equals("")) {
                        if (Integer.parseInt(kv.getValue().sequence) == last_contribute) {
                            innerPanel.add(removeContribute, "width :50:");
                        }
                    }
                }

                if (addcontribute == null) {
                    logger.info("Adding a new contribute");
                    addcontribute = new JButton("+");

                    addcontribute.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent event) {
                            BookImporter.getInstance()
                                    .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                            addContributorToMetadata(panelname);
                            BookImporter.getInstance().refreshMetadataTab(false, panelname);
                            BookImporter.getInstance().setCursor(null);
                        }
                    });

                    temppanel.add(label, " width :200:");
                    temppanel.add(addcontribute, "width :50:");
                    innerPanel.add(temppanel, "wrap, growx");
                } else {
                    temppanel.add(label, " width :200:");
                    findLastContribute(panelname);
                    if (!kv.getValue().sequence.equals("")) {
                        if (Integer.parseInt(kv.getValue().sequence) == last_contribute) {
                            temppanel.add(removeContribute, "width :50:");
                        }
                    }
                    innerPanel.add(temppanel, "wrap, growx");
                }
            } else if (Integer.toString(kv.getValue().MID).equals("115")) {
                logger.info("Devo gestire una provenience!");
            }
        } else {
            String title = "";

            if (kv.getValue().mandatory.equals("Y") || kv.getValue().MID == 14 || kv.getValue().MID == 15) {
                title = kv.getValue().description + " *";
            } else {
                title = kv.getValue().description;
            }

            innerPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title,
                    TitledBorder.LEFT, TitledBorder.TOP));

            if (datatype.equals("Vocabulary")) {
                TreeMap<String, String> entryCombo = new TreeMap<String, String>();
                int index = 0;
                String selected = null;

                if (!Integer.toString(kv.getValue().MID).equals("8"))
                    entryCombo.put(Utility.getBundleString("comboselect", bundle),
                            Utility.getBundleString("comboselect", bundle));

                for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) {
                    String tempmid = Integer.toString(kv.getValue().MID);

                    if (Integer.toString(kv.getValue().MID_parent).equals("11")
                            || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                        String[] testmid = tempmid.split("---");
                        tempmid = testmid[0];
                    }

                    if (vc.getKey().equals(tempmid)) {
                        TreeMap<String, VocEntry> iEntry = vc.getValue();

                        for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) {
                            entryCombo.put(ivc.getValue().description, ivc.getValue().ID);
                            if (kv.getValue().value != null) {
                                if (kv.getValue().value.equals(ivc.getValue().ID)) {
                                    selected = ivc.getValue().ID;
                                }
                            }
                            index++;
                        }
                    }
                }

                final ComboMapImpl model = new ComboMapImpl();
                model.setVocabularyCombo(true);
                model.putAll(entryCombo);

                final JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                if (Integer.toString(kv.getValue().MID_parent).equals("11")
                        || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                    voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence);
                } else {
                    voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                }

                if (Integer.toString(kv.getValue().MID).equals("8") && selected == null)
                    selected = "44";

                selected = (selected == null) ? Utility.getBundleString("comboselect", bundle) : selected;

                for (int k = 0; k < voc.getItemCount(); k++) {
                    Map.Entry<String, String> el = (Map.Entry<String, String>) voc.getItemAt(k);
                    if (el.getValue().equals(selected))
                        voc.setSelectedIndex(k);
                }

                voc.setPreferredSize(new Dimension(150, 30));
                innerPanel.add(voc, "wrap, width :400:");
                tabobjects.add(voc);
            } else if (datatype.equals("CharacterString") || datatype.equals("GPS")) {
                final JTextArea textField = new javax.swing.JTextArea();

                if (Integer.toString(kv.getValue().MID_parent).equals("11")
                        || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                    textField.setName(
                            "MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence);
                } else {
                    textField.setName("MID_" + Integer.toString(kv.getValue().MID));
                }

                textField.setPreferredSize(new Dimension(230, 0));
                textField.setText(kv.getValue().value);
                textField.setLineWrap(true);
                textField.setWrapStyleWord(true);

                innerPanel.add(textField, "wrap, width :300:");

                textField.addKeyListener(new KeyAdapter() {
                    @Override
                    public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode() == KeyEvent.VK_TAB) {
                            if (e.getModifiers() > 0) {
                                textField.transferFocusBackward();
                            } else {
                                textField.transferFocus();
                            }
                            e.consume();
                        }
                    }
                });

                tabobjects.add(textField);
            } else if (datatype.equals("LangString")) {
                JScrollPane inner_scroll = new javax.swing.JScrollPane();
                inner_scroll.setHorizontalScrollBarPolicy(
                        javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
                inner_scroll.setVerticalScrollBarPolicy(
                        javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
                inner_scroll.setPreferredSize(new Dimension(240, 80));
                inner_scroll.setName("langStringScroll");
                final JTextArea jTextArea1 = new javax.swing.JTextArea();
                jTextArea1.setName("MID_" + Integer.toString(kv.getValue().MID));
                jTextArea1.setText(kv.getValue().value);

                jTextArea1.setSize(new Dimension(350, 70));
                jTextArea1.setLineWrap(true);
                jTextArea1.setWrapStyleWord(true);

                inner_scroll.setViewportView(jTextArea1);
                innerPanel.add(inner_scroll, "width :300:");

                //Add combo language box
                JComboBox voc = getComboLangBox(kv.getValue().language);
                voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "_lang");

                voc.setPreferredSize(new Dimension(200, 20));
                innerPanel.add(voc, "wrap, width :300:");

                jTextArea1.addKeyListener(new KeyAdapter() {
                    @Override
                    public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode() == KeyEvent.VK_TAB) {
                            if (e.getModifiers() > 0) {
                                jTextArea1.transferFocusBackward();
                            } else {
                                jTextArea1.transferFocus();
                            }
                            e.consume();
                        }
                    }
                });
                tabobjects.add(jTextArea1);
                tabobjects.add(voc);
            } else if (datatype.equals("Language")) {
                final JComboBox voc = getComboLangBox(kv.getValue().value);
                voc.setName("MID_" + Integer.toString(kv.getValue().MID));

                voc.setPreferredSize(new Dimension(150, 20));
                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :500:");

                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);

            } else if (datatype.equals("Boolean")) {
                int selected = 0;
                TreeMap bin = new TreeMap<String, String>();
                bin.put("yes", Utility.getBundleString("voc1", bundle));
                bin.put("no", Utility.getBundleString("voc2", bundle));

                if (kv.getValue().value == null) {
                    switch (kv.getValue().MID) {
                    case 35:
                        selected = 0;
                        break;
                    case 36:
                        selected = 1;
                        break;
                    }
                } else if (kv.getValue().value.equals("yes")) {
                    selected = 1;
                } else {
                    selected = 0;
                }

                final ComboMapImpl model = new ComboMapImpl();
                model.putAll(bin);

                final JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                voc.setSelectedIndex(selected);

                voc.setPreferredSize(new Dimension(150, 20));
                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :300:");
                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);
            } else if (datatype.equals("License")) {
                String selectedIndex = null;
                int vindex = 0;
                int defaultIndex = 0;

                TreeMap<String, String> entryCombo = new TreeMap<String, String>();

                for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) {
                    if (vc.getKey().equals(Integer.toString(kv.getValue().MID))) {
                        TreeMap<String, VocEntry> iEntry = vc.getValue();

                        for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) {
                            entryCombo.put(ivc.getValue().description, ivc.getValue().ID);

                            if (ivc.getValue().ID.equals("1"))
                                defaultIndex = vindex;

                            if (kv.getValue().value != null) {
                                if (ivc.getValue().ID.equals(kv.getValue().value)) {
                                    selectedIndex = Integer.toString(vindex);
                                }
                            }
                            vindex++;
                        }
                    }
                }

                if (selectedIndex == null)
                    selectedIndex = Integer.toString(defaultIndex);

                ComboMapImpl model = new ComboMapImpl();
                model.putAll(entryCombo);
                model.setVocabularyCombo(true);

                JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                voc.setSelectedIndex(Integer.parseInt(selectedIndex));
                voc.setPreferredSize(new Dimension(150, 20));

                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :500:");
                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);
            } else if (datatype.equals("DateTime")) {
                //final JXDatePicker datePicker = new JXDatePicker();
                JDateChooser datePicker = new JDateChooser();
                datePicker.setName("MID_" + Integer.toString(kv.getValue().MID));

                JPanel test = new JPanel(new MigLayout());
                JLabel lbefore = new JLabel(Utility.getBundleString("beforechristlabel", bundle));
                JCheckBox beforechrist = new JCheckBox();
                beforechrist.setName("MID_" + Integer.toString(kv.getValue().MID) + "_check");

                if (kv.getValue().value != null) {
                    try {
                        if (kv.getValue().value.charAt(0) == '-') {
                            beforechrist.setSelected(true);
                        }

                        Date date1 = new Date();
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        if (kv.getValue().value.charAt(0) == '-') {
                            date1 = sdf.parse(adjustDate(kv.getValue().value));
                        } else {
                            date1 = sdf.parse(kv.getValue().value);
                        }
                        datePicker.setDate(date1);
                    } catch (Exception e) {
                        //Console.WriteLine("ERROR import date:" + ex.Message);
                    }
                }

                test.add(datePicker, "width :200:");
                test.add(lbefore, "gapleft 30");
                test.add(beforechrist, "wrap");

                innerPanel.add(test, "wrap");
            }
        }

        //Recursive call
        create_metadata_view(kv.getValue().submetadatas, innerPanel, level + 1, panelname);

        if (kv.getValue().editable.equals("Y")
                || (datatype.equals("Node") && kv.getValue().hidden.equals("0"))) {
            parent.add(innerPanel, "wrap, growx");

            for (Component tabobject : tabobjects) {
                BookImporter.policy.addIndexedComponent(tabobject);
            }
        }
    }
}