Results 1 to 4 of 4

Thread: Boolean issues

  1. #1
    Lingerz is offline Member
    Join Date
    Sep 2009
    Posts
    21
    Rep Power
    0

    Default Boolean issues

    Hey. In making a simple clicking applet, I've run into an odd problem.

    Throughout explaining I'll be talking about one of the eight JButtons, as I really don't think it matters that I talk about all of them as they all have the same problem.

    I declared a boolean, 'm1', which is set to true when check(), called by process(), generates a random number below a certain amount (specific for the level).

    I got check(), icons() and actionPerformed(ActionEvent) to print m1. The result:

    Java Code:
    Check: true
    Icons: true
    ActionEvent: false

    Whenever the user clicks on the button, it goes false whether it's true or not. The methods are below.

    process()

    Java Code:
    	public void process() {
    		check();
    		repaint();
    	}

    check()

    Java Code:
    	public void check() {
    		int c1 = rN(tN);//rN(int) is the random number.
    
    		if (c1 < hT) {
    			if (m1) {
    				m1 = false;
    			}
    			else {
    				m1 = true;
    			}
    		}
    		icons()
    	}

    icons()

    Java Code:
    	public void icons() {
    		if (m1) {
    			S1.setIcon(gI("GREEN"));//gI(String) collects an image from the sprites folder.
    		}
    		else {
    			S1.setIcon(gI("RED"));
    		}
    	}

    If you can and are willing to help, I'd like to know why it does that and how to stop it, or a way around it.

    Thanks in advance. :)

  2. #2
    Lingerz is offline Member
    Join Date
    Sep 2009
    Posts
    21
    Rep Power
    0

    Default

    What..? :l

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

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

    Default

    To the OP, you may want to create an SSCCE that demonstrates your problem as well as go into greater detail on what's going on. Please look at the third link in my signature below. Best of luck!

Similar Threads

  1. Boolean methods
    By sonny in forum New To Java
    Replies: 7
    Last Post: 03-26-2010, 10:16 PM
  2. Boolean confusion
    By KM88 in forum New To Java
    Replies: 13
    Last Post: 11-02-2009, 12:44 PM
  3. Boolean method help
    By syferite in forum New To Java
    Replies: 6
    Last Post: 10-28-2009, 01:32 PM
  4. 1 as an integer, not boolean
    By McChill in forum New To Java
    Replies: 1
    Last Post: 05-02-2009, 09:39 PM
  5. [SOLVED] if-else and boolean issues
    By AngrYkIdzrUlE in forum New To Java
    Replies: 21
    Last Post: 03-09-2009, 05:18 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •