Results 1 to 6 of 6
  1. #1
    BertMan23 is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Post parsing a checkbox to boolean

    hi guys,

    im having some trouble. im trying to parse a checkbox to a boolean so that i can then save it to a text file. at the moment i have the current code which to me makes sense:

    private void btnSaveLoanActionPerformed(java.awt.event.ActionEv ent evt) {
    int loanid;
    float loandur, loanrate, loanamnt, security;
    boolean reinvest;

    loanid = Integer.parseInt(txtLoanID.getText());
    loandur = Float.parseFloat(txtLoanDur.getText());
    loanrate = Float.parseFloat(txtLoanRate.getText());
    loanamnt = Float.parseFloat(txtLoanAmount.getText());
    security = Float.parseFloat(txtLoanSecurityAmount.getText());
    reinvest = Boolean.parseBoolean(chkReinvest.isSelected());



    }

    all the text parsing works but the boolean one is telling me "method parseBoolean in class java.lang.Boolean cannot be applied to given types
    required: java.lang.String
    found: boolean"
    and when i click the warning im given the option to create the method parseBoolean(boolean) in java.lang.Boolean but when i click it, it just takes me to the Boolean class and doesnt do anything...

    its doing my head in if anyone could give me a hand ill be really appreciative

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The isSelected method returns a boolean indicating whether it is selected. Therefore, you don't need to parse it, just capture it.

  3. #3
    BertMan23 is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    ok im really kinda slow with java unfortunately, how would i capture it then save it to a text file?

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Java Code:
    boolean varName = checkBox.isSelected();
    will capture it, then check the output stream you are usings API and see how/if it can handle booleans in the write method.

  5. #5
    BertMan23 is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    ok that makes sense, thanks for the help :)

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

Similar Threads

  1. boolean error help when no boolean is given
    By drewtrcy in forum New To Java
    Replies: 18
    Last Post: 05-05-2011, 10:04 AM
  2. Replies: 3
    Last Post: 07-27-2010, 10:52 AM
  3. checkbox question
    By HellRider in forum AWT / Swing
    Replies: 1
    Last Post: 02-09-2010, 04:35 PM
  4. CheckBox
    By boss in forum NetBeans
    Replies: 3
    Last Post: 01-17-2010, 05:51 AM
  5. checkbox
    By Alan in forum AWT / Swing
    Replies: 3
    Last Post: 05-18-2007, 11:10 AM

Posting Permissions

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