Results 1 to 10 of 10

Thread: jframes

  1. #1
    javazers is offline Member
    Join Date
    Aug 2012
    Posts
    10
    Rep Power
    0

    Default jframes

    hello everyone,.can anyone help me on ho to connect/link jframes without opening a new window/frame?i wanted it to stay in the same size and doesn't actually open a new window/frame...check my sample

    Java Code:
    import javax.swing.JOptionPane;
    
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    
    /**
     *
     * @author HOME
     */
    public class frmMain extends javax.swing.JFrame {
    
    
        /**
         * Creates new form frmMain
         */
        public frmMain() {
            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() {
    
    
            frmHome = new javax.swing.JFrame();
            passwordTextfield = new javax.swing.JTextField();
            jLabel1 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
    
    
            javax.swing.GroupLayout frmHomeLayout = new javax.swing.GroupLayout(frmHome.getContentPane());
            frmHome.getContentPane().setLayout(frmHomeLayout);
            frmHomeLayout.setHorizontalGroup(
                frmHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
            );
            frmHomeLayout.setVerticalGroup(
                frmHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE)
            );
    
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
    
            jLabel1.setText("Password");
    
    
            jButton1.setText("Ok");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
    
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(106, 106, 106)
                            .addComponent(jLabel1)
                            .addGap(18, 18, 18)
                            .addComponent(passwordTextfield, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(161, 161, 161)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(164, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(108, 108, 108)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(passwordTextfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1))
                    .addGap(18, 18, 18)
                    .addComponent(jButton1)
                    .addContainerGap(154, Short.MAX_VALUE))
            );
    
    
            pack();
        }// </editor-fold>
    
    
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            if(passwordTextfield.getText().equals("miami")){
                 frmHome.setVisible(true);
                frmHome.setSize(600,400);
            }
            else{
                JOptionPane.showMessageDialog(null,"");
            }
           
           
        }
    
    
        /**
         * @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(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(frmMain.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 frmMain().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify
        private javax.swing.JFrame frmHome;
        private javax.swing.JButton jButton1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JTextField passwordTextfield;
        // End of variables declaration
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,017
    Rep Power
    10

    Default Re: jframes

    I'm not really sure what you're asking. What exactly do you mean when you say you want to connect/link JFrames? Also, most people here would advise you to ditch the gui builder until you have a stronger grasp of what it's doing.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    javazers is offline Member
    Join Date
    Aug 2012
    Posts
    10
    Rep Power
    0

    Default Re: jframes

    Sorry, thats what my college thought us,.we went ahead on gui builder

    what im trying to say is,.the program asks for a password,after i enter the password,it opens into a new FRAME without the frame that was asking for a password appearing..

    im really sorry for this,i never learn't that in college,i just wanted to explore more on better understanding of this

  4. #4
    javazers is offline Member
    Join Date
    Aug 2012
    Posts
    10
    Rep Power
    0

    Default Re: jframes

    because back in our turboC classes,..we use methods in changing the interface format..ugghh im not sure if i have typed the right term

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,017
    Rep Power
    10

    Default Re: jframes

    Are you asking how to change what appears in a single JFrame instead of using multiple JFrames? If so, what you're looking for is CardLayout.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: jframes

    Moved from Advanced Java.

    Nothing 'advanced' about the question either.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    gowthamgutha is offline Member
    Join Date
    Sep 2012
    Location
    Guntur, India
    Posts
    27
    Rep Power
    0

    Default Re: jframes

    Fine. First create a new JFrame,

    Java Code:
    JFrame f2;
    
    JFrame f1=new JFrame();
    f1.setTitle("Give Password");
    f1.setVisible(true);
    f1.setLayout(new GridBagLayout());
    JButton ok=new JButton("Check password");
    JTextField jf=new JTextField(20);
    f1.add(jf);
    f1.add(ok);
    
    ok.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae)
    {
    String pass=jf.getText();
    // your password checking here.
    
     if(pass.equals("mypassword"))
    {
    f1.dispose();
    f2=new JFrame();
    f2.setTitle("Welcome");
    f2.setLayout(new FlowLayout()); // some other layout of your choice
    f2.setVisible(true);
    
    }
    }
    });
    Last edited by Fubarable; 10-19-2012 at 06:55 PM. Reason: Moderator edit: quote tags changed to code tags

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

    Default Re: jframes

    Moderator edit to post above: [quote] [/quote] tags changed to [code] [/code] tags. Poster, consider editing the post further and indenting your code for ease of readability.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: jframes

    Quote Originally Posted by gowthamgutha View Post
    Fine. First create a new JFrame,

    Java Code:
    JFrame f2;
    
    JFrame f1=new JFrame();
    f1.setTitle("Give Password");
    f1.setVisible(true);
    f1.setLayout(new GridBagLayout());
    JButton ok=new JButton("Check password");
    JTextField jf=new JTextField(20);
    f1.add(jf);
    f1.add(ok);
    
    ok.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae)
    {
    String pass=jf.getText();
    // your password checking here.
    
     if(pass.equals("mypassword"))
    {
    f1.dispose();
    f2=new JFrame();
    f2.setTitle("Welcome");
    f2.setLayout(new FlowLayout()); // some other layout of your choice
    f2.setVisible(true);
    
    }
    }
    });
    That's bad code. Better learn Swing before trying to answer questions in this section.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: jframes

    Quote Originally Posted by DarrylBurke View Post
    That's bad code. Better learn Swing before trying to answer questions in this section.

    db
    Darryl, I wouldn't bother giving him this recommendation. He's the same bloke who recommended that someone should learn AWT before learning Swing.

Similar Threads

  1. Need help with JFrames
    By chassconcept in forum New To Java
    Replies: 3
    Last Post: 06-13-2012, 12:18 AM
  2. need help with jframes
    By glomic in forum New To Java
    Replies: 13
    Last Post: 01-08-2011, 12:16 PM
  3. help with jframes
    By pao09 in forum AWT / Swing
    Replies: 0
    Last Post: 04-15-2009, 03:10 PM
  4. jframes
    By ddj in forum AWT / Swing
    Replies: 0
    Last Post: 03-24-2009, 04:15 PM
  5. two JFrames
    By kirtesh4u in forum New To Java
    Replies: 0
    Last Post: 11-17-2008, 09:26 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
  •