Example usage for javax.swing JPanel setOpaque

List of usage examples for javax.swing JPanel setOpaque

Introduction

In this page you can find the example usage for javax.swing JPanel setOpaque.

Prototype

@BeanProperty(expert = true, description = "The component's opacity")
public void setOpaque(boolean isOpaque) 

Source Link

Document

If true the component paints every pixel within its bounds.

Usage

From source file:es.emergya.ui.plugins.admin.aux1.SummaryAction.java

@SuppressWarnings("unchecked")
protected JFrame generateUrlDialog(final String label_cabecera, final String label_pie,
        final String centered_label, final String titulo, final Object[] left_items, final Object[] right_items,
        final String left_label, final String right_label, final SaveOrUpdateAction guardar, final Icon icono,
        final String title, final Boolean habilitada, final Boolean tipoCapa, final String url) {
    int width_listas = SummaryAction.PANEL_WIDTH;
    if (left_items == null)
        width_listas = width_listas * 3 / 2;
    final Dimension dimensionList = new Dimension(width_listas, SummaryAction.HEIGHT);
    final Dimension dimensionPanel = new Dimension(SummaryAction.PANEL_WIDTH + 15,
            SummaryAction.HEIGHT + SummaryAction.FILTER_HEIGHT + 15);
    final Dimension dimensionButtonPanel = new Dimension(SummaryAction.BUTTON_WIDTH, SummaryAction.HEIGHT);
    final Dimension dimensionFilterLateral = new Dimension(SummaryAction.PANEL_WIDTH,
            SummaryAction.FILTER_HEIGHT);

    if (d != null) {
        d.setVisible(true);/*ww w  . j  av  a 2 s  .  c  o m*/
        return d;
    }
    d = createJDialog(titulo);

    JPanel cabecera = buildCabecera(label_cabecera, textfieldSize, icono, title, null);
    JPanel caracteristicas = new JPanel(new FlowLayout());
    caracteristicas.setOpaque(false);
    caracteristicas.add(new JLabel("Tipo de Capa: "));
    ((DefaultComboBoxModel) comboTipoCapa.getModel()).removeAllElements();
    ((DefaultComboBoxModel) comboTipoCapa.getModel()).addElement("Base");
    ((DefaultComboBoxModel) comboTipoCapa.getModel()).addElement("Opcional");
    caracteristicas.add(comboTipoCapa);
    caracteristicas.add(new JLabel("Habilitada:"));
    caracteristicas.add(habilitado);
    cabecera.add(caracteristicas, BorderLayout.SOUTH);
    d.add(cabecera, BorderLayout.NORTH);

    JPanel urlPanel = new JPanel(new FlowLayout());
    urlPanel.setOpaque(false);

    urlPanel.add(new JLabel("URL:"));
    urlPanel.add(nombre);

    JPanel central = buildCentralUrl(centered_label, left_items, right_items, left_label, right_label,
            textfieldSize, dimensionList, dimensionPanel, dimensionButtonPanel, dimensionFilterLateral,
            urlPanel);

    d.add(central, BorderLayout.CENTER);

    JPanel pie = buildPie(label_pie, guardar, textfieldSize, d);
    d.add(pie, BorderLayout.SOUTH);

    if (guardar != null) {
        guardar.setFrame(d);
    }

    return d;
}

From source file:es.emergya.ui.plugins.admin.AdminLayers.java

