user.NewJPanel2.java Source code

Java tutorial

Introduction

Here is the source code for user.NewJPanel2.java

Source

/*
 * 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 user;

import java.awt.Image;
import javax.swing.DefaultComboBoxModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;

/**
 *
 * @author Nisha
 */
public class NewJPanel2 extends javax.swing.JPanel {

    /**
     * Creates new form NewJPanel2
     */
    public NewJPanel2() {
        initComponents();
        createChart = new CreateChart(query.getBestAsset(), "Most popular asset");

    }

    public static void setChartLabel(ImageIcon ii) {

        chartLabel.setIcon(ii);

    }

    private void setCheckBox(String[] items) {
        DefaultComboBoxModel model = (DefaultComboBoxModel) choiceBox2.getModel();
        model.removeAllElements();

        for (String item : items) {
            model.addElement(item);
        }
        choiceBox2.setModel(model);

    }

    CreateChart createChart = null;
    Query query = new Query();
    String[] tweetAnalyse = { "Most popular area", "Least popular area", "Visitors country", "Visitors region" };
    String[] animalAnalyse = { "Most popular animals" };
    String[] zooAnalyse = { "Activity", "Tweet content", "Followers" };
    String[] weatherAnalyse = { "Rainy weather", "Sunny weather", "Low temperature", "High temperature" };
    String selection = "Tweets";

    /**
     * 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() {

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu3 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        jMenuBar3 = new javax.swing.JMenuBar();
        jMenu5 = new javax.swing.JMenu();
        jMenu6 = new javax.swing.JMenu();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jButton3 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        choiceMenu = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        choiceBox2 = new javax.swing.JComboBox();
        chartLabel = new javax.swing.JLabel();

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        jMenu3.setText("File");
        jMenuBar2.add(jMenu3);

        jMenu4.setText("Edit");
        jMenuBar2.add(jMenu4);

        jMenu5.setText("File");
        jMenuBar3.add(jMenu5);

        jMenu6.setText("Edit");
        jMenuBar3.add(jMenu6);

        jButton1.setText("Previous");

        jButton2.setText("Next");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Day", "Week", "Month" }));

        jButton3.setText("Update");

        jLabel2.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        jLabel2.setText("Weather");

        jLabel3.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        jLabel3.setText("Zoo");

        choiceMenu.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "Tweets", "Zoo", "Animal", "Weather" }));
        choiceMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                choiceMenuActionPerformed(evt);
            }
        });

        choiceBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                choiceBox2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(41, 41, 41).addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel3).addGap(25, 25, 25))
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(22, 22, 22).addGroup(jPanel1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(chartLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 592,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18).addComponent(jLabel1))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jButton1)
                                                .addComponent(choiceMenu, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addGroup(jPanel1Layout.createSequentialGroup().addGap(12, 12, 12)
                                                        .addComponent(choiceBox2,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addComponent(jComboBox1,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(jPanel1Layout.createSequentialGroup()
                                                        .addGap(143, 143, 143).addComponent(jButton3)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addComponent(jButton2,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 69,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                        .addGap(0, 0, Short.MAX_VALUE)));
        jPanel1Layout
                .setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 358,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel1Layout
                                                .createSequentialGroup().addContainerGap().addComponent(chartLabel,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(18, 18, 18)
                                                .addGroup(jPanel1Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(choiceMenu,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(
                                                                jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(
                                                                choiceBox2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(67, 96, Short.MAX_VALUE))
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addGroup(jPanel1Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jButton3).addComponent(jButton2)
                                                        .addComponent(jButton1))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel3).addComponent(jLabel2))
                                                .addGap(26, 26, 26)))));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(jPanel1,
                        javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(30, Short.MAX_VALUE)));
    }// </editor-fold>//GEN-END:initComponents

    private void choiceMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_choiceMenuActionPerformed
        // TODO add your handling code here:
        switch (choiceMenu.getSelectedIndex()) {
        case 0:
            setCheckBox(tweetAnalyse);
            selection = "Tweets";
            break;
        case 1:
            setCheckBox(zooAnalyse);
            selection = "Zoo";
            break;
        case 2:
            setCheckBox(animalAnalyse);
            selection = "Animal";
            break;
        case 3:
            setCheckBox(weatherAnalyse);
            selection = "Weather";
            break;
        }
    }//GEN-LAST:event_choiceMenuActionPerformed

    private void choiceBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_choiceBox2ActionPerformed
        switch (selection) {
        case "Tweets":
            switch (choiceBox2.getSelectedIndex()) {
            case 0:

                createChart = new CreateChart(query.getBestAsset(), "Most popular asset");
                break;
            case 1:
                createChart = new CreateChart(query.getWorstAsset(), "Least popular asset");
                break;
            case 2:
                createChart = new CreateChart(query.getCountry(), "Country");
                break;
            case 3:
                createChart = new CreateChart(query.getRegion(), "Region");
                break;
            }
            break;
        case "Animal":
            switch (choiceBox2.getSelectedIndex()) {
            case 0:
                //createChart = new CreateChart(query.getBestAnimal(), "Tweet about animals"); 
                break;
            }
            break;
        case "Zoo":
            switch (choiceBox2.getSelectedIndex()) {
            case 0:
                //createChart = new CreateChart(query.getBlijdorpTweetsAndDate(), "Response"); 
                break;
            case 1:
                createChart = new CreateChart(query.getBlijdorpTweets(), "Tweet content");
                break;
            case 2:
                createChart = new CreateChart(query.getFollowersBlijdorp(), "Followers", "Datum", "Followers");
                break;
            }
            break;
        case "Weather":
            switch (choiceBox2.getSelectedIndex()) {
            case 0:
                //createChart = new CreateChart(query.getRainAndTweets(), "Rain"); 
                break;
            case 1:
                //createChart = new CreateChart(query.getGoodWeatherAndTweets(), "Sun");
                break;
            case 2:
                //createChart = new CreateChart(query.getLowTemperatureAndTweets(), "Low temperature");
                break;
            case 3:
                //createChart = new CreateChart(query.getHighTemperatureAndTweets(), "High temperature");
                break;
            }
            break;
        }//end of (selection) switch

    }//GEN-LAST:event_choiceBox2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JLabel chartLabel;
    private javax.swing.JComboBox choiceBox2;
    private javax.swing.JComboBox choiceMenu;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenuBar jMenuBar3;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}