Vista.Main.java Source code

Java tutorial

Introduction

Here is the source code for Vista.Main.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 Vista;

import Controlador.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.Vector;
import javax.swing.JDialog;
import javax.swing.JInternalFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.xy.DefaultXYDataset;
import org.jfree.data.xy.XYDataset;
import Modelo.Usuarios;

/**
 *
 * @author urias
 */
public class Main extends javax.swing.JFrame {

    private Color arduino = new Color(1, 160, 153);
    ControladorLecturas controladorLecturas;
    private boolean isNetworkAvaliable;
    private boolean sesionIniciada = false;
    private ControladorUsuarios controladorUsuarios;
    public Usuarios usuario;

    /**
     * Creates new form Main
     */
    public Main() {
        initComponents();
        isNetworkAvaliable = Internet.isNetAvailable(statusPanel, statusLabel);
        elementosDeSesion();
        controladorUsuarios = new ControladorUsuarios();
    }

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

        desktopPane = new javax.swing.JDesktopPane();
        statusPanel = new javax.swing.JPanel();
        statusLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        infoLabel = new javax.swing.JLabel();
        dcInicio = new datechooser.beans.DateChooserCombo();
        jLabel3 = new javax.swing.JLabel();
        dcFinal = new datechooser.beans.DateChooserCombo();
        jLabel4 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        exitMenuItem = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        itemIniciarSesion = new javax.swing.JMenuItem();
        itemCerrarSesion = new javax.swing.JMenuItem();
        itemRegistrarNuevoUsuario = new javax.swing.JMenuItem();
        itemDarDeBajaMiUsuario = new javax.swing.JMenuItem();
        menuTabla = new javax.swing.JMenu();
        itemTablaTemperatura = new javax.swing.JMenuItem();
        itemTablaHumedadAmbiental = new javax.swing.JMenuItem();
        itemTablaHumedadSuelo = new javax.swing.JMenuItem();
        menuGrafico = new javax.swing.JMenu();
        itemGraficoTemperatura = new javax.swing.JMenuItem();
        itemGraficoHumedadAmbiental = new javax.swing.JMenuItem();
        itemGraficoHumedadSuelo = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SAMI - Sistema para la Automatizacion y Monitoreo de Invernaderos");
        setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);

        statusPanel.setBackground(java.awt.SystemColor.desktop);

        statusLabel.setForeground(new java.awt.Color(254, 254, 254));
        statusLabel.setText("Status");

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout
                .setHorizontalGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
        statusPanelLayout
                .setVerticalGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout
                                .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(statusLabel)));

        jPanel2.setBackground(java.awt.SystemColor.desktop);

        infoLabel.setForeground(new java.awt.Color(254, 254, 254));
        infoLabel.setText("Inicia sesin para continuar...");

        dcInicio.setCurrentView(new datechooser.view.appearance.AppearancesList("Light",
                new datechooser.view.appearance.ViewAppearance("custom",
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Ubuntu", java.awt.Font.PLAIN, 11),
                                new java.awt.Color(76, 76, 76), new java.awt.Color(0, 0, 255), false, true,
                                new datechooser.view.appearance.swing.ButtonPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Ubuntu", java.awt.Font.PLAIN, 11),
                                new java.awt.Color(76, 76, 76), new java.awt.Color(0, 0, 255), true, true,
                                new datechooser.view.appearance.swing.ButtonPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Ubuntu", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 255),
                                new java.awt.Color(0, 0, 255), false, true,
                                new datechooser.view.appearance.swing.ButtonPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Ubuntu", java.awt.Font.PLAIN, 11),
                                new java.awt.Color(128, 128, 128), new java.awt.Color(0, 0, 255), false, true,
                                new datechooser.view.appearance.swing.LabelPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Ubuntu", java.awt.Font.PLAIN, 11),
                                new java.awt.Color(76, 76, 76), new java.awt.Color(0, 0, 255), false, true,
                                new datechooser.view.appearance.swing.LabelPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Ubuntu", java.awt.Font.PLAIN, 11),
                                new java.awt.Color(76, 76, 76), new java.awt.Color(255, 0, 0), false, false,
                                new datechooser.view.appearance.swing.ButtonPainter()),
                        (datechooser.view.BackRenderer) null, false, true)));
        dcInicio.setBorder(null);
        dcInicio.setMaxDate(java.util.Calendar.getInstance());
        dcInicio.setShowOneMonth(true);

        jLabel3.setForeground(new java.awt.Color(254, 254, 254));
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel3.setText("Fecha final");

        dcFinal.setCurrentView(new datechooser.view.appearance.AppearancesList("Light",
                new datechooser.view.appearance.ViewAppearance("custom",
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Ubuntu", java.awt.Font.PLAIN, 11),
                                new java.awt.Color(76, 76, 76), new java.awt.Color(0, 0, 255), false, true,
                                new datechooser.view.appearance.swing.ButtonPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Ubuntu", java.awt.Font.PLAIN, 11),
                                new java.awt.Color(76, 76, 76), new java.awt.Color(0, 0, 255), true, true,
                                new datechooser.view.appearance.swing.ButtonPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Ubuntu", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 255),
                                new java.awt.Color(0, 0, 255), false, true,
                                new datechooser.view.appearance.swing.ButtonPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Ubuntu", java.awt.Font.PLAIN, 11),
                                new java.awt.Color(128, 128, 128), new java.awt.Color(0, 0, 255), false, true,
                                new datechooser.view.appearance.swing.LabelPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Ubuntu", java.awt.Font.PLAIN, 11),
                                new java.awt.Color(76, 76, 76), new java.awt.Color(0, 0, 255), false, true,
                                new datechooser.view.appearance.swing.LabelPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Ubuntu", java.awt.Font.PLAIN, 11),
                                new java.awt.Color(76, 76, 76), new java.awt.Color(255, 0, 0), false, false,
                                new datechooser.view.appearance.swing.ButtonPainter()),
                        (datechooser.view.BackRenderer) null, false, true)));
        dcFinal.setBorder(null);
        dcFinal.setMaxDate(java.util.Calendar.getInstance());
        dcFinal.setShowOneMonth(true);

        jLabel4.setForeground(new java.awt.Color(254, 254, 254));
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel4.setText("Fecha de Inicio");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout
                .setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel4).addGap(4, 4, 4)
                                .addComponent(dcInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 106,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel3).addGap(4, 4, 4)
                                .addComponent(dcFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 108,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(infoLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(infoLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 22,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(dcInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 22,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                        .addComponent(dcFinal, javax.swing.GroupLayout.Alignment.TRAILING,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 22,
                                javax.swing.GroupLayout.PREFERRED_SIZE)));

        fileMenu.setMnemonic('A');
        fileMenu.setText("Archivo");

        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        jMenu1.setText("Usuarios");

        itemIniciarSesion.setText("Iniciar Sesin");
        itemIniciarSesion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemIniciarSesionActionPerformed(evt);
            }
        });
        jMenu1.add(itemIniciarSesion);

        itemCerrarSesion.setText("Cerrar Sesin");
        itemCerrarSesion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemCerrarSesionActionPerformed(evt);
            }
        });
        jMenu1.add(itemCerrarSesion);

        itemRegistrarNuevoUsuario.setText("Registrar nuevo usuario");
        itemRegistrarNuevoUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemRegistrarNuevoUsuarioActionPerformed(evt);
            }
        });
        jMenu1.add(itemRegistrarNuevoUsuario);

        itemDarDeBajaMiUsuario.setText("Dar de baja mi usuario");
        itemDarDeBajaMiUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemDarDeBajaMiUsuarioActionPerformed(evt);
            }
        });
        jMenu1.add(itemDarDeBajaMiUsuario);

        menuBar.add(jMenu1);

        menuTabla.setText("Tabla");
        menuTabla.setEnabled(false);

        itemTablaTemperatura.setText("Temperatura Ambiental");
        itemTablaTemperatura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemTablaTemperaturaActionPerformed(evt);
            }
        });
        menuTabla.add(itemTablaTemperatura);

        itemTablaHumedadAmbiental.setText("Humedad Ambiental");
        itemTablaHumedadAmbiental.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemTablaHumedadAmbientalActionPerformed(evt);
            }
        });
        menuTabla.add(itemTablaHumedadAmbiental);

        itemTablaHumedadSuelo.setText("Humedad del Suelo");
        itemTablaHumedadSuelo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemTablaHumedadSueloActionPerformed(evt);
            }
        });
        menuTabla.add(itemTablaHumedadSuelo);

        menuBar.add(menuTabla);

        menuGrafico.setText("Grafico");
        menuGrafico.setEnabled(false);

        itemGraficoTemperatura.setText("Temperatura Ambiental");
        itemGraficoTemperatura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemGraficoTemperaturaActionPerformed(evt);
            }
        });
        menuGrafico.add(itemGraficoTemperatura);

        itemGraficoHumedadAmbiental.setText("Humedad Ambiental");
        itemGraficoHumedadAmbiental.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemGraficoHumedadAmbientalActionPerformed(evt);
            }
        });
        menuGrafico.add(itemGraficoHumedadAmbiental);

        itemGraficoHumedadSuelo.setText("Humedad del Suelo");
        itemGraficoHumedadSuelo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemGraficoHumedadSueloActionPerformed(evt);
            }
        });
        menuGrafico.add(itemGraficoHumedadSuelo);

        menuBar.add(menuGrafico);

        helpMenu.setMnemonic('y');
        helpMenu.setText("Ayuda");

        aboutMenuItem.setMnemonic('a');
        aboutMenuItem.setText("Acerca de SAMI");
        helpMenu.add(aboutMenuItem);

        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(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 851, Short.MAX_VALUE)
                .addComponent(statusPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, 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(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 445, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(statusPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)));

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

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void itemIniciarSesionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemIniciarSesionActionPerformed
        // TODO add your handling code here:
        IniciarSesion iniciarSesion = new IniciarSesion(this, true);
        iniciarSesion.setLocationRelativeTo(this);
        iniciarSesion.setVisible(isNetworkAvaliable);
        sesionIniciada = iniciarSesion.autenticado;
        usuario = iniciarSesion.usuario;
        iniciarSesion.dispose();
        elementosDeSesion();
    }//GEN-LAST:event_itemIniciarSesionActionPerformed

    private void itemCerrarSesionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemCerrarSesionActionPerformed
        // TODO add your handling code here:
        sesionIniciada = false;
        statusLabel.setText("Hasta pronto " + usuario.getUsuario());
        statusPanel.setBackground(Color.blue);
        elementosDeSesion();
    }//GEN-LAST:event_itemCerrarSesionActionPerformed

    private void itemGraficoTemperaturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemGraficoTemperaturaActionPerformed
        // TODO add your handling code here:
        controladorLecturas = new ControladorLecturas(dcInicio.getCurrent().getTime(),
                dcFinal.getCurrent().getTime());
        JInternalFrame jInternalFrame = controladorLecturas.graficoTemperatura();
        desktopPane.add(jInternalFrame);
        jInternalFrame.setVisible(true);
    }//GEN-LAST:event_itemGraficoTemperaturaActionPerformed

    private void itemGraficoHumedadAmbientalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemGraficoHumedadAmbientalActionPerformed
        // TODO add your handling code here:
        controladorLecturas = new ControladorLecturas(dcInicio.getCurrent().getTime(),
                dcFinal.getCurrent().getTime());
        JInternalFrame jInternalFrame = controladorLecturas.graficoHumedadAmbiental();
        desktopPane.add(jInternalFrame);
        jInternalFrame.setVisible(true);
    }//GEN-LAST:event_itemGraficoHumedadAmbientalActionPerformed

    private void itemGraficoHumedadSueloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemGraficoHumedadSueloActionPerformed
        // TODO add your handling code here:
        controladorLecturas = new ControladorLecturas(dcInicio.getCurrent().getTime(),
                dcFinal.getCurrent().getTime());
        JInternalFrame jInternalFrame = controladorLecturas.graficoHumedadSuelo();
        desktopPane.add(jInternalFrame);
        jInternalFrame.setVisible(true);
    }//GEN-LAST:event_itemGraficoHumedadSueloActionPerformed

    private void itemTablaTemperaturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemTablaTemperaturaActionPerformed
        // TODO add your handling code here:
        controladorLecturas = new ControladorLecturas(dcInicio.getCurrent().getTime(),
                dcFinal.getCurrent().getTime());
        JInternalFrame jInternalFrame = new Tabla(controladorLecturas.tablaTemperatura(),
                "Tabla de Temperatura Ambiental");
        desktopPane.add(jInternalFrame);
        jInternalFrame.setVisible(true);
    }//GEN-LAST:event_itemTablaTemperaturaActionPerformed

    private void itemTablaHumedadAmbientalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemTablaHumedadAmbientalActionPerformed
        // TODO add your handling code here:
        controladorLecturas = new ControladorLecturas(dcInicio.getCurrent().getTime(),
                dcFinal.getCurrent().getTime());
        JInternalFrame jInternalFrame = new Tabla(controladorLecturas.tablaHumedadAmbiental(),
                "Tabla de Humedad Ambiental");
        desktopPane.add(jInternalFrame);
        jInternalFrame.setVisible(true);
    }//GEN-LAST:event_itemTablaHumedadAmbientalActionPerformed

    private void itemTablaHumedadSueloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemTablaHumedadSueloActionPerformed
        // TODO add your handling code here:
        controladorLecturas = new ControladorLecturas(dcInicio.getCurrent().getTime(),
                dcFinal.getCurrent().getTime());
        JInternalFrame jInternalFrame = new Tabla(controladorLecturas.tablaHumedadSuelo(),
                "Tabla de Humedad del Suelo");
        desktopPane.add(jInternalFrame);
        jInternalFrame.setVisible(true);
    }//GEN-LAST:event_itemTablaHumedadSueloActionPerformed

    private void itemRegistrarNuevoUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemRegistrarNuevoUsuarioActionPerformed
        // TODO add your handling code here:
        NuevoUsuario nuevoUsuario = new NuevoUsuario(this, true);
        nuevoUsuario.setLocationRelativeTo(this);
        nuevoUsuario.setVisible(true);
        statusPanel.setBackground(arduino);
        statusLabel.setText("Alta de usuario exitosa");
        nuevoUsuario.dispose();
    }//GEN-LAST:event_itemRegistrarNuevoUsuarioActionPerformed

    private void itemDarDeBajaMiUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemDarDeBajaMiUsuarioActionPerformed
        // TODO add your handling code here:
        BajaUsuario bajaUsuario = new BajaUsuario(this, true);
        bajaUsuario.setVisible(true);
        if (usuario.getContrasena().equals(bajaUsuario.password)) {
            controladorUsuarios.bajaUsuarios(usuario);
        }
        bajaUsuario.dispose();
        sesionIniciada = false;
        elementosDeSesion();
        statusLabel.setText("Adios.....");
    }//GEN-LAST:event_itemDarDeBajaMiUsuarioActionPerformed

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

    private void elementosDeSesion() {
        if (sesionIniciada) {
            controladorLecturas = new ControladorLecturas(dcInicio.getCurrent().getTime(),
                    dcFinal.getCurrent().getTime());
            infoLabel.setText("Ultimo Registro el " + controladorLecturas.ultimaLectura().getFecha().toString()
                    + " a las " + controladorLecturas.ultimaLectura().getHora().toString() + " horas, Temperatura: "
                    + controladorLecturas.ultimaLectura().getTemperatura().toString() + ", Humedad Ambiental: "
                    + controladorLecturas.ultimaLectura().getHumedadambiente().toString() + ", Humedad del suelo: "
                    + controladorLecturas.ultimaLectura().getHumedadsuelo().toString());
            statusPanel.setBackground(arduino);
            statusLabel.setText("Bienvenido " + usuario.getUsuario());
        } else {
            infoLabel.setText("Inicia sesin para continuar...");
        }
        itemIniciarSesion.setVisible(!sesionIniciada);
        itemCerrarSesion.setVisible(sesionIniciada);
        itemRegistrarNuevoUsuario.setVisible(sesionIniciada);
        itemDarDeBajaMiUsuario.setVisible(sesionIniciada);
        menuTabla.setEnabled(sesionIniciada);
        menuGrafico.setEnabled(sesionIniciada);
        dcFinal.setEnabled(sesionIniciada);
        dcInicio.setEnabled(sesionIniciada);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private datechooser.beans.DateChooserCombo dcFinal;
    private datechooser.beans.DateChooserCombo dcInicio;
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JLabel infoLabel;
    private javax.swing.JMenuItem itemCerrarSesion;
    private javax.swing.JMenuItem itemDarDeBajaMiUsuario;
    private javax.swing.JMenuItem itemGraficoHumedadAmbiental;
    private javax.swing.JMenuItem itemGraficoHumedadSuelo;
    private javax.swing.JMenuItem itemGraficoTemperatura;
    private javax.swing.JMenuItem itemIniciarSesion;
    private javax.swing.JMenuItem itemRegistrarNuevoUsuario;
    private javax.swing.JMenuItem itemTablaHumedadAmbiental;
    private javax.swing.JMenuItem itemTablaHumedadSuelo;
    private javax.swing.JMenuItem itemTablaTemperatura;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenu menuGrafico;
    private javax.swing.JMenu menuTabla;
    private javax.swing.JLabel statusLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

}