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 4 of 4

Thread: Disabling Check Boxes created by different method.

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Disabling Check Boxes created by different method.

    So. I have the following method that is called to create Check Boxes:

    	//function to create check boxes and add them to frame ( complete with action listeners )
    	public void addCheckButton(int i){
    		String ButtonNum = Integer.toString(i);
    		JCheckBox select = new JCheckBox(ButtonNum);
    		select.setBackground(new Color(56,48,44));
    		select.setForeground(new Color(225,255,255));
     
    		con.add(select);
    		select.addActionListener(this);	
    	}

    I am creating these buttons in my implemention like so:

    		//add our check-buttons
    		for (int i=0; i<35; i++){
    			lottery.addCheckButton((i+1));
    		}


    I want to disable all of my created checkboxes when 6 are selected. I am using the action listener event like so:

    	public void actionPerformed(ActionEvent evt)  { 	
     
    			//String Action= evt.paramString();
    			this.check_six++;
    			if (this.check_six<=6){ 
    				JOptionPane.showMessageDialog(frame, "Action id: " + check_six);
    			}
                else {
                	JOptionPane.showMessageDialog(frame, "MAX");
                	//DISABLE CHECK BUTTONS HERE!
                }
     
           }


    Does any one have a solution for this that would work with my current setup?
    thx


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,453
    My Mood
    Hungover
    Thanks
    144
    Thanked 638 Times in 546 Posts

    Default Re: Disabling Check Boxes created by different method.

    You have to keep a reference to the checkboxes you want to disable, then iterate over them and disable them when appropriate.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Disabling Check Boxes created by different method.

    I see. So would this pretty much require me making a class scope variable?

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,453
    My Mood
    Hungover
    Thanks
    144
    Thanked 638 Times in 546 Posts

    Default Re: Disabling Check Boxes created by different method.

    Quote Originally Posted by xdega View Post
    I see. So would this pretty much require me making a class scope variable?
    That's one way to do it. Or you could pass the reference around as a parameter to the necessary method(s).
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. check for valid argument to a method
    By lupis in forum Exceptions
    Replies: 8
    Last Post: March 24th, 2012, 11:09 PM
  2. Replies: 3
    Last Post: November 25th, 2011, 01:02 PM
  3. Disabling undo button in Word.
    By Silversurfer21 in forum Java Theory & Questions
    Replies: 0
    Last Post: September 5th, 2011, 09:03 AM
  4. Replies: 2
    Last Post: February 28th, 2011, 09:51 AM
  5. Method for Cedit card check, help!!!!1
    By raidcomputer in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 31st, 2009, 09:16 AM