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 view; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.LayoutManager; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.JButton; import org.jfree.chart.ChartPanel; /** * * @author Lucas */ public class PlotterView extends javax.swing.JFrame { /** * Creates new form PlotterView */ public PlotterView() { initComponents(); } public int getComboBoxIndex() { return this.xAxisVariableJComboBox.getSelectedIndex(); } public int getQuantityComboBoxIndex() { return this.quantityJComboBox.getSelectedIndex(); } public int getSizeComboBoxIndex() { return this.sizeJComboBox.getSelectedIndex(); } public int getTypeComboBoxIndex() { return this.typeJComboBox.getSelectedIndex(); } public int getMachineComboBoxIndex() { return this.machineJComboBox.getSelectedIndex(); } public String getTextFieldText() { return this.filePathJTextField.getText(); } public void setChartPanel(ChartPanel chartPanel) { // this.chartJPanel.setLayout(new BorderLayout()); // this.initComponents(); this.chartJPanel.removeAll(); this.chartJPanel.add(chartPanel, BorderLayout.NORTH); this.chartJPanel.revalidate(); this.chartJPanel.repaint(); } public void addComboBoxListener(ActionListener comboBoxListener) { this.xAxisVariableJComboBox.addActionListener(comboBoxListener); } public void addButtonListener(ActionListener buttonListener) { this.startJButton.addActionListener(buttonListener); } /** * 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() { chartJPanel = new javax.swing.JPanel(); xAxisVariableJComboBox = new javax.swing.JComboBox<>(); jLabel1 = new javax.swing.JLabel(); startJButton = new javax.swing.JButton(); filePathJTextField = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); quantityJComboBox = new javax.swing.JComboBox<>(); jLabel3 = new javax.swing.JLabel(); sizeJComboBox = new javax.swing.JComboBox<>(); jLabel4 = new javax.swing.JLabel(); typeJComboBox = new javax.swing.JComboBox<>(); jLabel5 = new javax.swing.JLabel(); machineJComboBox = new javax.swing.JComboBox<>(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Result Plotter"); setResizable(false); chartJPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); chartJPanel.setLayout(new java.awt.BorderLayout()); xAxisVariableJComboBox.setModel( new javax.swing.DefaultComboBoxModel<>(new String[] { "Quantity", "Size", "Type", "Machine" })); xAxisVariableJComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { xAxisVariableJComboBoxActionPerformed(evt); } }); jLabel1.setText(" X-axis Variable:"); startJButton.setText("Start"); filePathJTextField.setToolTipText("Path to file"); jLabel2.setText("Quantity:"); quantityJComboBox .setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "10", "50", "100", "200" })); jLabel3.setText("Size:"); sizeJComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1mb", "10mb", "50mb" })); jLabel4.setText("Type:"); typeJComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Binary", "Textual" })); jLabel5.setText("Mquina:"); machineJComboBox .setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "caio", "dilts", "Jonathan" })); 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() .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(startJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 510, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(xAxisVariableJComboBox, 0, 164, Short.MAX_VALUE) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(quantityJComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(sizeJComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(typeJComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup().addComponent(jLabel4) .addGap(0, 0, Short.MAX_VALUE)) .addComponent(machineJComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(filePathJTextField).addComponent(chartJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 510, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(xAxisVariableJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(quantityJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(sizeJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(typeJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(machineJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(chartJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(filePathJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(startJButton).addContainerGap(50, Short.MAX_VALUE))); pack(); }// </editor-fold>//GEN-END:initComponents private void xAxisVariableJComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_xAxisVariableJComboBoxActionPerformed // TODO add your handling code here: System.out.println("change"); }//GEN-LAST:event_xAxisVariableJComboBoxActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(PlotterView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(PlotterView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(PlotterView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(PlotterView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new PlotterView().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel chartJPanel; private javax.swing.JTextField filePathJTextField; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JComboBox<String> machineJComboBox; private javax.swing.JComboBox<String> quantityJComboBox; private javax.swing.JComboBox<String> sizeJComboBox; private javax.swing.JButton startJButton; private javax.swing.JComboBox<String> typeJComboBox; private javax.swing.JComboBox<String> xAxisVariableJComboBox; // End of variables declaration//GEN-END:variables }