Results 1 to 4 of 4

Thread: Frame constructor in java

  1. #1
    Join Date
    Nov 2009
    Posts
    356

    Frame constructor in java

    Hi
    I use netbeans to write code, In my code I am trying to create a new instance of another class. When I try to do that the compiler gives me an error, I can not figure out what is the exact problem with the code. I have posted my code. The name of my class is conn.
    Code:
    public class cln extends javax.swing.JFrame {
        JFileChooser fc;
        Defaultlistmod listmod;
        Connect conn; 
        public cln() {
            initComponents();
            fc = new JFileChooser();
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            Connect conn = new Connect();
        }
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
    
                public void run() {
                    new cln().setVisible(true);
                }
            });
        }
    }
    Any advice or help on this.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Frame constructor in java

    Hello
    I just went through your code and I have made some changes to your code. I am posting the modified code, please check, may be this is what you want from this code, I mean this is how you want it to work.
    Code:
    public class cln extends javax.swing.JFrame {
        JFileChooser fc;
        Defaultlistmod listmod;
        Connect conn; // member variable in class scope
        public cln() {
            initComponents();
            fc = new JFileChooser();
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            Connect conn = new Connect();
        }

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Frame constructor in java

    Hello
    It would be better if you send the stack trace or point the code where is the error. This may help us and we may give you the exact suggestion on it. If it is possible for you please post the stack trace.

  4. #4
    Join Date
    Nov 2009
    Posts
    356

    Re: Frame constructor in java

    Hi
    As reegan mentioned, If I am not wrong the conn class does have a no-argument constructor. This is something like this
    Code:
    public Conn(){
    
    }
    the problem is that the actual frame is not showing.
    As zeco wanted, the error is in this part of the code, line number second.
    Code:
    public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Client().setVisible(true);
             }
            });
        }

Similar Threads

  1. What is the use of Frame class in java?
    By Truster in forum Software Development
    Replies: 5
    Last Post: 25-02-2010, 11:16 AM
  2. Creating an Internal Frame in java
    By samualres in forum Software Development
    Replies: 4
    Last Post: 24-02-2010, 10:46 PM
  3. Java program code for frame
    By Sarfaraj Khan in forum Software Development
    Replies: 5
    Last Post: 08-01-2010, 11:02 AM
  4. Remove Title Bar of a Frame in Java
    By rashmi_ay in forum Software Development
    Replies: 4
    Last Post: 30-11-2009, 12:57 PM
  5. Constructor in Java
    By Dharamsi in forum Software Development
    Replies: 4
    Last Post: 06-03-2009, 12:47 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,247,140.44699 seconds with 16 queries