Results 1 to 10 of 10

Thread: GUI program

  1. #1
    Join Date
    Apr 2011
    Posts
    23
    Rep Power
    0

    Default GUI program

    I trying to create a GUI that asks a user to input inches.
    I finished the program, but there are errors
    Any help will be appreciated

    Errors are as follows:

    line 24 cannot find symbol symbol: method getContentPane()

    lines 56 cannot find symbol symbol: method setTitle ( java.lang.String)
    line 57 cannot find symbol symbol: method setSize (int, int)
    line 58 cannot find symbol symbol: setVisible (boolean)


    code:

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    
    
    public class InchFeetGUI {
        private JLabel inchesQuestionLabel = new JLabel();
        private JTextField inchesBox = new JTextField();
        private JLabel inchesAnswerLabel = new JLabel ();;
        private Container contentPane;
        private JButton submitButton = new JButton ();
        
        public InchFeetGUI (){
            createGUI ();
        }// ends Welcome constructor
        
        private void createGUI (){
             //get content pane and set the layout to null
            
            contentPane = getContentPane();
            contentPane.setBackground(Color.white);
            contentPane.setLayout(null);
             
            //setup the question label
            inchesQuestionLabel.setText ("Enter inches: ");
            inchesQuestionLabel.setLocation(0,0);
            inchesQuestionLabel.setSize (200,30);
            contentPane.add(inchesQuestionLabel);
            
            //set up the textfield for user entry
            inchesBox.setText("0");
            inchesBox.setLocation(210,0);
            inchesBox.setSize(100,30);
            contentPane.add(inchesBox);
            
            //set up the submit button
            submitButton.setText("Submit");
            submitButton.setLocation(50,100);
            submitButton.setSize(100,30);
            contentPane.add(submitButton);
            
            //set up the label where answer will be
            
            inchesAnswerLabel.setText (" ");
            inchesAnswerLabel.setLocation (0,200);
            inchesAnswerLabel.setSize (300, 30);
            contentPane.add(inchesAnswerLabel);
            
            
            //set properties of Window
            
            setTitle (" Inches/Feet Converter ");
            setSize (400,400);
            setVisible (true);
                 
        }//ends createGUI method
    
       
        public static void main(String[] args) {
            
        }
    
    }
    Last edited by Fubarable; 04-23-2011 at 08:23 PM. Reason: code tags added

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

    Default

    If you're going to call a method of your class, your class has to have the method, either declared in the class or declared in a parent of the class. Your program looks as if you meant to subclass JFrame but neglected to do this, and this would make sense since JFrame has this method declared and your code doesn't.

    Other problem: your main method doesn't do much. :)

    Also, I added code tags added to your post above to help make it readable.

    To the OP, in the future, to do this yourself, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:

    Java Code:
    [code]
      // your code goes here
      // notice how the top and bottom tags are different
    [/code]
    Best of luck

  3. #3
    Join Date
    Apr 2011
    Posts
    23
    Rep Power
    0

    Default thanks

    thanks alot, i'm new to java programming an made a newbie mistake

  4. #4
    Join Date
    Apr 2011
    Posts
    23
    Rep Power
    0

    Default GUI not popping up

    Fixed the errors, but the GUI does not pop up when I run the program

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

    Default

    Quote Originally Posted by program junkie View Post
    Fixed the errors, but the GUI does not pop up when I run the program
    Not a newbie mistake but a common sense issue: We really can't help you if you change your code and don't show it to us with the changes-- should be sort of obvious. Please post your latest code, but again use code tags as noted in my first reply.
    Last edited by Fubarable; 04-23-2011 at 09:03 PM.

  6. #6
    Join Date
    Apr 2011
    Posts
    23
    Rep Power
    0

    Default new code for GUI proram

    Here's the new code:


    Java Code:
    import java.awt.*;
    import javax.swing.*;
    
    public class InchFeetGUI extends JFrame {
    
        private JLabel inchesQuestionLabel = new JLabel();
        private JTextField inchesBox = new JTextField();
        private JLabel inchesAnswerLabel = new JLabel();
    
        ;
        private Container contentPane;
        private JButton submitButton = new JButton();
    
        public InchFeetGUI() {
            createGUI();
        }// ends Welcome constructor
    
        private void createGUI() {
            //get content pane and set the layout to null
    
            contentPane = getContentPane();
            contentPane.setBackground(Color.white);
            contentPane.setLayout(null);
    
            //setup the question label
            inchesQuestionLabel.setText("Enter inches: ");
            inchesQuestionLabel.setLocation(0, 0);
            inchesQuestionLabel.setSize(200, 30);
            contentPane.add(inchesQuestionLabel);
    
            //set up the textfield for user entry
            inchesBox.setText("0");
            inchesBox.setLocation(210, 0);
            inchesBox.setSize(100, 30);
            contentPane.add(inchesBox);
    
            //set up the submit button
            submitButton.setText("Submit");
            submitButton.setLocation(50, 100);
            submitButton.setSize(100, 30);
            contentPane.add(submitButton);
    
    
            //set up the label where answer will be
    
            inchesAnswerLabel.setText(" ");
            inchesAnswerLabel.setLocation(0, 200);
            inchesAnswerLabel.setSize(300, 30);
            contentPane.add(inchesAnswerLabel);
    
    
            //set properties of Window
    
            setTitle("Inches/Feet Converter");
            setSize(400, 400);
            setVisible(true);
    
        }//ends createGUI method
    
        public static void main(String[] args) {
            InchFeetGUI application = new InchFeetGUI();
    
        }
    }

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

    Default

    Quote Originally Posted by program junkie View Post
    Fixed the errors, but the GUI does not pop up when I run the program
    I see your GUI when I run your latest code. What problems are you experiencing?

  8. #8
    Join Date
    Apr 2011
    Posts
    23
    Rep Power
    0

    Default

    Well, Im using Netbeans as the IDE and the GUI is not populating when I run the code. Must be an issue with Netbeans

  9. #9
    Join Date
    Apr 2011
    Posts
    23
    Rep Power
    0

    Default Thanks

    Thanks alot Fubarable for your patience in assisting me.

    I got the program to work

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

    Default

    Quote Originally Posted by program junkie View Post
    Well, Im using Netbeans as the IDE and the GUI is not populating when I run the code. Must be an issue with Netbeans
    NetBeans is compiling the code, but are you sure that you're telling it to run the code? Have you run programs with NetBeans before?

    edit: nevermind! congrats!

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  2. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  3. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 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
  •