Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: trouble with GUI

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default trouble with GUI

    Hey guys, for my computer science class we are writing with GUI
    This is the first program I've tried to write with GUI and I can't figure these errors out.
    thanks in advance.

    piGUI.java:11: cannot resolve symbol
    symbol : variable iteration
    location: class piGUI
    private double extent = iteration.getnumber();
    ^
    piGUI.java:38: cannot resolve symbol
    symbol : variable end
    location: class piGUI
    private double answer = numberField.setnumber(end);
    ^
    import javax.swing.*;
    import BreezySwing.*;
    public class piGUI extends GBFrame{
     
    private JLabel iterationLabel;
    private JLabel numberLabel;
    private DoubleField iterationField;
    private DoubleField numberField;
    private JButton iterationButton;
    private JButton numberButton;
    private double extent = iteration.getnumber();
     
    public piGUI(){
     
    iterationLabel = addLabel ("Iterations" ,1,1,1,1);
    numberLabel = addLabel ("Pi" ,1,2,1,1);
    iterationField = addDoubleField (0.0 ,2,1,1,1);
    numberField = addDoubleField (0.0 ,2,2,1,1);
    iterationButton = addButton (">>>>>" ,3,1,1,1);}
     
    public void buttonClicked (JButton buttonObj){
     
      for (int i=1; i < extent; i++) {
     
      if(answer % 2 == 1)
      {
      extent=extent-1.0/(2*i-1);
      answer=answer+1;
      }
      else
      {
      extent=extent+1.0/(2*i-1);
      answer=answer+1;
      answer = answer * 4;
      }
      }
      }
    private double answer = numberField.setnumber(end);
     
    public static void main (String[] args){
    piGUI theGUI = new piGUI();
    theGUI.setSize (250, 100);
    theGUI.setVisible(true);
    }
    }
    Last edited by copeg; February 7th, 2011 at 03:13 PM.


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: trouble with GUI

    import javax.swing.*;
    import BreezySwing.*;
    public class piGUI extends GBFrame{
     // beginning of class 
    private JLabel iterationLabel;
    private JLabel numberLabel;
    private DoubleField iterationField;
    private DoubleField numberField;
    private JButton iterationButton;
    private JButton numberButton;
    private double extent = iteration.getnumber();
     
    public piGUI(){
    // beginning of constructor
    iterationLabel = addLabel ("Iterations" ,1,1,1,1);
    numberLabel = addLabel ("Pi" ,1,2,1,1);
    iterationField = addDoubleField (0.0 ,2,1,1,1);
    numberField = addDoubleField (0.0 ,2,2,1,1);
    iterationButton = addButton (">>>>>" ,3,1,1,1);
    } // end of constructor
     
     
    public void buttonClicked (JButton buttonObj){
    // beginning of method 
    for (int i=1; i < extent; i++) {
    // beginning of for
    if(answer % 2 == 1)
    { // beginning of if 
    extent=extent-1.0/(2*i-1);
    answer=answer+1;
    } // end of if
    else
    { // beginning of else
    extent=extent+1.0/(2*i-1);
    answer=answer+1;
    answer = answer * 4;
    } // end of else
    } // end of for
    } // end of method 
    private double answer = numberField.setnumber(end);
     
    public static void main (String[] args){ // beginning of main
    piGUI theGUI = new piGUI();
    theGUI.setSize (250, 100);
    theGUI.setVisible(true);
    } // end of main
    } // end of class

    Well..it appears your brackets don't match up..i.e. no bracket for end of constructor it appears.

    Also, you should try adding an ActionListener for a button.

    Also

    private double extent = iteration.getnumber()

    I can't find a variable called iteration anywhere. Neither could the compiler I'm guessing. That's why it said it couldn't find symbol.
    Also, the same goes for the variable end.

    If they were private variables of the super class or of one of the other classes you're importing...you can't access them.

    Also...though I don't have your code to tell for sure...

    private double answer = numberField.setnumber(end);

    Wouldn't it be getNumber() if anything?

    Set methods are usually void.

    However, if numberField is aJTextComponent...it will return a String even with the get method. You'll have to parse it to deal with that.

    Not sure what exactly you're trying to do overall..but I'm wondering why it seems you may be making setNumbeer and stuff like that.

    Usually most people would...for a JTextComponent....

    JTextComponent jtc = new JTextComponent();

    jtc.setText("Text");

    For JButtons, most people would

    JButton jb = new JButton("Button text");
    Last edited by javapenguin; February 7th, 2011 at 03:42 PM. Reason: Fixing mistake I made

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: trouble with GUI

    Please use the code tags, it helps format your code into a much more readable format.

    These errors are telling you that the variables you are trying to use (defined by the name and line in the error report) cannot be found. To take the first error, you attempt to access a variable named iteration, but this is not defined anywhere in the code you posted (if it is defined in the parent class, be sure the variable is not private)
    Last edited by copeg; February 7th, 2011 at 03:22 PM.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: trouble with GUI

    Well..it appears your brackets don't match up..i.e. no bracket for end of constructor it appears.
    Yes there is.

    Also, you should try adding an ActionListener for a button.
    Why? For all we know the function addButton (which I presume is defined in the parent class) does just this, there just isn't enough code posted to determine that...and both of these points are completely beside the point, skirting around the original posters question.

    I can't find a variable called iteration anywhere. Neither could the compiler I'm guessing. That's why it said it couldn't find symbol.
    You are right. But as I've said in the past, if you have to add phrases lilke "I'm Guessing", perhaps you should truly think, rethink, and test your idea.

  5. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: trouble with GUI

    To add an ActionListener, you could do this
    aButton.addActionListener(this);
    anotherButton.addActionListener(this);
    and then later...outside of constructor inside it's own method.

    public void actionPerformed(ActionEvent e)
    {
     
    if (e.getActionCommand().equals("Some text of a button"))
    {
    // action for that button
    }
     
    else if (e.getActionCommand().equals("Some text for the other button"))
    {
    // action for other button
    }
    }

    However...as it appears you're doing...if you just have like one button...or if you just prefer to do it this way...you can also

    aButton.addActionListener(new ActionListener() {
     
    public void actionPerformed(ActionEvent e)
    {
    // action for that button
    }
    });

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: trouble with GUI

    To add an ActionListener, you could do this
    Did you even read the original question? What does an action listener have to do with it?

  7. #7
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Red face Re: trouble with GUI

    Quote Originally Posted by copeg View Post
    Yes there is.



    Why? For all we know the function addButton (which I presume is defined in the parent class) does just this, there just isn't enough code posted to determine that...and both of these points are completely beside the point, skirting around the original posters question.



    You are right. But as I've said in the past, if you have to add phrases lilke "I'm Guessing", perhaps you should truly think, rethink, and test your idea.
    Yeah...I see that end bracket now. Didn't catch it.


  8. #8
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: trouble with GUI

    Quote Originally Posted by copeg View Post
    Did you even read the original question? What does an action listener have to do with it?
    I answered the original question. Was just pointing out how buttonClicked never was called it seems.
    That's all.



Similar Threads

  1. Having trouble with linked list
    By joecool594 in forum Collections and Generics
    Replies: 6
    Last Post: March 21st, 2011, 08:50 PM
  2. [SOLVED] array trouble
    By littlefuzed in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 13th, 2010, 08:56 PM
  3. Having trouble with a While statment
    By java0 in forum Loops & Control Statements
    Replies: 1
    Last Post: January 27th, 2010, 12:37 PM
  4. Having trouble with an if statement. please help!!
    By humdinger in forum Loops & Control Statements
    Replies: 11
    Last Post: January 21st, 2010, 02:49 PM
  5. Having trouble with strings
    By Reaperkid77 in forum Java SE APIs
    Replies: 3
    Last Post: October 20th, 2009, 06:30 PM

Tags for this Thread