4 Replies Latest reply: Sep 13, 2012 3:58 AM by DarrylBurke RSS

    internal frame listener

    955780
      so, im doing a jdesktopPane with some frames inside of it, i just want 1 instance of everyframe so i want to listen to the closing of the frame so i can update a boolean variable, but i dont know how to listen to the closing, here is my code

      private void bitacoraItemActionPerformed(java.awt.event.ActionEvent evt) {                                             
            
              if(!bitacoraBool){
                  Bitacora = new javax.swing.JInternalFrame();
                  Pendientes = new javax.swing.JInternalFrame();
                  Registro = new javax.swing.JInternalFrame();
                  BitacoraTab = new javax.swing.JTabbedPane();
             
             
                  Bitacora.setClosable(true);
                  Bitacora.setIconifiable(true);
                  Bitacora.setMaximizable(true);
                  Bitacora.setResizable(true);
                  Bitacora.setTitle("Bitacora");
                  Bitacora.setVisible(true);
                  Bitacora.addInternalFrameListener(this);
      the last line is what i am not sure of, here is the complete code,
      /*
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
      package my.Navman;
      
      
      
      /**
       *
       * @author pato
       */
      public class NavmanUI extends javax.swing.JFrame {
      
          /**
           * Creates new form NavmanUI
           */
          public NavmanUI() {
              initComponents();
          }
      
          /**
           * 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">                          
          private void initComponents() {
      
              jDesktopPane1 = new javax.swing.JDesktopPane();
              jMenuBar1 = new javax.swing.JMenuBar();
              fileMenu = new javax.swing.JMenu();
              bitacoraItem = new javax.swing.JMenuItem();
              kmGpsItem = new javax.swing.JMenuItem();
              sabaMaestraItem = new javax.swing.JMenuItem();
              facturaItem = new javax.swing.JMenuItem();
              jSeparator1 = new javax.swing.JPopupMenu.Separator();
              salirItem = new javax.swing.JMenuItem();
              uploadMenu = new javax.swing.JMenu();
              catalogoItem = new javax.swing.JMenuItem();
              encendidosItem = new javax.swing.JMenuItem();
              temperaturaItem = new javax.swing.JMenuItem();
              resumenItem = new javax.swing.JMenuItem();
      
              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
              setTitle("Navman");
      
              jDesktopPane1.setBackground(new java.awt.Color(204, 204, 255));
      
              fileMenu.setMnemonic(java.awt.event.KeyEvent.VK_ALT);
              fileMenu.setText("File");
      
              bitacoraItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
              bitacoraItem.setText("Bitacora");
              bitacoraItem.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      bitacoraItemActionPerformed(evt);
                  }
              });
              fileMenu.add(bitacoraItem);
      
              kmGpsItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_K, java.awt.event.InputEvent.CTRL_MASK));
              kmGpsItem.setText("Km GPS");
              kmGpsItem.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      kmGpsItemActionPerformed(evt);
                  }
              });
              fileMenu.add(kmGpsItem);
      
              sabaMaestraItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
              sabaMaestraItem.setText("Sabana Maestra");
              sabaMaestraItem.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      sabaMaestraItemActionPerformed(evt);
                  }
              });
              fileMenu.add(sabaMaestraItem);
      
              facturaItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK));
              facturaItem.setText("Factura");
              fileMenu.add(facturaItem);
              fileMenu.add(jSeparator1);
      
              salirItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
              salirItem.setText("Salir");
              salirItem.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      salirItemActionPerformed(evt);
                  }
              });
              fileMenu.add(salirItem);
      
              jMenuBar1.add(fileMenu);
      
              uploadMenu.setText("Upload");
      
              catalogoItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
              catalogoItem.setText("Catalogo");
              catalogoItem.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      catalogoItemActionPerformed(evt);
                  }
              });
              uploadMenu.add(catalogoItem);
      
              encendidosItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.ALT_MASK));
              encendidosItem.setText("Diario Encendidos");
              encendidosItem.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      encendidosItemActionPerformed(evt);
                  }
              });
              uploadMenu.add(encendidosItem);
      
              temperaturaItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK));
              temperaturaItem.setText("Temperatura");
              temperaturaItem.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      temperaturaItemActionPerformed(evt);
                  }
              });
              uploadMenu.add(temperaturaItem);
      
              resumenItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.ALT_MASK));
              resumenItem.setText("Resumenes");
              resumenItem.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      resumenItemActionPerformed(evt);
                  }
              });
              uploadMenu.add(resumenItem);
      
              jMenuBar1.add(uploadMenu);
      
              setJMenuBar(jMenuBar1);
      
              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 673, Short.MAX_VALUE)
              );
              layout.setVerticalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE)
              );
      
              jDesktopPane1.getAccessibleContext().setAccessibleName("");
      
              pack();
          }// </editor-fold>                        
      
          private void bitacoraItemActionPerformed(java.awt.event.ActionEvent evt) {                                             
            
              if(!bitacoraBool){
                  Bitacora = new javax.swing.JInternalFrame();
                  Pendientes = new javax.swing.JInternalFrame();
                  Registro = new javax.swing.JInternalFrame();
                  BitacoraTab = new javax.swing.JTabbedPane();
             
             
                  Bitacora.setClosable(true);
                  Bitacora.setIconifiable(true);
                  Bitacora.setMaximizable(true);
                  Bitacora.setResizable(true);
                  Bitacora.setTitle("Bitacora");
                  Bitacora.setVisible(true);
                  Bitacora.addInternalFrameListener(this);
      
                  BitacoraTab.setTabPlacement(javax.swing.JTabbedPane.BOTTOM);
      
                  Pendientes.setVisible(true);
      
                  javax.swing.GroupLayout PendientesLayout = new javax.swing.GroupLayout(Pendientes.getContentPane());
                  Pendientes.getContentPane().setLayout(PendientesLayout);
                  PendientesLayout.setHorizontalGroup(
                      PendientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGap(0, 213, Short.MAX_VALUE)
                  );
                  PendientesLayout.setVerticalGroup(
                      PendientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGap(0, 284, Short.MAX_VALUE)
                  );
      
                  BitacoraTab.addTab("Pendientes", Pendientes);
      
                  Registro.setVisible(true);
      
                  javax.swing.GroupLayout RegistroLayout = new javax.swing.GroupLayout(Registro.getContentPane());
                  Registro.getContentPane().setLayout(RegistroLayout);
                  RegistroLayout.setHorizontalGroup(
                      RegistroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGap(0, 213, Short.MAX_VALUE)
                  );
                  RegistroLayout.setVerticalGroup(
                      RegistroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGap(0, 284, Short.MAX_VALUE)
                  );
      
                  BitacoraTab.addTab("Registro", Registro);
      
                  javax.swing.GroupLayout BitacoraLayout = new javax.swing.GroupLayout(Bitacora.getContentPane());
                  Bitacora.getContentPane().setLayout(BitacoraLayout);
                  BitacoraLayout.setHorizontalGroup(
                      BitacoraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(BitacoraTab)
                  );
                  BitacoraLayout.setVerticalGroup(
                      BitacoraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(BitacoraTab, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)
                  );
      
                  BitacoraTab.getAccessibleContext().setAccessibleName("Registro");
      
                  Bitacora.setBounds(40, 30, 250, 370);
                  jDesktopPane1.add(Bitacora, javax.swing.JLayeredPane.DEFAULT_LAYER);
                  bitacoraBool = true;
              }else
              {
             
              }
             
          }                                            
      
          private void catalogoItemActionPerformed(java.awt.event.ActionEvent evt) {                                             
              // TODO add your handling code here:
          }                                            
      
          private void kmGpsItemActionPerformed(java.awt.event.ActionEvent evt) {                                          
              // TODO add your handling code here:
          }                                         
      
          private void sabaMaestraItemActionPerformed(java.awt.event.ActionEvent evt) {                                                
              // TODO add your handling code here:
          }                                               
      
          private void encendidosItemActionPerformed(java.awt.event.ActionEvent evt) {                                               
              // TODO add your handling code here:
          }                                              
      
          private void temperaturaItemActionPerformed(java.awt.event.ActionEvent evt) {                                                
              // TODO add your handling code here:
          }                                               
      
          private void resumenItemActionPerformed(java.awt.event.ActionEvent evt) {                                            
              // TODO add your handling code here:
          }                                           
      
          private void salirItemActionPerformed(java.awt.event.ActionEvent evt) {                                          
              // TODO add your handling code here:
              System.exit(0);
          }                                         
      
          /**
           * @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(NavmanUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
              } catch (InstantiationException ex) {
                  java.util.logging.Logger.getLogger(NavmanUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
              } catch (IllegalAccessException ex) {
                  java.util.logging.Logger.getLogger(NavmanUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
              } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                  java.util.logging.Logger.getLogger(NavmanUI.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 NavmanUI().setVisible(true);
                  }
              });
          }
          // Variables declaration - do not modify                     
          private javax.swing.JMenuItem bitacoraItem;
          private javax.swing.JMenuItem catalogoItem;
          private javax.swing.JMenuItem encendidosItem;
          private javax.swing.JMenuItem facturaItem;
          private javax.swing.JMenu fileMenu;
          private javax.swing.JDesktopPane jDesktopPane1;
          private javax.swing.JMenuBar jMenuBar1;
          private javax.swing.JPopupMenu.Separator jSeparator1;
          private javax.swing.JMenuItem kmGpsItem;
          private javax.swing.JMenuItem resumenItem;
          private javax.swing.JMenuItem sabaMaestraItem;
          private javax.swing.JMenuItem salirItem;
          private javax.swing.JMenuItem temperaturaItem;
          private javax.swing.JMenu uploadMenu;
          // End of variables declaration                   
          private javax.swing.JInternalFrame Bitacora;
          private javax.swing.JInternalFrame Pendientes;
          private javax.swing.JInternalFrame Registro;
          private javax.swing.JTabbedPane BitacoraTab;
          private boolean bitacoraBool = false;
          
         
        • 1. Re: internal frame listener
          jduprez
          Well if your class NavmanUI is used as an InternalFrameListener , it must implement the InternalFrameListener interface, that is, provide implementation for all methods of this interface ( internalFrameClosed(InternalFrameEvent e) etc...).
          The code you posted is incomplete (for example it is missing a final brace } ), and probably doesn't compile...
          • 2. Re: internal frame listener
            DarrylBurke
            Moved from Java Programming. Please take the trouble to find an appropriate section before you start a thread.

            db
            • 3. Re: internal frame listener
              955780
              jduprez wrote:
              Well if your class NavmanUI is used as an InternalFrameListener , it must implement the InternalFrameListener interface, that is, provide implementation for all methods of this interface ( internalFrameClosed(InternalFrameEvent e) etc...).
              Yea, Eclipse tells me that, but when i get an error telling me that the class should be abstract, i have no idea what that is, never worked with abstract classes.

              The code you posted is incomplete (for example it is missing a final brace } ), and probably doesn't compile...
              That must be just a mistake while copying it here.

              THX
              • 4. Re: internal frame listener
                DarrylBurke
                http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html
                http://docs.oracle.com/javase/tutorial/java/IandI/usinginterface.html

                db