Results 1 to 11 of 11
Thread: dispose all using Vector ?
- 08-29-2009, 05:31 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 66
- Rep Power
- 0
dispose all using Vector ?
That's my code.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 }
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?
- 08-29-2009, 06:44 AM #2
edit: oops, missread.
Last edited by mrmatt1111; 08-29-2009 at 06:48 AM.
My Hobby Project: LegacyClone
- 08-29-2009, 07:33 AM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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.
- 08-29-2009, 09:36 AM #4
Member
- Join Date
- Aug 2009
- Posts
- 66
- Rep Power
- 0
- 08-29-2009, 11:10 AM #5
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Sure,
creates a new LoginForm object but no references to manipulate that object with.Java Code:new LoginForm();
creates both a new LoginForm object and a reference to that object called "aLogInForm".Java Code:LoginForm aLogInForm = new LoginForm();
We can now manipulate the log in form object as we wish by calling it's methods (including dispose()) through the aLogInForm reference.
- 08-29-2009, 03:47 PM #6
Member
- Join Date
- Aug 2009
- Posts
- 66
- Rep Power
- 0
how do I know which JFrame is an active one (which is open at the current time?)
- 08-29-2009, 03:55 PM #7
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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.
- 08-30-2009, 11:19 PM #8
> 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.dbJava Code:Frame[] frames = Frame.getFrames(); for (Frame frame : frames) { if (frame != loginForm) { frame.dispose(); } }
- 08-31-2009, 03:00 PM #9
Member
- Join Date
- Aug 2009
- Posts
- 66
- Rep Power
- 0
This is my code, still have errors :(
Functions.java have this code :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);
Is this work palz?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; }
- 08-31-2009, 03:55 PM #10
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:
- 08-31-2009, 04:51 PM #11
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
dispose() method not working
By R&R in forum New To JavaReplies: 19Last Post: 11-15-2010, 01:46 AM -
[SOLVED] Not dispose my JPanel
By Eranga in forum Advanced JavaReplies: 3Last Post: 11-14-2010, 03:02 PM -
i cant dispose the jframe(urgent)
By arunkumarinfo in forum NetBeansReplies: 2Last Post: 02-24-2009, 09:19 AM -
dispose() does not work here
By arunkumarinfo in forum NetBeansReplies: 4Last Post: 02-01-2009, 12:16 PM -
How to dispose tooltip.
By Preethi in forum New To JavaReplies: 1Last Post: 07-22-2008, 07:06 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks