private void analyzeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_analyzeButtonActionPerformed
        try
        {
            if (hoursList.getModel().getSize() != 0)
            {
                DefaultListModel hoursModel = (DefaultListModel)hoursList.getModel();
                hoursModel.clear();
            }
            if (dateList.getModel().getSize() != 0)
            {
                DefaultListModel dateModel = (DefaultListModel)dateList.getModel();
                dateModel.clear();
            }
            
            if (conn == null)
                throw new NullPointerException("No connection to database!");
            
            String selectedDevice = macList.getSelectedValue().toString().split("-")[0];
            
            ResultSet rs;
            String selectDatesForMAC = "SELECT DISTINCT(date) FROM `requests` WHERE source = '"+selectedDevice+"';";
            Statement st = conn.createStatement();
            
            rs = st.executeQuery(selectDatesForMAC);
            DefaultListModel<Date> datesInRangeForMAC = new DefaultListModel();
            ArrayList<Date> datesInRangeForMACList = new ArrayList<>();
            Date date;
            while (rs.next())
            {
                date = rs.getDate(1);
                datesInRangeForMAC.addElement(date);
                //dateTimeForMAC.put(date, new ArrayList<Integer>());
                datesInRangeForMACList.add(date);
            }
            dateList.setModel(datesInRangeForMAC);
            
            String selectTimestampsForDate;
            TreeMap<Date,ArrayList<Timestamp>> dateTimeForMAC = new TreeMap<>();
            for (Date dateInRange : datesInRangeForMACList)
            {
                selectTimestampsForDate = "SELECT timestamp FROM `requests` "
                                        + "WHERE source = '"+selectedDevice+"' AND date = '"+dateInRange+"'";
                rs = st.executeQuery(selectTimestampsForDate);
                ArrayList<Timestamp> times = new ArrayList<>();
                while (rs.next())
                    times.add(rs.getTimestamp(1));
                dateTimeForMAC.put(dateInRange, times);
            }
            
            CategoryDataset ds = getDatasetFromDateTime(dateTimeForMAC);
            totalTimeLabel.setText("Total time: "+(totalTime > 100 ? (totalTime/60)+":"+(totalTime%60)+" hrs":totalTime+" min"));
            //new BarChart(graphPanel, "Total time by day", ds, "Day", "Minutes");
            new StackedBarChart(graphPanel, "Total time by day", ds, "Day", "Minutes");
            
        } catch (NullPointerException e) {
            JOptionPane.showMessageDialog(this, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
            this.dispose();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_analyzeButtonActionPerformed