protected SummaryAction getSummaryAction(final CapaInformacion capaInformacion) {
    SummaryAction action = new SummaryAction(capaInformacion) {

        private static final long serialVersionUID = -3691171434904452485L;

        @Override//ww  w. ja v  a 2s .c o  m
        protected JFrame getSummaryDialog() {

            if (capaInformacion != null) {
                d = getDialog(capaInformacion, null, "", null, "image/png");
                return d;
            } else {
                JDialog primera = getJDialog();
                primera.setResizable(false);
                primera.setVisible(true);
                primera.setAlwaysOnTop(true);
            }
            return null;
        }

        private JDialog getJDialog() {
            final JDialog dialog = new JDialog();
            dialog.setTitle(i18n.getString("admin.capas.nueva.titleBar"));
            dialog.setIconImage(getBasicWindow().getIconImage());

            dialog.setLayout(new BorderLayout());

            JPanel centro = new JPanel(new FlowLayout());
            centro.setOpaque(false);
            JLabel label = new JLabel(i18n.getString("admin.capas.nueva.url"));
            final JTextField url = new JTextField(50);
            final JLabel icono = new JLabel(LogicConstants.getIcon("48x48_transparente"));
            label.setLabelFor(url);
            centro.add(label);
            centro.add(url);
            centro.add(icono);
            dialog.add(centro, BorderLayout.CENTER);

            JPanel pie = new JPanel(new FlowLayout(FlowLayout.TRAILING));
            pie.setOpaque(false);
            final JButton siguiente = new JButton(i18n.getString("admin.capas.nueva.boton.siguiente"),
                    LogicConstants.getIcon("button_next"));
            JButton cancelar = new JButton(i18n.getString("admin.capas.nueva.boton.cancelar"),
                    LogicConstants.getIcon("button_cancel"));
            final SiguienteActionListener siguienteActionListener = new SiguienteActionListener(url, dialog,
                    icono, siguiente);
            url.addActionListener(siguienteActionListener);

            siguiente.addActionListener(siguienteActionListener);

            cancelar.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    dialog.dispose();
                }
            });
            pie.add(siguiente);
            pie.add(cancelar);
            dialog.add(pie, BorderLayout.SOUTH);

            dialog.getContentPane().setBackground(Color.WHITE);

            dialog.pack();
            dialog.setLocationRelativeTo(null);
            return dialog;
        }

        private JFrame getDialog(final CapaInformacion c, final Capa[] left_items, final String service,
                final Map<String, Boolean> transparentes, final String png) {

            if (left_items != null && left_items.length == 0) {
                JOptionPane.showMessageDialog(AdminLayers.this,
                        i18n.getString("admin.capas.nueva.error.noCapasEnServicio"));
            } else {

                final String label_cabecera = i18n.getString("admin.capas.nueva.nombreCapa");
                final String label_pie = i18n.getString("admin.capas.nueva.infoAdicional");
                final String centered_label = i18n.getString("admin.capas.nueva.origenDatos");
                final String left_label = i18n.getString("admin.capas.nueva.subcapasDisponibles");
                final String right_label;
                if (left_items != null) {
                    right_label = i18n.getString("admin.capas.nueva.capasSeleccionadas");
                } else {
                    right_label = i18n.getString("admin.capas.ficha.capasSeleccionadas");
                }
                final String tituloVentana, cabecera;
                if (c.getNombre() == null) {
                    tituloVentana = i18n.getString("admin.capas.nueva.titulo.nuevaCapa");
                    cabecera = i18n.getString("admin.capas.nueva.cabecera.nuevaCapa");
                } else {
                    tituloVentana = i18n.getString("admin.capas.nueva.titulo.ficha");
                    cabecera = i18n.getString("admin.capas.nueva.cabecera.ficha");
                }

                final Capa[] right_items = c.getCapas().toArray(new Capa[0]);
                final AdminPanel.SaveOrUpdateAction<CapaInformacion> guardar = layers.new SaveOrUpdateAction<CapaInformacion>(
                        c) {

                    private static final long serialVersionUID = 7447770296943341404L;

                    @Override
                    public void actionPerformed(ActionEvent e) {

                        if (isNew && CapaConsultas.alreadyExists(textfieldCabecera.getText())) {
                            JOptionPane.showMessageDialog(super.frame,
                                    i18n.getString("admin.capas.nueva.error.nombreCapaYaExiste"));

                        } else if (textfieldCabecera.getText().isEmpty()) {
                            JOptionPane.showMessageDialog(super.frame,
                                    i18n.getString("admin.capas.nueva.error.nombreCapaEnBlanco"));

                        } else if (((DefaultListModel) right.getModel()).size() == 0) {
                            JOptionPane.showMessageDialog(super.frame,
                                    i18n.getString("admin.capas.nueva.error.noCapasSeleccionadas"));

                        } else if (cambios) {
                            int i = JOptionPane.showConfirmDialog(super.frame,
                                    i18n.getString("admin.capas.nueva.confirmar.guardar.titulo"),
                                    i18n.getString("admin.capas.nueva.confirmar.boton.guardar"),
                                    JOptionPane.YES_NO_CANCEL_OPTION);

                            if (i == JOptionPane.YES_OPTION) {

                                if (original == null) {
                                    original = new CapaInformacion();

                                }
                                original.setInfoAdicional(textfieldPie.getText());
                                original.setNombre(textfieldCabecera.getText());
                                original.setHabilitada(habilitado.isSelected());
                                original.setOpcional(comboTipoCapa.getSelectedIndex() != 0);

                                boolean transparente = true;

                                HashSet<Capa> capas = new HashSet<Capa>();
                                List<Capa> capasEnOrdenSeleccionado = new ArrayList<Capa>();
                                int indice = 0;
                                for (Object c : ((DefaultListModel) right.getModel()).toArray()) {
                                    if (c instanceof Capa) {
                                        transparente = transparente && (transparentes != null
                                                && transparentes.get(((Capa) c).getNombre()) != null
                                                && transparentes.get(((Capa) c).getNombre()));
                                        capas.add((Capa) c);
                                        capasEnOrdenSeleccionado.add((Capa) c);
                                        ((Capa) c).setCapaInformacion(original);
                                        ((Capa) c).setOrden(indice++);
                                        // ((Capa)
                                        // c).setNombre(c.toString());
                                    }

                                }
                                original.setCapas(capas);

                                if (original.getId() == null) {
                                    String url = nombre.getText();

                                    if (url.indexOf("?") > -1) {
                                        if (!url.endsWith("?")) {
                                            url += "&";

                                        }
                                    } else {
                                        url += "?";

                                    }
                                    url += "VERSION=" + version + "&REQUEST=GetMap&FORMAT=" + png + "&SERVICE="
                                            + service + "&WIDTH={2}&HEIGHT={3}&BBOX={1}&SRS={0}";
                                    // if (transparente)
                                    url += "&TRANSPARENT=TRUE";
                                    url += "&LAYERS=";

                                    String estilos = "";
                                    final String coma = "%2C";
                                    if (capasEnOrdenSeleccionado.size() > 0) {
                                        for (Capa c : capasEnOrdenSeleccionado) {
                                            url += c.getTitulo().replaceAll(" ", "+") + coma;
                                            estilos += c.getEstilo() + coma;
                                        }
                                        estilos = estilos.substring(0, estilos.length() - coma.length());

                                        estilos = estilos.replaceAll(" ", "+");

                                        url = url.substring(0, url.length() - coma.length());
                                    }
                                    url += "&STYLES=" + estilos;
                                    original.setUrl_visible(original.getUrl());
                                    original.setUrl(url);
                                }
                                CapaInformacionAdmin.saveOrUpdate(original);

                                cambios = false;

                                layers.setTableData(getAll(new CapaInformacion()));

                                closeFrame();
                            } else if (i == JOptionPane.NO_OPTION) {
                                closeFrame();

                            }
                        } else {
                            closeFrame();

                        }
                    }
                };
                JFrame segunda = generateUrlDialog(label_cabecera, label_pie, centered_label, tituloVentana,
                        left_items, right_items, left_label, right_label, guardar,
                        LogicConstants.getIcon("tittleficha_icon_capa"), cabecera, c.getHabilitada(),
                        c.getOpcional(), c.getUrl_visible());
                segunda.setResizable(false);

                if (c != null) {
                    textfieldCabecera.setText(c.getNombre());
                    textfieldPie.setText(c.getInfoAdicional());
                    nombre.setText(c.getUrl_visible());
                    nombre.setEditable(false);
                    if (c.getHabilitada() == null) {
                        c.setHabilitada(false);

                    }
                    habilitado.setSelected(c.getHabilitada());
                    if (c.isOpcional() != null && c.isOpcional()) {
                        comboTipoCapa.setSelectedIndex(1);
                    } else {
                        comboTipoCapa.setSelectedIndex(0);
                    }
                }

                if (c.getId() == null) {
                    habilitado.setSelected(true);
                    comboTipoCapa.setSelectedIndex(1);
                }

                habilitado.setEnabled(true);
                if (c == null || c.getId() == null) {
                    textfieldCabecera.setEditable(true);
                } else {
                    textfieldCabecera.setEditable(false);
                }

                cambios = false;

                segunda.pack();
                segunda.setLocationRelativeTo(null);
                segunda.setVisible(true);
                return segunda;
            }
            return null;
        }

        class SiguienteActionListener implements ActionListener {

            private final JTextField url;
            private final JDialog dialog;
            private final JLabel icono;
            private final JButton siguiente;

            public SiguienteActionListener(JTextField url, JDialog dialog, JLabel icono, JButton siguiente) {
                this.url = url;
                this.dialog = dialog;
                this.icono = icono;
                this.siguiente = siguiente;
            }

            @Override
            public void actionPerformed(ActionEvent e) {
                final CapaInformacion ci = new CapaInformacion();
                ci.setUrl(url.getText());
                ci.setCapas(new HashSet<Capa>());
                SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {

                    private List<Capa> res = new LinkedList<Capa>();
                    private String service = "WMS";
                    private String png = null;
                    private Map<String, Boolean> transparentes = new HashMap<String, Boolean>();
                    private ArrayList<String> errorStack = new ArrayList<String>();
                    private Boolean goOn = true;

                    @SuppressWarnings(value = "unchecked")
                    @Override
                    protected Object doInBackground() throws Exception {
                        try {
                            final String url2 = ci.getUrl();
                            WMSClient client = new WMSClient(url2);
                            client.connect(new ICancellable() {

                                @Override
                                public boolean isCanceled() {
                                    return false;
                                }

                                @Override
                                public Object getID() {
                                    return System.currentTimeMillis();
                                }
                            });

                            version = client.getVersion();

                            for (final String s : client.getLayerNames()) {
                                WMSLayer layer = client.getLayer(s);
                                // this.service =
                                // client.getServiceName();
                                final Vector allSrs = layer.getAllSrs();
                                boolean epsg = (allSrs != null) ? allSrs.contains("EPSG:4326") : false;
                                final Vector formats = client.getFormats();
                                if (formats.contains("image/png")) {
                                    png = "image/png";
                                } else if (formats.contains("IMAGE/PNG")) {
                                    png = "IMAGE/PNG";
                                } else if (formats.contains("png")) {
                                    png = "png";
                                } else if (formats.contains("PNG")) {
                                    png = "PNG";
                                }
                                boolean image = png != null;
                                if (png == null) {
                                    png = "IMAGE/PNG";
                                }
                                if (epsg && image) {
                                    boolean hasTransparency = layer.hasTransparency();
                                    this.transparentes.put(s, hasTransparency);
                                    Capa capa = new Capa();
                                    capa.setCapaInformacion(ci);
                                    if (layer.getStyles().size() > 0) {
                                        capa.setEstilo(((WMSStyle) layer.getStyles().get(0)).getName());
                                    }
                                    capa.setNombre(layer.getTitle());
                                    capa.setTitulo(s);
                                    res.add(capa);
                                    if (!hasTransparency) {
                                        errorStack.add(i18n.getString(Locale.ROOT,
                                                "admin.capas.nueva.error.capaNoTransparente",
                                                layer.getTitle()));
                                    }
                                } else {
                                    String error = "";
                                    // if (opaque)
                                    // error += "<li>Es opaca</li>";
                                    if (!image) {
                                        error += i18n.getString("admin.capas.nueva.error.formatoPNG");
                                    }
                                    if (!epsg) {
                                        error += i18n.getString("admin.capas.nueva.error.projeccion");
                                    }
                                    final String cadena = i18n.getString(Locale.ROOT,
                                            "admin.capas.nueva.error.errorCapa", new Object[] { s, error });
                                    errorStack.add(cadena);
                                }
                            }
                        } catch (final Throwable t) {
                            log.error("Error al parsear el WMS", t);
                            goOn = false;
                            icono.setIcon(LogicConstants.getIcon("48x48_transparente"));

                            JOptionPane.showMessageDialog(dialog,
                                    i18n.getString("admin.capas.nueva.error.errorParseoWMS"));

                            siguiente.setEnabled(true);
                        }
                        return null;
                    }

                    @Override
                    protected void done() {
                        super.done();
                        if (goOn) {

                            dialog.dispose();
                            ci.setUrl_visible(ci.getUrl());
                            final JFrame frame = getDialog(ci, res.toArray(new Capa[0]), service, transparentes,
                                    png);
                            if (!errorStack.isEmpty()) {
                                String error = "<html>";
                                for (final String s : errorStack) {
                                    error += s + "<br/>";
                                }
                                error += "</html>";
                                final String errorString = error;
                                SwingUtilities.invokeLater(new Runnable() {

                                    @Override
                                    public void run() {
                                        JOptionPane.showMessageDialog(frame, errorString);
                                    }
                                });
                            }
                        }
                    }
                };
                sw.execute();
                icono.setIcon(LogicConstants.getIcon("anim_conectando"));
                icono.repaint();
                siguiente.setEnabled(false);
            }
        }
    };

    return action;
}

