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 monitor; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JButton; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; /** * * @author wolszczc */ public class StatsWindow extends javax.swing.JFrame { private String nGramLabel; private int[] nGramCounts; public String getnGramLabel() { return nGramLabel; } public void setnGramLabel(String nGramLabel) { this.nGramLabel = nGramLabel; } public int[] getnGramCounts() { return nGramCounts; } public void setnGramCounts(int[] nGramCounts) { this.nGramCounts = nGramCounts; } public StatsWindow() { initComponents(); } public JButton getjButtonRefresh() { return jButtonRefresh; } public void setjButtonRefresh(JButton jButtonRefresh) { this.jButtonRefresh = jButtonRefresh; } /** * 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() { jScrollPane1 = new javax.swing.JScrollPane(); jTree1 = new javax.swing.JTree(); jProgressBar1 = new javax.swing.JProgressBar(); jButtonQuit = new javax.swing.JButton(); jButtonRefresh = new javax.swing.JButton(); jPanelDiagram = new javax.swing.JPanel(); jScrollPane2 = new javax.swing.JScrollPane(); jTextAreaNGramWords = new javax.swing.JTextArea(); jPanelDiagram2 = new javax.swing.JPanel(); jScrollPane3 = new javax.swing.JScrollPane(); jTextAreaSufiksWords = new javax.swing.JTextArea(); jScrollPane1.setViewportView(jTree1); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButtonQuit.setText("Quit"); jButtonQuit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonQuitActionPerformed(evt); } }); jButtonRefresh.setText("Refresh"); jButtonRefresh.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonRefreshActionPerformed(evt); } }); jPanelDiagram.setBackground(new java.awt.Color(153, 153, 153)); jPanelDiagram.setLayout(new java.awt.BorderLayout()); jTextAreaNGramWords.setColumns(20); jTextAreaNGramWords.setRows(5); jScrollPane2.setViewportView(jTextAreaNGramWords); jPanelDiagram2.setBackground(new java.awt.Color(153, 153, 153)); jPanelDiagram2.setLayout(new java.awt.BorderLayout()); jTextAreaSufiksWords.setColumns(20); jTextAreaSufiksWords.setRows(5); jScrollPane3.setViewportView(jTextAreaSufiksWords); 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(layout.createSequentialGroup().addComponent(jButtonQuit) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 586, Short.MAX_VALUE) .addComponent(jButtonRefresh)) .addGroup(layout.createSequentialGroup() .addGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanelDiagram, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanelDiagram2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPane3)))) .addContainerGap())); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanelDiagram, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jPanelDiagram2, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE) .addComponent(jScrollPane3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButtonQuit).addComponent(jButtonRefresh)) .addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents private void jButtonQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonQuitActionPerformed Object source = evt.getSource(); if (jButtonQuit == source) { dispose(); } }//GEN-LAST:event_jButtonQuitActionPerformed private void jButtonRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRefreshActionPerformed DefaultCategoryDataset dateset = new DefaultCategoryDataset(); dateset.setValue(Window.getIndeksWordsInSettingsWindow()[0], "", "1"); dateset.setValue(Window.getIndeksWordsInSettingsWindow()[1], "", "2"); dateset.setValue(Window.getIndeksWordsInSettingsWindow()[2], "", "3"); dateset.setValue(Window.getIndeksWordsInSettingsWindow()[3], "", "4"); dateset.setValue(Window.getIndeksWordsInSettingsWindow()[4], "", "5"); DefaultCategoryDataset dateset2 = new DefaultCategoryDataset(); dateset2.setValue(Window.getIndeksWordsInSettingsWindow2()[0], "", "1"); dateset2.setValue(Window.getIndeksWordsInSettingsWindow2()[1], "", "2"); dateset2.setValue(Window.getIndeksWordsInSettingsWindow2()[2], "", "3"); dateset2.setValue(Window.getIndeksWordsInSettingsWindow2()[3], "", "4"); dateset2.setValue(Window.getIndeksWordsInSettingsWindow2()[4], "", "5"); JFreeChart chart = ChartFactory.createBarChart("Prefiks counts diagram", "", "", dateset, PlotOrientation.HORIZONTAL, false, false, false); CategoryPlot catPlot = chart.getCategoryPlot(); catPlot.setRangeGridlinePaint(Color.BLACK); JFreeChart chart2 = ChartFactory.createBarChart("Sufiks counts diagram", "", "", dateset2, PlotOrientation.HORIZONTAL, false, false, false); CategoryPlot catPlot2 = chart2.getCategoryPlot(); catPlot2.setRangeGridlinePaint(Color.BLACK); ChartPanel chartPanel = new ChartPanel(chart); jPanelDiagram.removeAll(); jPanelDiagram.add(chartPanel, BorderLayout.CENTER); jPanelDiagram.validate(); ChartPanel chartPanel2 = new ChartPanel(chart2); jPanelDiagram2.removeAll(); jPanelDiagram2.add(chartPanel2, BorderLayout.CENTER); jPanelDiagram2.validate(); jTextAreaNGramWords.setText(Window.getWordsInSettingsWindow()); jTextAreaSufiksWords.setText(Window.getWordsInSettingsWindow2()); }//GEN-LAST:event_jButtonRefreshActionPerformed /** * @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(StatsWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(StatsWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(StatsWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(StatsWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new StatsWindow().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtonQuit; private javax.swing.JButton jButtonRefresh; private javax.swing.JPanel jPanelDiagram; private javax.swing.JPanel jPanelDiagram2; private javax.swing.JProgressBar jProgressBar1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JTextArea jTextAreaNGramWords; private javax.swing.JTextArea jTextAreaSufiksWords; private javax.swing.JTree jTree1; // End of variables declaration//GEN-END:variables }