MainUI.java Source code

Java tutorial

Introduction

Here is the source code for MainUI.java

Source

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.SwingConstants;
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.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

/*
 * 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.
 */

/**
 *
 * @author Administrator
 */
public class MainUI extends javax.swing.JFrame implements ActionListener {

    /**
     * Creates new form MainUI
     */
    public MainUI() {
        initComponents();
        initListener();
        initChart();
    }

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

        TabbedPane = new javax.swing.JTabbedPane();
        mainPagePanel = new javax.swing.JPanel();
        historyPanel = new javax.swing.JPanel();
        hisComboBox = new javax.swing.JComboBox();
        dateTextField0 = new javax.swing.JTextField();
        dateTextField1 = new javax.swing.JTextField();
        his_Button = new javax.swing.JButton();
        hisPanel1 = new javax.swing.JPanel();
        lightPointPanel = new javax.swing.JPanel();
        distencePanel = new javax.swing.JPanel();
        disLabel = new javax.swing.JLabel();
        disTextField = new javax.swing.JTextField();
        disComboBox = new javax.swing.JComboBox();
        disButton = new javax.swing.JButton();
        recommendationPanel = new javax.swing.JPanel();
        recomComboBox = new javax.swing.JComboBox();
        recomButton = new javax.swing.JButton();
        mainPanel = new javax.swing.JPanel();
        accountLabel = new javax.swing.JLabel();
        accountTextField = new javax.swing.JTextField();
        switchAccountButton = new javax.swing.JButton();
        Separator = new javax.swing.JSeparator();
        MenuBar = new javax.swing.JMenuBar();
        docMenu = new javax.swing.JMenu();
        docMenuItem0 = new javax.swing.JMenuItem();
        docMenuItem1 = new javax.swing.JMenuItem();
        sysMenu = new javax.swing.JMenu();
        sysMenuItem0 = new javax.swing.JMenuItem();
        sysMenuItem1 = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        TabbedPane.setToolTipText("");
        TabbedPane.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        javax.swing.GroupLayout mainPagePanelLayout = new javax.swing.GroupLayout(mainPagePanel);
        mainPagePanel.setLayout(mainPagePanelLayout);
        mainPagePanelLayout.setHorizontalGroup(mainPagePanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 628, Short.MAX_VALUE));
        mainPagePanelLayout.setVerticalGroup(mainPagePanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 370, Short.MAX_VALUE));

        TabbedPane.addTab("", mainPagePanel);

        hisComboBox.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "", "", "" }));

        dateTextField0.setText("");

        dateTextField1.setText("?");

        his_Button.setText("");
        his_Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                his_ButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout hisPanel1Layout = new javax.swing.GroupLayout(hisPanel1);
        hisPanel1.setLayout(hisPanel1Layout);
        hisPanel1Layout.setHorizontalGroup(hisPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));
        hisPanel1Layout.setVerticalGroup(hisPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 331, Short.MAX_VALUE));

        javax.swing.GroupLayout historyPanelLayout = new javax.swing.GroupLayout(historyPanel);
        historyPanel.setLayout(historyPanelLayout);
        historyPanelLayout.setHorizontalGroup(historyPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(historyPanelLayout.createSequentialGroup().addContainerGap()
                        .addGroup(historyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(hisPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(historyPanelLayout.createSequentialGroup()
                                        .addComponent(hisComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(dateTextField0, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(dateTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(his_Button).addContainerGap(293, Short.MAX_VALUE)))));
        historyPanelLayout.setVerticalGroup(historyPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(historyPanelLayout.createSequentialGroup().addContainerGap().addGroup(historyPanelLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(hisComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(dateTextField0, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(dateTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(his_Button))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(hisPanel1,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)));

        TabbedPane.addTab("?", historyPanel);

        javax.swing.GroupLayout lightPointPanelLayout = new javax.swing.GroupLayout(lightPointPanel);
        lightPointPanel.setLayout(lightPointPanelLayout);
        lightPointPanelLayout.setHorizontalGroup(lightPointPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 628, Short.MAX_VALUE));
        lightPointPanelLayout.setVerticalGroup(lightPointPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 370, Short.MAX_VALUE));

        TabbedPane.addTab("", lightPointPanel);

        disLabel.setText("?");

        disTextField.setText("?");

        disComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "", "" }));

        disButton.setText("");
        disButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                disButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout distencePanelLayout = new javax.swing.GroupLayout(distencePanel);
        distencePanel.setLayout(distencePanelLayout);
        distencePanelLayout.setHorizontalGroup(distencePanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(distencePanelLayout.createSequentialGroup().addContainerGap().addComponent(disLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(disTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(disComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(disButton)
                        .addContainerGap(365, Short.MAX_VALUE)));
        distencePanelLayout.setVerticalGroup(distencePanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(distencePanelLayout.createSequentialGroup().addContainerGap().addGroup(distencePanelLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(disLabel)
                        .addComponent(disTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(disComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(disButton)).addContainerGap(337, Short.MAX_VALUE)));

        TabbedPane.addTab("?", distencePanel);

        recomComboBox.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "??", "?", "", "?", "" }));

        recomButton.setText("");

        javax.swing.GroupLayout recommendationPanelLayout = new javax.swing.GroupLayout(recommendationPanel);
        recommendationPanel.setLayout(recommendationPanelLayout);
        recommendationPanelLayout.setHorizontalGroup(recommendationPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(recommendationPanelLayout.createSequentialGroup().addContainerGap()
                        .addComponent(recomComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(recomButton).addContainerGap(481, Short.MAX_VALUE)));
        recommendationPanelLayout.setVerticalGroup(
                recommendationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(recommendationPanelLayout.createSequentialGroup().addContainerGap()
                                .addGroup(recommendationPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(recomComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(recomButton))
                                .addContainerGap(337, Short.MAX_VALUE)));

        TabbedPane.addTab("??", recommendationPanel);

        accountLabel.setText("?");

        accountTextField.setText("?");

        switchAccountButton.setText("??");
        switchAccountButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                switchAccountButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(mainPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup().addContainerGap().addComponent(accountLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(accountTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(switchAccountButton)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addComponent(Separator, javax.swing.GroupLayout.Alignment.TRAILING));
        mainPanelLayout.setVerticalGroup(mainPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(Separator, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(accountLabel)
                                .addComponent(accountTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(switchAccountButton))
                        .addContainerGap()));

        docMenu.setBorder(null);
        docMenu.setText("");
        docMenu.setToolTipText("");

        docMenuItem0.setText("");
        docMenuItem0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                docMenuItem0ActionPerformed(evt);
            }
        });
        docMenu.add(docMenuItem0);

        docMenuItem1.setText("");
        docMenu.add(docMenuItem1);

        MenuBar.add(docMenu);

        sysMenu.setBorder(null);
        sysMenu.setText("");

        sysMenuItem0.setText("");
        sysMenu.add(sysMenuItem0);

        sysMenuItem1.setText("?");
        sysMenu.add(sysMenuItem1);

        MenuBar.add(sysMenu);

        helpMenu.setText("");
        MenuBar.add(helpMenu);

        setJMenuBar(MenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(TabbedPane).addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addComponent(TabbedPane)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void his_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_his_ButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_his_ButtonActionPerformed

    private void disButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_disButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_disButtonActionPerformed

    private void switchAccountButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_switchAccountButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_switchAccountButtonActionPerformed

    private void docMenuItem0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_docMenuItem0ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_docMenuItem0ActionPerformed

    /**
     * @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(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainUI.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 MainUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar MenuBar;
    private javax.swing.JSeparator Separator;
    private javax.swing.JTabbedPane TabbedPane;
    private javax.swing.JLabel accountLabel;
    private javax.swing.JTextField accountTextField;
    private javax.swing.JTextField dateTextField0;
    private javax.swing.JTextField dateTextField1;
    private javax.swing.JButton disButton;
    private javax.swing.JComboBox disComboBox;
    private javax.swing.JLabel disLabel;
    private javax.swing.JTextField disTextField;
    private javax.swing.JPanel distencePanel;
    private javax.swing.JMenu docMenu;
    private javax.swing.JMenuItem docMenuItem0;
    private javax.swing.JMenuItem docMenuItem1;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JComboBox hisComboBox;
    private javax.swing.JPanel hisPanel1;
    private javax.swing.JButton his_Button;
    private javax.swing.JPanel historyPanel;
    private javax.swing.JPanel lightPointPanel;
    private javax.swing.JPanel mainPagePanel;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JButton recomButton;
    private javax.swing.JComboBox recomComboBox;
    private javax.swing.JPanel recommendationPanel;
    private javax.swing.JButton switchAccountButton;
    private javax.swing.JMenu sysMenu;
    private javax.swing.JMenuItem sysMenuItem0;
    private javax.swing.JMenuItem sysMenuItem1;
    // End of variables declaration//GEN-END:variables

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == hisComboBox) {
            int index = hisComboBox.getSelectedIndex();
        }
    }

    private void initListener() {
        switchAccountButton.addActionListener(this);
        his_Button.addActionListener(this);
        disButton.addActionListener(this);
        recomButton.addActionListener(this);
        hisComboBox.addActionListener(this);
    }

    public static CategoryDataset createDataset() //?
    {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(10, "a", "?");
        dataset.setValue(20, "b", "");
        dataset.setValue(40, "c", "?");
        dataset.setValue(15, "d", "");
        return dataset;
    }

    public static JFreeChart createChart(CategoryDataset dataset) //?
    {
        JFreeChart chart = ChartFactory.createBarChart("hi", "", "?", dataset,
                PlotOrientation.VERTICAL, true, true, false); //JFreeChart
        chart.setTitle(new TextTitle("??", new Font("", Font.BOLD + Font.ITALIC, 20)));//???hi?
        CategoryPlot plot = (CategoryPlot) chart.getPlot();//?plot
        CategoryAxis categoryAxis = plot.getDomainAxis();//??
        categoryAxis.setLabelFont(new Font("", Font.BOLD, 12));//??
        return chart;
    }

    private void initChart() {

    }

}