From source file:es.emergya.ui.gis.popups.ConsultaHistoricos.java

private JPanel getBotones() {
    JPanel boton = new JPanel(new FlowLayout());
    boton.setOpaque(false);
    consultar = getConsultar();/* ww  w  .j  av a  2 s . c  o  m*/
    boton.add(consultar);
    limpiar = getLimpiar();
    boton.add(limpiar);
    cargando = new JLabel(LogicConstants.getIcon("48x48_transparente"));
    boton.add(cargando);
    boton.add(new JLabel(LogicConstants.getIcon("48x48_transparente")));
    JButton cancelar = getCancelar();
    boton.add(cancelar);
    return boton;
}

From source file:ChiSquareCalculator.java

ChiSquareCalculator() {
    final JFrame jfrm = new JFrame("Chi Square Calculator");
    jfrm.setSize(400, 550);//from w ww .  ja  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:chisquarecalculator.ChisqCal.java

public ChisqCal() {
    final JFrame jfrm = new JFrame("Chi Square Calculator");
    jfrm.setSize(400, 550);/*from  w w w  . ja  v a  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:es.emergya.ui.plugins.admin.aux1.SummaryAction.java

private JPanel buildCenter(final String centered_label) {
    GridBagConstraints gbc = new GridBagConstraints();
    JPanel central = new JPanel(new GridBagLayout());
    central.setBorder(new EmptyBorder(15, 15, 15, 15));
    central.setOpaque(false);
    gbc.gridx = 0;/*from   w w w  .  j av  a 2s .c  om*/
    gbc.gridy = 0;
    gbc.insets = new Insets(5, 15, 5, 15);
    gbc.gridwidth = 2;
    return central;
}

From source file:es.emergya.ui.plugins.admin.aux1.SummaryAction.java

private JPanel buildCabecera(final String label_cabecera, final int textfieldSize, final Icon icono,
        final String titulo, final String icono_seleccionado) {
    JLabel title = new JLabel(titulo, icono, SwingConstants.LEFT);
    title.setFont(LogicConstants.deriveBoldFont(12f));
    JPanel resultado = new JPanel(new BorderLayout(2, 2));
    resultado.setOpaque(false);
    resultado.add(title, BorderLayout.NORTH);
    JPanel cabecera = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    cabecera.setOpaque(false);//from   ww  w  . j av  a  2 s . c  o  m

    JLabel nombre = new JLabel(label_cabecera, JLabel.RIGHT);
    gbc.gridx = 0;
    gbc.gridy = 0;
    cabecera.add(nombre, gbc);
    textfieldCabecera.setColumns(textfieldSize);
    textfieldCabecera.getDocument().addDocumentListener(changeListener);
    nombre.setLabelFor(textfieldCabecera);
    gbc.gridx++;
    cabecera.add(textfieldCabecera, gbc);

    if (icono_seleccionado != null) {
        JLabel nombre2 = new JLabel("Icono:", JLabel.RIGHT);
        gbc.gridx = 0;
        gbc.gridy++;
        cabecera.add(nombre2, gbc);
        ((DefaultComboBoxModel) iconos.getModel()).removeAllElements();
        for (String icon : FlotaConsultas.getAllIcons("/images/" + LogicConstants.DIRECTORIO_ICONOS_FLOTAS)) {
            ((DefaultComboBoxModel) iconos.getModel()).addElement(icon);
        }
        for (ActionListener l : iconos.getActionListeners()) {
            iconos.removeActionListener(l);
        }
        iconos.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                cambios = true;
                if (iconos.getSelectedItem() != null) {
                    i.setIcon(LogicConstants.getIcon(LogicConstants.DIRECTORIO_ICONOS_FLOTAS
                            + iconos.getSelectedItem().toString() + "_flota_preview"));
                }
                i.updateUI();
            }
        });
        iconos.setSelectedItem(icono_seleccionado);
        if (iconos.getSelectedIndex() == -1 || i.getIcon() == null) {
            if (iconos.getModel().getSize() > 0)
                iconos.setSelectedIndex(0);
        }
        cambios = false;
        nombre2.setLabelFor(iconos);
        gbc.gridx++;
        gbc.anchor = GridBagConstraints.WEST;
        cabecera.add(iconos, gbc);

        gbc.gridheight = 2;
        gbc.gridx = 2;
        gbc.gridy = 0;
        gbc.insets = new Insets(2, 10, 2, 10);
        gbc.ipadx = 5;
        gbc.ipady = 5;
        i.setBorder(BorderFactory.createLineBorder(Color.black));
        cabecera.add(i, gbc);
    }

    resultado.add(cabecera, BorderLayout.CENTER);
    resultado.setBorder(new EmptyBorder(15, 15, 15, 15));
    return resultado;
}

