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 ds.monte.carlo; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.ImageIcon; import javax.swing.UIDefaults; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.CategoryLabelPositions; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.NumberTickUnit; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.chart.renderer.category.LineAndShapeRenderer; import org.jfree.data.category.DefaultCategoryDataset; /** * * @author Carmen */ public class Application extends javax.swing.JFrame implements PropertyChangeListener { /** * Creates new form Application */ Simulation monteCarlo; int numberOfReplications, initSeed; public Application() { initComponents(); initProgressBar(); this.setTitle("Monte Carlo"); ImageIcon img = new ImageIcon("img.png"); this.setIconImage(img.getImage()); numberOfReplications = 1000; initSeed = 0; jLabel3.setVisible(false); } /** * 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() { jPanel1 = new javax.swing.JPanel(); jTabbedPane4 = new javax.swing.JTabbedPane(); jPanel3 = new javax.swing.JPanel(); jProgressBar1 = new javax.swing.JProgressBar(); jPanel5 = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jPanel6 = new javax.swing.JPanel(); jPanel8 = new javax.swing.JPanel(); jPanel9 = new javax.swing.JPanel(); jPanel7 = new javax.swing.JPanel(); jLabel9 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); jLabel14 = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); jLabel16 = new javax.swing.JLabel(); jLabel17 = new javax.swing.JLabel(); jLabel18 = new javax.swing.JLabel(); jPanel4 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jTextField2 = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 100, Short.MAX_VALUE)); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 100, Short.MAX_VALUE)); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jTabbedPane4.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jPanel3.setBackground(new java.awt.Color(255, 255, 255)); jProgressBar1.setForeground(new java.awt.Color(204, 204, 204)); jProgressBar1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(102, 102, 102), 1, true)); jProgressBar1.setOpaque(true); jPanel5.setBackground(new java.awt.Color(255, 255, 255)); jPanel5.setLayout(new java.awt.BorderLayout()); jLabel4.setBackground(new java.awt.Color(255, 255, 255)); jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel4.setIcon(new javax.swing.ImageIcon( "C:\\Users\\Carmen\\Documents\\NetBeansProjects\\ds Monte Carlo\\run.png")); // NOI18N jLabel4.setOpaque(true); jLabel4.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jLabel4MouseClicked(evt); } }); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)) .addContainerGap()) .addGroup(jPanel3Layout.createSequentialGroup().addGap(134, 134, 134).addComponent(jLabel4) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); jTabbedPane4.addTab("Simulation", jPanel3); jPanel2.setBackground(new java.awt.Color(255, 255, 255)); jPanel6.setBackground(new java.awt.Color(255, 255, 255)); jPanel6.setLayout(new java.awt.BorderLayout()); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout .setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup().addContainerGap() .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap() .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE) .addGap(73, 73, 73))); jTabbedPane4.addTab("Growth", jPanel2); jPanel8.setBackground(new java.awt.Color(255, 255, 255)); jPanel9.setBackground(new java.awt.Color(255, 255, 255)); jPanel9.setLayout(new java.awt.BorderLayout()); javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8); jPanel8.setLayout(jPanel8Layout); jPanel8Layout.setHorizontalGroup(jPanel8Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel8Layout.createSequentialGroup().addContainerGap().addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); jPanel8Layout.setVerticalGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel8Layout.createSequentialGroup().addContainerGap() .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE) .addContainerGap())); jTabbedPane4.addTab("Length", jPanel8); jPanel7.setBackground(new java.awt.Color(255, 255, 255)); jLabel9.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jLabel9.setText("The project will last "); jLabel11.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jLabel13.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jLabel13.setText("%"); jLabel14.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jLabel14.setText("Probability the project will last up to 140 days:"); jLabel15.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jLabel15.setText("days in average."); jLabel16.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jLabel16.setText("___"); jLabel17.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jLabel17.setText("Days needed for finishing the project with 80% p."); jLabel18.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jLabel18.setText("x"); javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); jPanel7.setLayout(jPanel7Layout); jPanel7Layout .setHorizontalGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addGap(22, 22, 22).addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup().addComponent(jLabel9) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel16).addGap(39, 39, 39).addComponent(jLabel15)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup() .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(36, 36, 36))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup( jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel18).addComponent(jLabel13)) .addContainerGap(65, Short.MAX_VALUE))); jPanel7Layout.setVerticalGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addGap(38, 38, 38) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel15).addComponent(jLabel16)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel13)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel18)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 105, Short.MAX_VALUE) .addComponent(jLabel11).addGap(21, 21, 21))); jTabbedPane4.addTab("Results", jPanel7); jPanel4.setBackground(new java.awt.Color(255, 255, 255)); jLabel1.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jLabel1.setText("Number of replications"); jTextField1.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jTextField1.setHorizontalAlignment(javax.swing.JTextField.RIGHT); jTextField1.setText("1000"); jLabel5.setIcon(new javax.swing.ImageIcon( "C:\\Users\\Carmen\\Documents\\NetBeansProjects\\ds Monte Carlo\\src\\ds\\monte\\carlo\\save.png")); // NOI18N jLabel5.setText("jLabel5"); jLabel5.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jLabel5MouseClicked(evt); } }); jLabel2.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jLabel2.setText("Seed"); jTextField2.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jTextField2.setHorizontalAlignment(javax.swing.JTextField.RIGHT); jTextField2.setText("0"); jLabel3.setFont(new java.awt.Font("Segoe Print", 1, 14)); // NOI18N jLabel3.setForeground(new java.awt.Color(204, 204, 204)); jLabel3.setText("Saved!"); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup() .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout .createSequentialGroup().addGap(51, 51, 51) .addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel2).addComponent(jLabel1)) .addGap(52, 52, 52) .addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE) .addComponent(jTextField2))) .addGroup(jPanel4Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addGap(55, 55, 55))); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addGap(78, 78, 78) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1).addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(17, 17, 17) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(68, Short.MAX_VALUE))); jTabbedPane4.addTab("Settings", jPanel4); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTabbedPane4)); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTabbedPane4)); pack(); }// </editor-fold>//GEN-END:initComponents private void jLabel4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel4MouseClicked ImageIcon img = new ImageIcon("go.png"); this.setIconImage(img.getImage()); monteCarlo = new Simulation(numberOfReplications, initSeed); monteCarlo.addPropertyChangeListener(this); System.out.println("Simulacia vytvorena"); try { monteCarlo.execute(); } catch (Exception ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jLabel4MouseClicked private void jLabel5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel5MouseClicked String replications = jTextField1.getText(); numberOfReplications = Integer.parseInt(replications); String seed = jTextField2.getText(); initSeed = Integer.parseInt(seed); jLabel3.setVisible(true); }//GEN-LAST:event_jLabel5MouseClicked /** * @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(Application.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Application.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Application.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Application.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { new Application().setVisible(true); } }); } @Override public void propertyChange(PropertyChangeEvent evt) { if ("progress".equals(evt.getPropertyName())) { int progress = (Integer) evt.getNewValue(); jProgressBar1.setValue(progress); if (progress == 100) { createFrequencyGraph(monteCarlo.getDictionary()); createGrowthGraph(monteCarlo.getGrowthMap()); createLengthGraph(monteCarlo.findProbability()); ImageIcon img = new ImageIcon("img.png"); this.setIconImage(img.getImage()); jLabel13.setText(((double) monteCarlo.getSuccessful() / numberOfReplications) * 100 + "%"); jLabel16.setText(monteCarlo.getAvg() + ""); jLabel18.setText(monteCarlo.getP80() + ""); } } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel18; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel6; private javax.swing.JPanel jPanel7; private javax.swing.JPanel jPanel8; private javax.swing.JPanel jPanel9; private javax.swing.JProgressBar jProgressBar1; private javax.swing.JTabbedPane jTabbedPane4; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; // End of variables declaration//GEN-END:variables private void initProgressBar() { jProgressBar1.setMinimum(0); jProgressBar1.setMaximum(100); jProgressBar1.setValue(0); UIDefaults defaults = new UIDefaults(); defaults.put("ProgressBar[Enabled].backgroundPainter", new MyPainter(new Color(210, 210, 210))); defaults.put("ProgressBar[Enabled].foregroundPainter", new MyPainter(new Color(92, 184, 92))); jProgressBar1.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.FALSE); jProgressBar1.putClientProperty("Nimbus.Overrides", defaults); } private void createFrequencyGraph(HashMap<Long, Integer> dictionary) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); long checksum = 0; for (Long key : dictionary.keySet()) { dataset.setValue(dictionary.get(key), "", "" + key); checksum += dictionary.get(key); } JFreeChart chart = ChartFactory.createBarChart("Frequency graph", "", "", dataset, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(Color.WHITE); CategoryPlot catPlot = chart.getCategoryPlot(); catPlot.setRangeGridlinePaint(new Color(92, 184, 92)); ValueAxis vAxis = catPlot.getRangeAxis(); CategoryAxis cAxis = catPlot.getDomainAxis(); cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); Font font = new Font("SansSerif", Font.PLAIN, 12); Font fontTitle = new Font("SansSerif", Font.PLAIN, 14); Font fontc = new Font("SansSerif", Font.PLAIN, 10); vAxis.setTickLabelFont(font); chart.getTitle().setFont(fontTitle); cAxis.setTickLabelFont(fontc); BarRenderer renderer = (BarRenderer) catPlot.getRenderer(); Color bootstrapGreen = new Color(92, 184, 92); renderer.setSeriesPaint(0, bootstrapGreen); ChartPanel chartPanel = new ChartPanel(chart); jPanel5.removeAll(); jPanel5.add(chartPanel, BorderLayout.CENTER); jPanel5.validate(); //jPanel5.setVisible(true); System.out.println("Checksum " + checksum); System.out.println("NumberOfReplications " + numberOfReplications); } private void createGrowthGraph(double[] growthMap) { DefaultCategoryDataset growthDataset = new DefaultCategoryDataset(); double min = 1000000; double max = 0; int l_100 = growthMap.length; int l_40 = (int) Math.round(l_100 * 0.4); System.out.print(growthMap.length); for (int i = l_40; i < growthMap.length; i++) { growthDataset.setValue(growthMap[i], "", "" + i); if (growthMap[i] < min) { min = growthMap[i]; } if (growthMap[i] > max) { max = growthMap[i]; } } JFreeChart growChart = ChartFactory.createLineChart("Simulated annealing", "", "", growthDataset, PlotOrientation.VERTICAL, false, false, false); growChart.setBackgroundPaint(Color.WHITE); CategoryPlot catPlot = growChart.getCategoryPlot(); catPlot.setRangeGridlinePaint(new Color(92, 184, 92)); ValueAxis vAxis = catPlot.getRangeAxis(); CategoryAxis cAxis = catPlot.getDomainAxis(); cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); vAxis.setRange(min, max); cAxis.setTickLabelsVisible(false); Font font = new Font("SansSerif", Font.PLAIN, 12); Font fontTitle = new Font("SansSerif", Font.PLAIN, 14); vAxis.setTickLabelFont(font); growChart.getTitle().setFont(fontTitle); LineAndShapeRenderer renderer = (LineAndShapeRenderer) catPlot.getRenderer(); Color bootstrapGreen = new Color(92, 184, 92); renderer.setSeriesPaint(0, bootstrapGreen); ChartPanel chartPanel = new ChartPanel(growChart); jPanel6.removeAll(); jPanel6.add(chartPanel, BorderLayout.CENTER); jPanel6.validate(); //jPanel5.setVisible(true); } private void createLengthGraph(HashMap<Integer, Integer> probability) { DefaultCategoryDataset pDataset = new DefaultCategoryDataset(); for (Integer key : probability.keySet()) { pDataset.setValue(probability.get(key), "", "" + key); } JFreeChart growChart = ChartFactory.createLineChart("Simulated annealing", "", "", pDataset, PlotOrientation.VERTICAL, false, false, false); growChart.setBackgroundPaint(Color.WHITE); CategoryPlot catPlot = growChart.getCategoryPlot(); catPlot.setRangeGridlinePaint(new Color(92, 184, 92)); ValueAxis vAxis = catPlot.getRangeAxis(); CategoryAxis cAxis = catPlot.getDomainAxis(); cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); cAxis.setTickLabelsVisible(false); Font font = new Font("SansSerif", Font.PLAIN, 12); Font fontTitle = new Font("SansSerif", Font.PLAIN, 14); vAxis.setTickLabelFont(font); growChart.getTitle().setFont(fontTitle); LineAndShapeRenderer renderer = (LineAndShapeRenderer) catPlot.getRenderer(); Color bootstrapGreen = new Color(92, 184, 92); renderer.setSeriesPaint(0, bootstrapGreen); ChartPanel chartPanel = new ChartPanel(growChart); jPanel9.removeAll(); jPanel9.add(chartPanel, BorderLayout.CENTER); jPanel9.validate(); } }