Results 1 to 7 of 7

Thread: java problem

  1. #1
    Chillie in here j.o.s.h.1408's Avatar
    Join Date
    Dec 2005
    Location
    a place called home
    Posts
    8,543
    Thanks
    757
    Thanked
    256 times in 193 posts
    • j.o.s.h.1408's system
      • Motherboard:
      • ASUS P6T Delux
      • CPU:
      • Intel core i7 920 @ 3ghz
      • Memory:
      • 3GB DDR RAM
      • Storage:
      • 1TB Samsung F1, 500GB Seagate baracuda + 320gb Seagate PATA +150GB WD PATA
      • Graphics card(s):
      • EVGA 480GTX SC edition
      • PSU:
      • Seasonic M12 600W Module PSU FTW
      • Case:
      • Lian Li PC-A7010B (the rolls royce of pc cases)
      • Operating System:
      • vista ultimate edition and windows xp
      • Monitor(s):
      • 22inch 2005FPW dell monitor
      • Internet:
      • 24mb BE There Broadband

    java problem

    Hi, I am trying to create a very basic form using java netbeans. i have jdk 1.5.

    I have two classes, the main class and the gui class. The main class creates a Jframe and adds then adds the gui components from the gui class I made. The problem is when I try to run the program, the compiler throws an exception saying that I am adding a container to a window. The line it points at is highlighted below:



    Code:
    import com.sun.org.apache.bcel.internal.verifier.structurals.Frame;
    import javax.swing.JFrame;
    import java.awt.*;
    
    public class Main 
    {
        
    
        
     
        public static void main(String[] args) 
        {
            
            JFrame frame = new JFrame();
            //frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            frame.setTitle("Login");
            Login test1 = new Login();
            frame.getContentPane().add(test1);   //Line in which the compiler throws an exception
            frame.setSize(200, 150);
            frame.setVisible(true);
            
            
            
            // TODO code application logic here
        }
        
    }
    Last edited by j.o.s.h.1408; 19-01-2006 at 05:08 PM.

  2. #2
    Agent of the System ikonia's Avatar
    Join Date
    May 2004
    Location
    South West UK (Bath)
    Posts
    3,736
    Thanks
    39
    Thanked
    75 times in 56 posts
    j.o.s.h - are you jonney mendoza ?

    I assume frame.getContentPane(). is getting data from a container
    Last edited by ikonia; 19-01-2006 at 06:31 PM.
    It is Inevitable.....


  3. #3
    Chillie in here j.o.s.h.1408's Avatar
    Join Date
    Dec 2005
    Location
    a place called home
    Posts
    8,543
    Thanks
    757
    Thanked
    256 times in 193 posts
    • j.o.s.h.1408's system
      • Motherboard:
      • ASUS P6T Delux
      • CPU:
      • Intel core i7 920 @ 3ghz
      • Memory:
      • 3GB DDR RAM
      • Storage:
      • 1TB Samsung F1, 500GB Seagate baracuda + 320gb Seagate PATA +150GB WD PATA
      • Graphics card(s):
      • EVGA 480GTX SC edition
      • PSU:
      • Seasonic M12 600W Module PSU FTW
      • Case:
      • Lian Li PC-A7010B (the rolls royce of pc cases)
      • Operating System:
      • vista ultimate edition and windows xp
      • Monitor(s):
      • 22inch 2005FPW dell monitor
      • Internet:
      • 24mb BE There Broadband
    Its getting data from another class that represents the GUI... The GUI class has the code that adds all the buttons, text boxes etc from the swing package. all the code does above is display the contents of the GUI class into a frame with a set size...

    p.s No i am not Jonney Mendoza...

  4. #4
    Chillie in here j.o.s.h.1408's Avatar
    Join Date
    Dec 2005
    Location
    a place called home
    Posts
    8,543
    Thanks
    757
    Thanked
    256 times in 193 posts
    • j.o.s.h.1408's system
      • Motherboard:
      • ASUS P6T Delux
      • CPU:
      • Intel core i7 920 @ 3ghz
      • Memory:
      • 3GB DDR RAM
      • Storage:
      • 1TB Samsung F1, 500GB Seagate baracuda + 320gb Seagate PATA +150GB WD PATA
      • Graphics card(s):
      • EVGA 480GTX SC edition
      • PSU:
      • Seasonic M12 600W Module PSU FTW
      • Case:
      • Lian Li PC-A7010B (the rolls royce of pc cases)
      • Operating System:
      • vista ultimate edition and windows xp
      • Monitor(s):
      • 22inch 2005FPW dell monitor
      • Internet:
      • 24mb BE There Broadband
    Here is the code for the login class

    Code:
    /*
     * Login.java
     *
     * Created on 18 January 2006, 16:55
     */
    
    /**
     *
     * @author  jonathan
     */
    class Login extends javax.swing.JFrame implements java.awt.event.ActionListener {
        
        /** Creates new form Login */
        public Login() {
            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.
         */
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
        private void initComponents() {
            jLayeredPane1 = new javax.swing.JLayeredPane();
            jButton1 = new javax.swing.JButton();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jTextField1 = new javax.swing.JTextField();
            jButton2 = new javax.swing.JButton();
            jPasswordField1 = new javax.swing.JPasswordField();
    
            getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jButton1.setText("Login");
            getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 220, -1, -1));
    
            jLabel1.setText("Username");
            getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 120, -1, -1));
    
            jLabel2.setText("Password");
            getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 150, 50, -1));
    
            jTextField1.addActionListener(this);
    
            getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 120, 170, -1));
    
            jButton2.setText("Register");
            jButton2.addActionListener(this);
    
            getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 220, -1, -1));
    
            getContentPane().add(jPasswordField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 150, 170, 20));
    
            pack();
        }
    
        // Code for dispatching events from components to event handlers.
    
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == jButton2) {
                Login.this.jButton2ActionPerformed(evt);
            }
            else if (evt.getSource() == jTextField1) {
                Login.this.jTextField1ActionPerformed(evt);
            }
        }
        // </editor-fold>                        
    
        private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
    // TODO add your handling code here:
        }                                           
    
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
        }                                        
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
           // java.awt.EventQueue.invokeLater(new Runnable() {
               // public void run() {
                  //  new Login().setVisible(true);
               // }
            //});
        }
        
        // Variables declaration - do not modify                     
        public javax.swing.JButton jButton1;
        public javax.swing.JButton jButton2;
        public javax.swing.JLabel jLabel1;
        public javax.swing.JLabel jLabel2;
        public javax.swing.JLayeredPane jLayeredPane1;
        public javax.swing.JPasswordField jPasswordField1;
        public javax.swing.JTextField jTextField1;
        // End of variables declaration                   
        
    }

  5. #5
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    You are adding a frame to a container. You've instantiated a JFrame in class Main, used it's getContentPane() method to retrieve (you guessed it) it's content pane container, and you're trying to add the Login class to that, which is a JFrame (extends JFrame).
    To err is human. To really foul things up ... you need a computer.

  6. #6
    Chillie in here j.o.s.h.1408's Avatar
    Join Date
    Dec 2005
    Location
    a place called home
    Posts
    8,543
    Thanks
    757
    Thanked
    256 times in 193 posts
    • j.o.s.h.1408's system
      • Motherboard:
      • ASUS P6T Delux
      • CPU:
      • Intel core i7 920 @ 3ghz
      • Memory:
      • 3GB DDR RAM
      • Storage:
      • 1TB Samsung F1, 500GB Seagate baracuda + 320gb Seagate PATA +150GB WD PATA
      • Graphics card(s):
      • EVGA 480GTX SC edition
      • PSU:
      • Seasonic M12 600W Module PSU FTW
      • Case:
      • Lian Li PC-A7010B (the rolls royce of pc cases)
      • Operating System:
      • vista ultimate edition and windows xp
      • Monitor(s):
      • 22inch 2005FPW dell monitor
      • Internet:
      • 24mb BE There Broadband
    O i see. im a noob when it comes to SWING GUI interfaces. how do i add jus the contents of the GUI? or better, just open and run the login gui(my original idea) Thanks...

  7. #7
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    The only reason I can see why class Login wouldn't present you with a JFrame when you run it is an application is that you have the code commented out i.e. uncomment:

    // java.awt.EventQueue.invokeLater(new Runnable() {
    // public void run() {
    // new Login().setVisible(true);
    // }
    //});

    To be honest i'd use SwingUtilities.invokeLater
    To err is human. To really foul things up ... you need a computer.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. DVI problem, pc won't start! help needed.
    By snowwolf in forum Graphics Cards
    Replies: 1
    Last Post: 09-04-2010, 04:11 PM
  2. SN25P PSU or PCI-E problem!?
    By SilverFern in forum PC Hardware and Components
    Replies: 1
    Last Post: 19-01-2006, 10:51 AM
  3. Wierd Ati driver problem
    By Skii in forum PC Hardware and Components
    Replies: 5
    Last Post: 20-01-2004, 06:59 PM
  4. Keyboard Problem
    By Craig in forum PC Hardware and Components
    Replies: 0
    Last Post: 16-11-2003, 01:15 PM
  5. Problem with 8KRA2+ mobo and "C1" memory?
    By stryda in forum PC Hardware and Components
    Replies: 0
    Last Post: 14-10-2003, 01:04 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
  •