Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package problema_inventario.vistas; import Utils.GeneradorDeGraficas; import java.awt.GridLayout; import javax.swing.WindowConstants; import org.jfree.chart.ChartPanel; import problema_inventario.models.DeterministaBasico; import problema_inventario.models.DeterministaGeneral; /** * * @author Slaush */ public class GraphicForm extends javax.swing.JFrame { /** * Creates new form GraphicForm */ public GraphicForm(DeterministaGeneral general, String unidad) { this.problema = general; this.unidad = unidad; initComponents(); initChart(); initLayout(); setDefaultCloseOperation(DISPOSE_ON_CLOSE); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { okButton = new javax.swing.JButton(); panelGrafica = new javax.swing.JPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); okButton.setText("OK"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); panelGrafica.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Grafica", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Tahoma", 0, 14))); // NOI18N javax.swing.GroupLayout panelGraficaLayout = new javax.swing.GroupLayout(panelGrafica); panelGrafica.setLayout(panelGraficaLayout); panelGraficaLayout.setHorizontalGroup(panelGraficaLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 566, Short.MAX_VALUE)); panelGraficaLayout.setVerticalGroup(panelGraficaLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 278, Short.MAX_VALUE)); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(panelGrafica, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(248, 248, 248))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap() .addComponent(panelGrafica, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(okButton).addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed dispose(); }//GEN-LAST:event_okButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton okButton; private javax.swing.JPanel panelGrafica; // End of variables declaration//GEN-END:variables public DeterministaGeneral problema; public String unidad; private ChartPanel chart; private void initLayout() { GridLayout l = new GridLayout(); l.setColumns(1); l.setRows(1); panelGrafica.setLayout(l); panelGrafica.add(chart); } private void initChart() { chart = new ChartPanel(null); //Sigleton Pattern! chart.setChart(GeneradorDeGraficas.getInstance().graficarInventario(problema, unidad)); //chart.setChart(GeneradorDeGraficas.getInstance().graficarCostos(problema, unidad)); } }