Results 1 to 11 of 11
  1. #1
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default dispose all using Vector ?

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /*
     * UserForm.java
     *
     * Created on Aug 22, 2009, 4:15:41 PM
     */
    
    package gui;
    import com.mysql.jdbc.Connection;
    import java.sql.*;
    import javax.swing.JFrame;
    /**
     *
     * @author admin
     */
    public class UserForm extends javax.swing.JFrame {
    
        /** Creates new form UserForm */
        public UserForm() {
            initComponents();
            this.setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);
            /* **untuk full screen
             GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
             gd.setFullScreenWindow(this);
            */
    
        }
        private Connection conn;
        private ResultSet rs;
        private Statement stmt;
        private String sql = "";
    
        /** 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() {
    
            jPanel2 = new javax.swing.JPanel();
            jMenuBar2 = new javax.swing.JMenuBar();
            jMenu3 = new javax.swing.JMenu();
            jMenu4 = new javax.swing.JMenu();
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenu1 = new javax.swing.JMenu();
            jMenuItem1 = new javax.swing.JMenuItem();
            jMenuItem2 = new javax.swing.JMenuItem();
            jSeparator1 = new javax.swing.JSeparator();
            jMenuItem3 = new javax.swing.JMenuItem();
            jMenu2 = new javax.swing.JMenu();
            jMenuItem4 = new javax.swing.JMenuItem();
            jMenuItem5 = new javax.swing.JMenuItem();
            jSeparator3 = new javax.swing.JSeparator();
            jMenuItem6 = new javax.swing.JMenuItem();
            jSeparator2 = new javax.swing.JSeparator();
            jMenuItem8 = new javax.swing.JMenuItem();
            jMenu5 = new javax.swing.JMenu();
            jMenuItem10 = new javax.swing.JMenuItem();
            jSeparator4 = new javax.swing.JSeparator();
            jMenuItem7 = new javax.swing.JMenuItem();
            jMenuItem9 = new javax.swing.JMenuItem();
    
            jPanel2.setName("jPanel2"); // NOI18N
    
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
    
            jMenuBar2.setName("jMenuBar2"); // NOI18N
    
            jMenu3.setText("File");
            jMenu3.setName("jMenu3"); // NOI18N
            jMenuBar2.add(jMenu3);
    
            jMenu4.setText("Edit");
            jMenu4.setName("jMenu4"); // NOI18N
            jMenuBar2.add(jMenu4);
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Aplikasi Dunia Lamp Elektronik");
    
            jMenuBar1.setName("jMenuBar1"); // NOI18N
    
            jMenu1.setText("Start");
            jMenu1.setName("jMenu1"); // NOI18N
    
            jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/images/key.png"))); // NOI18N
            jMenuItem1.setText("Ubah Password");
            jMenuItem1.setName("jMenuItem1"); // NOI18N
            jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ubahPassword(evt);
                }
            });
            jMenu1.add(jMenuItem1);
    
            jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/images/logout.png"))); // NOI18N
            jMenuItem2.setText("Logout");
            jMenuItem2.setName("jMenuItem2"); // NOI18N
            jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    logoutEvent(evt);
                }
            });
            jMenu1.add(jMenuItem2);
    
            jSeparator1.setName("jSeparator1"); // NOI18N
            jMenu1.add(jSeparator1);
    
            jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
            jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/images/exit.png"))); // NOI18N
            jMenuItem3.setText("Keluar");
            jMenuItem3.setName("jMenuItem3"); // NOI18N
            jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    keluarEvent(evt);
                }
            });
            jMenu1.add(jMenuItem3);
    
            jMenuBar1.add(jMenu1);
    
            jMenu2.setText("Data");
            jMenu2.setName("jMenu2"); // NOI18N
    
            jMenuItem4.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\admin\\My Documents\\NetBeansProjects\\DuniaLamp\\src\\gui\\images\\jenis.jpg")); // NOI18N
            jMenuItem4.setText("Jenis Barang");
            jMenuItem4.setName("jMenuItem4"); // NOI18N
            jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jMenuItem4ActionPerformed(evt);
                }
            });
            jMenu2.add(jMenuItem4);
    
            jMenuItem5.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\admin\\My Documents\\NetBeansProjects\\DuniaLamp\\src\\gui\\images\\barang.jpg")); // NOI18N
            jMenuItem5.setText("Barang");
            jMenuItem5.setName("jMenuItem5"); // NOI18N
            jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jMenuItem5ActionPerformed(evt);
                }
            });
            jMenu2.add(jMenuItem5);
    
            jSeparator3.setName("jSeparator3"); // NOI18N
            jMenu2.add(jSeparator3);
    
            jMenuItem6.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\admin\\My Documents\\NetBeansProjects\\DuniaLamp\\src\\gui\\images\\pelanggan.png")); // NOI18N
            jMenuItem6.setText("Pelanggan");
            jMenuItem6.setName("jMenuItem6"); // NOI18N
            jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnPelanggan(evt);
                }
            });
            jMenu2.add(jMenuItem6);
    
            jSeparator2.setName("jSeparator2"); // NOI18N
            jMenu2.add(jSeparator2);
    
            jMenuItem8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/images/order.png"))); // NOI18N
            jMenuItem8.setText("Buat Pemesanan");
            jMenuItem8.setName("jMenuItem8"); // NOI18N
            jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    buatPemesanan(evt);
                }
            });
            jMenu2.add(jMenuItem8);
    
            jMenuBar1.add(jMenu2);
    
            jMenu5.setText("Laporan");
            jMenu5.setName("jMenu5"); // NOI18N
    
            jMenuItem10.setText("Stok");
            jMenuItem10.setName("jMenuItem10"); // NOI18N
            jMenu5.add(jMenuItem10);
    
            jSeparator4.setName("jSeparator4"); // NOI18N
            jMenu5.add(jSeparator4);
    
            jMenuItem7.setText("Pemesanan");
            jMenuItem7.setName("jMenuItem7"); // NOI18N
            jMenu5.add(jMenuItem7);
    
            jMenuItem9.setText("Pengiriman");
            jMenuItem9.setName("jMenuItem9"); // NOI18N
            jMenu5.add(jMenuItem9);
    
            jMenuBar1.add(jMenu5);
    
            setJMenuBar(jMenuBar1);
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 428, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 238, Short.MAX_VALUE)
            );
    
            pack();
        }// </editor-fold>                        
    
        private void logoutEvent(java.awt.event.ActionEvent evt) {                             
            // TODO add your handling code here:
            dispose();
            new LoginForm().setVisible(true);
        }                            
    
        private void keluarEvent(java.awt.event.ActionEvent evt) {                             
            // TODO add your handling code here:
            System.exit(0);
        }                            
    
        private void ubahPassword(java.awt.event.ActionEvent evt) {                              
            // TODO add your handling code here:
            new UbahPassword().setVisible(true);
        }                             
    
        private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
            // TODO add your handling code here:
            new JenisBarang().setVisible(true);
        }                                          
    
        private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {                                           
            // TODO add your handling code here:
            new Barang().setVisible(true);
        }                                          
    
        private void btnPelanggan(java.awt.event.ActionEvent evt) {                              
            // TODO add your handling code here:
            new Pelanggan().setVisible(true);
        }                             
    
        private void buatPemesanan(java.awt.event.ActionEvent evt) {                               
            // TODO add your handling code here:
            new BuatPemesanan().setVisible(true);
        }                              
    
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new UserForm().setVisible(true);
                }
            });
        }
        /**
        * @param args the command line arguments
        */
    
        // Variables declaration - do not modify                     
        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.JMenuBar jMenuBar1;
        private javax.swing.JMenuBar jMenuBar2;
        private javax.swing.JMenuItem jMenuItem1;
        private javax.swing.JMenuItem jMenuItem10;
        private javax.swing.JMenuItem jMenuItem2;
        private javax.swing.JMenuItem jMenuItem3;
        private javax.swing.JMenuItem jMenuItem4;
        private javax.swing.JMenuItem jMenuItem5;
        private javax.swing.JMenuItem jMenuItem6;
        private javax.swing.JMenuItem jMenuItem7;
        private javax.swing.JMenuItem jMenuItem8;
        private javax.swing.JMenuItem jMenuItem9;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JSeparator jSeparator1;
        private javax.swing.JSeparator jSeparator2;
        private javax.swing.JSeparator jSeparator3;
        private javax.swing.JSeparator jSeparator4;
        // End of variables declaration                   
    }
    That's my code.
    I wanna dispose all except Login Form when I click LogOut Menu :(, but It's only close the current JFrame, the others active JFrames don't close automatically when logged out.

    Any solutions?

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    edit: oops, missread.
    Last edited by mrmatt1111; 08-29-2009 at 06:48 AM.
    My Hobby Project: LegacyClone

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You need to have references to those frames in order to be able to call dispose on them. Currently you are just creating them without creating the references to manipulate them with.

  4. #4
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    You need to have references to those frames in order to be able to call dispose on them. Currently you are just creating them without creating the references to manipulate them with.
    any simple examples ti create the references? :confused:

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Sure,
    Java Code:
    new LoginForm();
    creates a new LoginForm object but no references to manipulate that object with.
    Java Code:
    LoginForm aLogInForm = new LoginForm();
    creates both a new LoginForm object and a reference to that object called "aLogInForm".
    We can now manipulate the log in form object as we wish by calling it's methods (including dispose()) through the aLogInForm reference.

  6. #6
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default

    how do I know which JFrame is an active one (which is open at the current time?)

  7. #7
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    One way is to derive it from the logic that you put in the code. Most of the time it will be possible to know if you go through the steps that your code will be going through as it is executing.

    Another approach is to simply use those references to check. JFrames have a isVisible() method.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    > I wanna dispose all except Login Form when I click LogOut Menu
    Maintain a visible reference to your Login Form and use the static method of Frame to get an array of all Frames.
    Java Code:
    Frame[] frames = Frame.getFrames();
    for (Frame frame : frames) {
       if (frame != loginForm) {
          frame.dispose();
       }
    }
    db

  9. #9
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default

    This is my code, still have errors :(

    Java Code:
            Functions f = new Functions();
            Frame frames[] = f.getFrame();
            for (Frame frame : frames) {
               if (frame != LoginForm && frame!= null) {
                  frame.dispose();
               }
            }
            new LoginForm().setVisible(true);
    Functions.java have this code :
    Java Code:
        private Frame frames [] = new Frame[30];
        public int frameIndex = 0;
        
        public void setFrame(Frame newFrame){
            frames[frameIndex] = newFrame;
        }
    
        public Frame[] getFrame(){
            return frames;
        }
    Is this work palz?

  10. #10
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default

    Send a complete code.It will be useful for giving good solution.

    One suggestion is

    do like this below and try

    1. frame.setVisible(false);

    2. frame.dispose();
    Ramya:cool:

  11. #11
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    What errors are you getting? Post the error messages.

    Why are you doing new LoginForm().setVisible(true);? You already have a LogInForm at that stage (the one you were checking against in the for loop). Just toggle that one to visible.

Similar Threads

  1. dispose() does not work here
    By arunkumarinfo in forum NetBeans
    Replies: 5
    Last Post: 12-28-2013, 05:42 PM
  2. dispose() method not working
    By R&R in forum New To Java
    Replies: 19
    Last Post: 11-15-2010, 01:46 AM
  3. [SOLVED] Not dispose my JPanel
    By Eranga in forum Advanced Java
    Replies: 3
    Last Post: 11-14-2010, 03:02 PM
  4. i cant dispose the jframe(urgent)
    By arunkumarinfo in forum NetBeans
    Replies: 2
    Last Post: 02-24-2009, 09:19 AM
  5. How to dispose tooltip.
    By Preethi in forum New To Java
    Replies: 1
    Last Post: 07-22-2008, 07:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •