Results 1 to 7 of 7
  1. #1
    Masherbrum is offline Member
    Join Date
    Feb 2012
    Posts
    13
    Rep Power
    0

    Default Help with public variables

    Hey, I thought I could make a public variable and then have multiple lower level functions modify this variable. Is that not correct? What am I doing wrong, any help would be greatly appreciated. Thanks!



    public class testapp extends Applet implements MouseListener {


    *declare a bunch of public arrays*


    public void math() {


    *do a bunch of math*

    }


    public void map(graphics){

    *graphics*

    }}

    at the end it just outputs 0 for all those variables.

    are those functions even working?

  2. #2
    hvince95 is offline Member
    Join Date
    Jan 2012
    Location
    Adelaide, Australia
    Posts
    17
    Rep Power
    0

    Default Re: Help with public variables

    Its kinda hard to say, but I dont see the functions math(), or map() called from anywhere, so the integer variables could simply be outputting their defualt 0 value

    ...Try to use code tags when you post code.

  3. #3
    Masherbrum is offline Member
    Join Date
    Feb 2012
    Posts
    13
    Rep Power
    0

    Default Re: Help with public variables

    Ya, I was playing around with that.

    public void main(Graphics g){

    math(g);
    map(g);

    }

    I am not sure that is working though

    Thanks

  4. #4
    Masherbrum is offline Member
    Join Date
    Feb 2012
    Posts
    13
    Rep Power
    0

    Default Re: Help with public variables

    The mapping function is certainly working... its outputting the right variables in the right places, all the variables are simply 0.

    Either the math function isnt running or the variables are not being passed back and forth properly. Help!

  5. #5
    hvince95 is offline Member
    Join Date
    Jan 2012
    Location
    Adelaide, Australia
    Posts
    17
    Rep Power
    0

    Default Re: Help with public variables

    try doing this:

    Java Code:
    public class testapp extends Applet implements MouseListener {
    	*declare a bunch of public arrays*
    
    	public void start() {
    		math();
    		map();
    	}
    
    	public void math() {
    		*do a bunch of math*
    	}
    	public void map(graphics g){
    		*graphics*
    	}
    }

  6. #6
    Masherbrum is offline Member
    Join Date
    Feb 2012
    Posts
    13
    Rep Power
    0

    Default Re: Help with public variables

    It worked! Map runs without the start thing, but math does not.

    Thanks!

  7. #7
    hvince95 is offline Member
    Join Date
    Jan 2012
    Location
    Adelaide, Australia
    Posts
    17
    Rep Power
    0

    Default Re: Help with public variables

    No problem, You're the first i've helped on this forum!

Similar Threads

  1. public class variables versus methods
    By jezza10181 in forum New To Java
    Replies: 3
    Last Post: 02-07-2011, 09:54 PM
  2. public variables?
    By dyelax in forum New To Java
    Replies: 9
    Last Post: 12-28-2010, 12:17 AM
  3. Access Public Global Variables in class
    By spatel14 in forum New To Java
    Replies: 5
    Last Post: 07-08-2010, 11:50 AM
  4. Access Public Global Variables in class
    By spatel14 in forum New To Java
    Replies: 1
    Last Post: 07-07-2010, 08:41 PM
  5. Replies: 4
    Last Post: 10-22-2009, 06:45 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
  •