jcheckbox and actionlisteners

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • carlos123
    New Member
    • Sep 2007
    • 53

    #1

    jcheckbox and actionlisteners

    i wondering if any with blueJ will look at my program, and just tell me what im doing wrong. ive been trying to solve this problem for 3 weeks now, and i am just sick of it.

    email. <Email removed>
    aim. <AIM removed>

    thanks.

    Code:
     public void actionPerformed (ActionEvent event)
          {
              if (bathroom.isSelected()) {
                
                       bathroomb=true;
                        }
    
            if (bathroomb == true){
       f1.dispose();
    }
    }
    thats basicly my problem. i dont understand why its not working.
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    What is bathroom and bathroomb?

    Comment

    • carlos123
      New Member
      • Sep 2007
      • 53

      #3
      bathroom is a checkbox

      bathroomb is a boolean

      sorry.

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        Well, I don't see why you need both bathroom and bathroomb. Why not have the code:

        [CODE=java]if (bathroom.isSel ected()) {
        f1.dispose();
        }[/CODE]

        If you do this, and it doesn't work, check out the dispose method you are calling on f1 (whatever that is).

        Comment

        • carlos123
          New Member
          • Sep 2007
          • 53

          #5
          Code:
                if (bathroom.isSelected()) {
            
                   System.out.println("WONT PRINT");
            
                }
          i was just using f1.dispose as an example. im just saying the code wont work.

          Comment

          • Ganon11
            Recognized Expert Specialist
            • Oct 2006
            • 3651

            #6
            Well, I have no clue. perhaps a better explanation of "does not work" would be helpful? Does it not compile? Does it compile, but not run? Does it run, but not do what you expect? We're going to need more details and background, because the code you have given here looks perfectly alright.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              You use an ItemListener not an ActionListener for the JCheckbox to handle the event that you want to handle here. You should have read the Java tutorial here before you tried this.

              Comment

              Working...