Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Fubarable

Thread: moving from one frame to another

  1. #1
    aditi08 is offline Member
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Default moving from one frame to another

    im new to gui building in netbeans.
    im trying to write a simple code which takes me from one frame to another.dis code do not work,wat is the problem??plsss help

    MAINFORM code..

    Java Code:
    package net;
    public class frmMain extends javax.swing.JFrame {
    
        /** Creates new form frmMain */
        public frmMain() {
            initComponents();
        }
    
        private void initcomponents()
        {
    
            cmdregister = new javax.swing.JButton();
            register = new javax.swing.JLabel();
            sign = new javax.swing.JLabel();
            cmdsign = new javax.swing.JButton();
    
            cmdregister.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    cmdregisterActionPerformed(evt);
                }
            });
    
             cmdsign.addActionListener(new java.awt.event.ActionListener() {
    
                 public void actionPerformed(java.awt.event.ActionEvent evt) {
                    cmdsignActionPerformed(evt);
                }
            });
        }
         private void cmdregisterActionPerformed(java.awt.event.ActionEvent evt) {                                            
            frmMain fm=new frmMain();
             this.dispose();
            frmregister fr = new frmregister();
            fr.setVisible(true);
         }
            private void cmdsignActionPerformed(java.awt.event.ActionEvent evt) {                                        
    
            frmLogin fl = new frmLogin();
            fl.setVisible(true);
            this.dispose();
    
    
    }
    
        
    //    @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            cmdsign = new javax.swing.JButton();
            sign = new javax.swing.JLabel();
            register = new javax.swing.JLabel();
            cmdregister = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            cmdsign.setText("SIGNIN");
    
            sign.setText("EXISTING USER");
    
            register.setText("NEW USER");
    
            cmdregister.setText("SIGNUP");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGap(54, 54, 54)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(register)
                        .addComponent(cmdregister))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 293, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(sign, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(cmdsign))
                    .addGap(22, 22, 22))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(149, 149, 149)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(sign)
                        .addComponent(register))
                    .addGap(45, 45, 45)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cmdsign)
                        .addComponent(cmdregister))
                    .addContainerGap(193, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new frmMain().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton cmdregister;
        private javax.swing.JButton cmdsign;
        private javax.swing.JLabel register;
        private javax.swing.JLabel sign;
        // End of variables declaration                   
    
    }
    
    REGISTER FORM(on signup)
    
    package net;
    public class frmregister extends javax.swing.JFrame {
    
        /** Creates new form frmregister */
        public frmregister() {
            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() {
    
            jTextField1 = new javax.swing.JTextField();
            jTextField2 = new javax.swing.JTextField();
            regok = new javax.swing.JButton();
            jLabel1 = new javax.swing.JLabel();
            name = new javax.swing.JLabel();
            pass = new javax.swing.JLabel();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            jTextField1.setText("jTextField1");
    
            jTextField2.setText("jTextField2");
    
            regok.setText("OK");
    
            name.setText("USERNAME");
    
            pass.setText("PASSWORD");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(347, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(name)
                        .addComponent(pass))
                    .addGap(35, 35, 35)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(regok)
                        .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING))
                    .addGap(78, 78, 78))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(62, 62, 62)
                    .addComponent(jLabel1)
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(name))
                    .addGap(64, 64, 64)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(pass))
                    .addGap(39, 39, 39)
                    .addComponent(regok)
                    .addContainerGap(117, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new frmregister().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JLabel jLabel1;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        private javax.swing.JLabel name;
        private javax.swing.JLabel pass;
        private javax.swing.JButton regok;
        // End of variables declaration                   
    
    }
    LOGIN FORM(on sigin)
    
    package net;
    public class frmLogin extends javax.swing.JFrame {
    
        /** Creates new form frmLogin */
        public frmLogin() {
            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() {
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE)
            );
    
            pack();
        }// </editor-fold>                        
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new frmLogin().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify                     
        // End of variables declaration                   
    
    }
    Last edited by Fubarable; 12-01-2011 at 07:55 PM. Reason: post approved and code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: moving from one frame to another

    Rather than stating "this isn't working" please tell us how it's not working since we're terrible at guessing. Please try to debug things and let us know what's happening. For instance, just what is your code doing?
    DarrylBurke likes this.

Similar Threads

  1. Replies: 4
    Last Post: 01-18-2011, 09:22 AM
  2. how to open one frame to another frame
    By tukadiya in forum AWT / Swing
    Replies: 1
    Last Post: 12-20-2010, 09:27 PM
  3. Java slave Frame access to its owner main frame problem
    By cagdaseckin in forum New To Java
    Replies: 0
    Last Post: 12-10-2010, 11:40 AM
  4. Replies: 7
    Last Post: 11-02-2009, 07:31 PM
  5. Moving Box
    By anilanar in forum New To Java
    Replies: 2
    Last Post: 08-30-2009, 01:29 PM

Posting Permissions

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