From source file:es.emergya.ui.plugins.admin.aux1.SummaryAction.java

@SuppressWarnings("unchecked")
private JPanel buildPie(final String label_pie, final SaveOrUpdateAction guardar, final int textfieldSize,
        final JFrame d) {
    GridBagConstraints gbc;/*  w ww . j a  v a 2 s. com*/
    JPanel pie = new JPanel(new GridBagLayout());
    pie.setBorder(new EmptyBorder(5, 15, 15, 15));
    pie.setOpaque(false);
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.insets = new Insets(15, 15, 15, 15);
    gbc.gridwidth = 1;
    JLabel labl_pie = new JLabel(label_pie, JLabel.LEFT);
    pie.add(labl_pie, gbc);
    textfieldPie.setColumns(textfieldSize);
    textfieldPie.getDocument().addDocumentListener(changeListener);
    labl_pie.setLabelFor(textfieldPie);
    gbc.gridx++;
    gbc.gridwidth = 1;
    pie.add(textfieldPie, gbc);
    gbc.gridy++;
    gbc.gridx = 1;
    gbc.insets = new Insets(15, -90, 15, 15);
    JPanel botones = getBotonesSalir(guardar, d, 200);
    pie.add(botones, gbc);
    return pie;
}

From source file:es.emergya.ui.gis.popups.ConsultaHistoricos.java

private JPanel getCabecera() {
    JPanel cabecera = new JPanel(new FlowLayout(FlowLayout.LEFT));
    cabecera.setOpaque(false);
    JLabel titulo = new JLabel("Consulta de Posiciones GPS en el Histrico");
    titulo.setFont(LogicConstants.deriveBoldFont(12.0f));
    titulo.setIcon(LogicConstants.getIcon("tittleventana_icon_consultahistorico"));
    cabecera.add(titulo);/* ww w .java2 s . c o  m*/
    return cabecera;
}

From source file:es.emergya.ui.gis.popups.ConsultaHistoricos.java

private JPanel getCentral() {
    JPanel central = new JPanel(new FlowLayout());
    central.setOpaque(false);

    JPanel intervalo = getIntervalo();
    intervalo.setOpaque(false);//ww w.  jav  a  2 s.  com
    intervalo.setPreferredSize(new Dimension(400, 100));
    central.add(intervalo);

    // JPanel consulta = getConsulta();
    // consulta.setOpaque(false);
    // consulta.setPreferredSize(new Dimension(400, 120));
    // central.add(consulta);

    JPanel elementos = getElementos();
    elementos.setOpaque(false);
    elementos.setPreferredSize(new Dimension(400, 210));
    central.add(elementos);

    JPanel ventanaMensaje = getVentanaMensaje();
    ventanaMensaje.setOpaque(false);
    ventanaMensaje.setPreferredSize(new Dimension(400, 30));
    central.add(ventanaMensaje);

    return central;
}