Checkbox - One affects all?  Need solution

Hello all,
I recently started a small program for the sake of testing out Checkboxes and already I am running into a brick wall.
The problem I am having, as I can best explain it, is that I am testing a very small program that does the following:
- Allows user to check multiple boxes
- As each box is checked, the price is INCREASED based on the value of that box
- As each box is unchecked, the price is DECREASED based on the value of that box
I am finding that if I begin the program with several empty boxes and make just one choice (on one box), all other empty boxes are treated as if they've been UNCHECKED (aka as if they were actually checked before!) Obviously in my case, beginning the program with several checkboxes and selecting only one - something that's supposed to add one dollar amount to the "0.00" beginning balance - instead makes it go into the negatives because the actions for deselecting the checkboxes are taken (those actions which tell the program to SUBTRACT the value from the unchecked boxes . . which is only supposed to occur if they were checked previously and are being unchecked now.)
What I need is some sort of system in which each checkbox is treated independently and so that action is taken only if the box I'm clicking has been selected/deselected, whereas any other boxes within the applet window are not changed at all.
My sample code is as follows:
import java.applet.*;*
*import java.awt.*;
import java.awt.event.*;
public class Sample extends Applet implements ItemListener
          //-------CHECKBOXES------------------------------
          Checkbox priceOneCB = new Checkbox("First Price");
          Checkbox priceTwoCB = new Checkbox("Second Price");
     public void init()
          //-------SET UP INTERFACE--------------------------------
          add(priceOneCB);
                priceOneCB.addItemListener(this);
          add(priceTwoCB);
                priceTwoCB.addItemListener(this);
     public void itemStateChanged(ItemEvent e)
           // price one selected
          if (priceOneCB.getState())
          System.out.println("PRICE ONE SELECTED!");
          // price one NOT selected
          else if (!(priceOneCB.getState()))
          System.out.println("PRICE ONE DESELECTED!");
          // price two selected
          if (priceTwoCB.getState())
             System.out.println("PRICE TWO SELECTED!");
            // price two NOT selected
            else if (!(priceTwoCB.getState()))
            System.out.println("PRICE TWO DESELECTED!");
}Does anyone have any suggestions? Am I just completely missing the mark here with my Checkbox usage? I am a complete "newbie" to this subject and I'm very frustrated, so hopefully someone can lead me down the right path. I also apologize if my explanation wasn't clear enough, but I did the best I could. It's a toughie to explain.
Thanks very much in advance!
- Chubz

Aren't you confusing deselected with unselected?
What your code is doing every time there is an event is going through all the boxes and saying "FOO SELECTED" if it is checked and "FOO DESELECTED" if it is not checked.. But you really want only to respond to changes.
You could do this directly by checking to see what CheckBox caused itemStateChange() to be fired. The ItemEvent class has a couple of methods which look like candidates to return this information. Once you know which check box was selected/deselected, you know how much to change the total by.
Another approach is to work out the total each time there is a click anywhere. Ie go through all of the check boxes and if they are selected multiply by the "value" associated with that box and add them up.
Always use braces - even for one line blocks. It adds greatly to readability
if(foo) {
} else if (bar) {
if(baz) {
}If there is a choice between just two things just use if-else:
if(someCondition) {
    // if true
} else {
    // if not
//if(someCondition) {
//    // if true
//} else if(!someCondition) {
//    // if not
//}This is especially important if someCondition is returned by a method - because it may change between one invocation and the next causing strange results.
Why are you using CheckBox, rather than JCheckBox?

Similar Messages

  • How can I change the space between a checkbox and text all at one time? I have a lot of checkboxes in my form.

    How can I change the space between a checkbox and text all at one time? I have a lot of checkboxes in my form.

    Okay, I haven't found a way to add an extra space using Find/replace, but you might be able to add some text wrap to the check boxes that will push the text away from them.
    Open Find/Replace and click the Object tab.
    Click the Specify attributes to find button to the right of the Find Object Format: field.
    Under Basic Attributes, choose Stroke and then the Black swatch (assuming the black swatch is applied to the strokes of your check boxes). If there are no other stand-alone objects in your form with a Black stroke, this should be all you need. (If there are Black strokes on your table cells, they will be ignored.)
    Click OK
    Click the Specify attributes to change button to the right of the Change Object Format: field.
    Under Basic Attributes, choose Text Wrap & Other > Text Wrap > Type: > Wrap around bounding box (2nd button from left)
    Under Offset, set a Right offset at the distance you'd like to add (I don't know what units you use, but the 3-5 points might work for your purposes...might take some trial-and-error to get it where you want)
    Click OK
    Click Change All

  • When i go to the app store to update the one app that needs to be updated, the screen is blank.  It used to list all the apps that need updating and have a button called update all.  Now nothing.  Just a blank screen.

    when i go to the app store to update the one app that needs to be updated, the screen is blank.  It used to list all the apps that need updating and have a button called update all.  Now nothing.  Just a blank screen.  How can I fix this?

    There's been a problem with this all day.  Seems to be a server problem  -  wait a day and try again, or use itunes on the computer to update, that works.

  • Anyone as frustrated as i am...just bought a brand new 13" powerbook to find that I can't load my adobe creative suite 2.3 software! i need solutions that do not involve spending more $$$$ one the newest version.

    Is anyone  as frustrated as i am...just bought a brand new 13" powerbook to find  that I can't load my adobe creative suite 2.3 software using the lion os! I need solutions  that do not involve spending more $$$$ one the newest CS version. After googling problem, I find I am not the only one. Apple told me Creative Suite 3 would work, but others said no.  Version 5.5 seems to be most reliable. Any feedback would be greatly appreciated.

    No, you're not the only person who failed to do any homework before making your purchase. You will have to upgrade your Adobe software at the very least. Before you post another complaint about what doesn't run see
    About incompatible software (OS X v10.6, OS X Lion, OS X Mountain Lion)
    The Lion Compatibility Site

  • HT1386 my screen crack on my ipad they are going to send me a new one but i need to save a video(my wedding) thats on the one i have now....i'm not very computer savy.....the lady said i can save ,sync, something all my info then put in on my new one....H

    my screen cracked on my ipad they are going to send me a new one but i need to save a video(my wedding) thats on the one i have now....i'm not very computer savy.....the lady said i can save ,sync, something all my info then put in on my new one....Help me

    You have to import the video to your computer by connecting the iPad with cable and then using iPhoto if you have a Mac or Windows Explorer or any other camera application that will import photos and videos. Read this for instructions.
    iOS: Importing personal photos and videos from ... - Support - Apple
    Make sure that you backup and sync with iTunes as well, if You have never synced with iTunes before, it might just be easier for you to backup with iCloud. You can restore from the backup when you get the replacement iPad.
    How to backup and restore from a backup
    http://support.apple.com/kb/HT1766

  • My phone was stolen and I forgot my Icloud account or password , Im sure I have created one . All what i need is to get back contacts and photos . any way to help?

    my phone was stolen and I forgot my Icloud account or password , Im sure I have created one . All what i need is to get back contacts and photos . any way to help?

    I think , you shoul backed up your data on icloud , if you , you can restore everything , if you forgot icloud id and no way to get it , i think you lost everything ...

  • Expire/Reduce for One PO Affected all POs

    GW8.0.2 HP3 on SLES 11 SP1
    I have 9 post offices. Each POA has 4 scheduled events that includes a daily user database check. We do not expire any messages but have mailbox size limits set. We leave it up to the user to manage their own mailbox size. One post office is for our retirees. We have a problem with this one as the mailbox sizes constantly grow. I decided to create a POA scheduled event, for just this PO, to expire messages that are older than 180 days. This new event was only enabled on the one POA. Well, it did run, but it ran for all the POAs. So, this morning I come in and all the post offices have been expired. I looked at the scheduled event for the user database check and it's Expire/Reduce option had been changed to match the one I created for single POA.
    What a mess. Anyway, is this normal behavior? It seems wierd that I can't create a new single event, and assign it to one POA, without it affecting all the others.
    Phillip

    See http://www.novell.com/support/kb/doc.php?id=10021870
    I know it's old, but as far as I know it still works the same way on GW8.
    After you created the new event, did you explicitly go into all the other
    post offices and disable the new event ?
    Cheers Dave
    Dave Parkes [NSCS]
    Occasionally resident at http://support-forums.novell.com/

  • I have a 1st gen ipad. Want to play Candy Crush. Installed app from app store. I hit play now, I see the board then the pad goes back to the start screen (the one with all the apps displayed). Do I need additional apps to run? Thanks.

    I have a 1st generation iPad. Want to play Candy Crush Saga. Installed app from Apple Store. When I tap on the app, I wait a long time while it reads "loading" then I hit "play", I see the board then the ipad goes back to the ipad start screen (the one with all the apps displayed). Is there some additional program I need to play this type of game. I know that space is not an issue as I have very little stored. Thanks.
    Just found my answer. Worked perfectly. Instructions very clear.

    try uninstalling the app and reinstalling it. u shouldnt need to install anything else but the app itself to get it running. if that doesnt work then update ur software and see if that works.

  • My computer crashed.  I now have a new one and I need to know how to sync my iPad without losing all the photos, contacts, podcasts, etc I have on my iPad.

    My computer crashed.  I now have a new one and I need to know how to sync my iPad without losing the photos, contacts, podcasts, apps, etc I have on my iPad.  Can anyone help?

    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    Some items cannot be redownloaded. You will need third-party software for them - Phone to Mac - Pod to Mac | Macroplant.com or Phone to PC | macroplant.com depending on your hardware.
    You might consider modifying your profile information so we will know what your hardware, OS, etc. is. Makes it easier to provided assistance.

  • .xmp not recognized by Bridge CS 5.5.  All previous solutions here not working for me.  Please help.

    First of all, this issue has existed for me since CS4.
    When I load an .nef file into photoshop from bridge, it opens in camera raw.  Once I edit that photo and send it to photoshop, an .xmp file is created and those changes should show up in bridge, but they don't.  Looking in my folder of raw files, I can see the .xmp file.
    To make matters more confusing, this only occurs with one of my two cameras.  I have two seemingly identical Nikon D300s DSLRs.  One with a 14mm and one with a 70-200 zoom.  Bridge's issue with failing to recognize .xmp files only occurs with folders that contain photos shot with the camera with the zoom lens.
    I have exhausted all of the solutions I have been able to find on this forum: telling my mac to open .xmp files with Bridge, telling Bridge to always use high quality thumbnails with 100% preview.
    Can someone please help?

    I have exhausted all of the solutions I have been able to find on this forum: telling my mac to open .xmp files with Bridge, telling Bridge to always use high quality thumbnails with 100% preview.
    For several years ago I decided to convert all my CR2 Raw files (I use Canon) to DNG upon ingestion of the files. Not only is DNG an open standard and therefor will it be long supported but mainly because I was growing mad of all the side car XMP files. DNG stores the XMP info into the file itself. No more hidden files no more mistakes in copy files leaving XMP lost in a folder, etc. etc.
    Although it is strange one dSLR has this problem and the other not I don't think it is lens related as Curt kindly suggested. To my knowledge lenses affect the EXIF data and Bridge creates the XMP Data as a sidecar file (by default selected in the Camera Raw preferences) with rating, labeling and ACR settings.
    By default Bridge also does not show hidden items (that XMP files are). Could you double check with Raw files from both cameras next to each other and after having altered them both in ACR (i.e. plus 2 in exposure to make a real difference) and in the Bridge menu view show hidden files (sort Bridge on filename for easy viewing).
    And if one is not showing the altered result could you click on it and with right mouse click menu check 'purge cache for selection and see if this changes things.  (If the changes are there in PS as Curt already asked this might also help)
    Could you also convert both files to DNG (Adobe has a free DNG converter for download (see also this link or Google it):
    http://www.adobe.com/products/photoshop/extend.displayTab2.html
    And could you provide a short summary of the solutions you already tried (all previous solutions is a little vague :-) )
    Having set XMP to open in Bridge is not important, XMP is not meant to be opened by the user, Bridge uses it to read and write but other apps also. For instance I just tested on an old CR2 file with XMP and by default it opens in Adobe Photoshop Elements (also on my system like CS5 Suite, Aperture and Lightroom) as I discovered using the get info command. Bridge wasn't even on the list for possible opening options :-)
    Also 100 % preview will not help, it just slows things down very much because the cache needs much more time to build and the cache file will grow to huge proportions...
    Only if you want to use to compare all files at 100 % you might benefit from that setting.

  • Enhancement request: Checkbox item - Default all checked

    When a page item with a display type of Checkbox is used in the WHERE clause of a report region (to show rows only if the corresponding checkbox is checked using the INSTR(item_name,column_name)>0 technique), it is frequently useful to render the page for the first time with all checkboxes checked.
    The only way I found to render a checkbox item with all values checked is to specify its "Source" attribute as a PL/SQL function body with
    declare
    l_retval varchar2(4000);
    begin
    for rec in (select d,r from <lov_query>) loop
       l_retval := l_retval || ':' || rec.r;
    end loop;
    return ltrim(l_retval,':');
    end;I don't like this solution because the LOV query is specified twice on the item properties page (in the LOV section and in this Source attribute). You need to remember to change it in both places.
    I think Apex should have a easier method to declaratively specify that checkbox-based items should be initially rendered with all values checked.
    Thanks

    Hello Vikas,
    Why not using an onLoad JavaScript code to mark your checkboxes?
    I was thinking about something similar to the check all checkboxes script, but target it to a specific item, and fired it on load.
    If you are using Px_ITEM1 as your checkbox item, the first option will always get the ID of Px_ITEM1_0. Using that, how about something like this:
    <script language="JavaScript" type="text/javascript">
    <!-- Hide
    function markBoxes(pItem){
      var itemId = pItem + '_0';
      var checkboxElm = $x(itemId).parentNode;
      var boxOption = checkboxElm.getElementsByTagName('input');
      for (var i=0; i < boxOption.length; i++) {
        boxOption.checked = true;
    // End Hide -->
    </script>
    This way you can keep only one LOV query, and because the tag name search is limited to one item, only its options will be checked.
    Regards,
    Arie.

  • Noob problem. Need solution

    Hi,
    I am new with Crystal Reports. I have been asked to resolve an issue that affects ALL of our users. When the user views a report, there will be a database login screen asking for login/pass for the ODBC database. ALL the users have the SAME password. Here is the screen that always pops up:
    [http://i146.photobucket.com/albums/r261/mikedavid00/ScreenHunter_02Oct131121.gif|http://i146.photobucket.com/albums/r261/mikedavid00/ScreenHunter_02Oct131121.gif]
    Once the person enters the correct info, it will show the report as usual.
    Is there any way to get rid of this?

    I guess we're having a bit of mis-communication here.
    We are a huge, national Frobes 50 company that you all know and love. I wouldn't be surprised if we are amongst SAP's largest clients.
    But we are in the real world. In the real world, there is no such thing as some BOE administrator. That is just a small portion of one persons job and does not consist of anyone's daily tasks.
    In the real world, there is not reports with ODBC connections showcasing peoples salaries. We have payroll departments with specialized payroll software that handles that. The fact you suggested there are reports shows you may not have experience in the 'real world'.
    In the real world, it is NOT acceptable to have a login for InfoView, and then bother and confuse the user for another separate login for the actual ODBC connection to the end user. This might make sense in the world of academia, but again, I am asking you from the real world and we need this issue resolved before we contact your 'support' and escalate a complaint.
    In Microsoft Reporting Services it is simple. The login and password to enter the db is saved directly on the online report on the website. After all, it's the online web based report that is accessing the database, NOT THE USER. Please see the picture below as proof:
    http://www.databasejournal.com/img/DJ_RS006-031.jpg
    So again, I have a hard time believing that it's a normal part of operation of have the actual USER prompted for the login and password for the ODBC connection. Again we're in the real world and prompting for passwords is a silly waste of our time and generates needles calls to our help desk.
    Do I need to create a DSN string with a login and password embedded when making the report?
    Please help.

  • SOS, need solution! Applet!

    Hi all,
    I urgently need solution for this program in Java, if sobebody can make this program for me, or even tell me where I can find solution and how?
    Thanks
    You are required to create an interface with the following choices:
    �Choice1: Enter a New Record
    �Choice 2: Modify An Existing Record
    �Choice3: Delete An Existing Record
    �Choice 4: View/Print An Existing Record
    �Choice 5: Exit
    You are implement the selection using the case structure.
    You output after running the applet should look as follows:
    Applet
    1.Enter a New Record
    2.Modify An Existing Record
    3.Delete An Existing Record
    4.View/Print An Existing Record
    5.Exit
    Enter Your Choice: 1
    //that number is in square, I couldn�t draw.
    You chose to add a record
    Applet started
    Important Note:
    You can create the menu as a text-based menu or you can use one of the
    layout managers included in Java. The layout manager inherit from class
    object and implement the layout manager interface. You can use the
    GridLayout layout manager to organise your menu. In this case you should
    Use the setLayout ( ) method.
    P.S. Scool project
    P.S.I�ve got this program to late, so there is no time to do, only solution is copy!

    I have done this kind of project....
    If you don't mind me asking when were you told to do this project..

  • Stop the Script - Pressing 'ESC' Key - Need Solutions.

    Dear All,
    Really I'm wondering "Press 'ESC' Key" the Script is Stopped. But OtherApplication 'EXE''s are not stopped even InDesign Plug-In also.
    Is there any solutions while I'm pressing 'ESC' key the InDesign Script is automatically stopped. But I need to run the script without any interruption using this 'ESC' or other keys. I tried so many RnD's, But I didn't get any solutuions.
    Please any one can knows let me know the solutions .
    Please any one can give the solutions I can appreciate.
    Thanks & Regards,
    Harihara SudhaN.T.R.

    Dear Harbs & Peter Kahrel
    Many thanks for this great replies.
    "I should try running scripts from the palette" - Peter Kahrel.
    I'm also tried so many times, but the script is stopped when I press [Interupt] the "Esc" KEY Button.
    One of my friend suggested "TSR" Programming to use comment the "ESC" KEY button action, after that running the ESTK Script then finally activate the "ESC" KEY button action. [Both STOP and START the "ESC" KEY Button action though create the "TSR" programming]
    1. Is it possible to Stop & Start the "ESC" KEY Button create through TSR Programming?
    2.  TSR Program we can use to ESTK script - is it possible?.
    I dont know what exactly the "Esc" Button is doing the operation. But the same time "Esc" Button is equal to "Cancel" button functionality - Java script Reference Guide mentioned.
    So what my understand in this ESTK - script is "ESC" button means "Cancel" button... I'm I right ? or else...
    Many thanks once again for the favour replies and pelase Mr. Harbs and Mr.Perter Kahrel let me know some more informations regarding this issue.
    I expect the detailed information regarding this issue, Please.
    Thanks & Regards
    Harihara SudhaN.T.R.,

  • I cant restore my iphone 4s since updating to ios7, error 29, tried all google solutions

    I cannot restore my daughters iphone 4s via itunes, since she updateds to ios7 latest version. error 29 keeps stopping the process. I have uninstalled and reistalled itunes, updated as per apple instructions and still same message.  Tried almost all google solutions except changing the battery - unsure what to do next

    Hello, helena1671. 
    Thank you for visiting Apple Support Communities. 
    The usual cause for error 29 on a restore of an iOS device usually mean a security software conflict or host file modifications.  Below, I have included a couple articles that will walk you through some troubleshooting steps. 
    Resolve issues between iTunes and security software
    http://support.apple.com/kb/TS3125
    Check your hosts file
    After you update iTunes to the latest version, check the hosts file to make sure your computer can contact the update server.
    If you’re using a Windows computer, follow the steps in this Microsoft support article (note that resetting thehosts file will affect software services that rely on hosts file redirects). If you're using Windows on a business computer, consult your IT department to be sure applications will work correctly after you reset the hosts file.
    If you're using a Mac, follow these steps:
    In the Finder, choose Applications > Utilities.
    Open Terminal.
    Enter this command and press Return:
    sudo nano /private/etc/hosts
    Enter the password you use to sign in to your computer and press Return. You won't see text appear in the Terminal window when you enter the password. Make sure you use a nonblank administrator password.
    Terminal will display the hosts file.
    Navigate using the arrow keys and look for an entry containing “gs.apple.com”.
    Add the # symbol and a space ("# ") to the beginning of the gs.apple.com entry.
    Press Control-O to save the file.
    Press Enter when asked for the filename and Control-X to exit the editor.
    Restart your computer.
    Try to update or restore your iOS device again.
    Error 3194, Error 17, or "This device isn't eligible for the requested build"
    http://support.apple.com/kb/ts4451
    Also, I would recommend not making any hardware modifications to the iOS device as it will void the warranty.  If service is needed please contact us here. 
    Cheers,
    Jason H. 

Maybe you are looking for

  • How do I install a version of vim with Python support?

    I'm trying to install a version of vim with Python support, but for some reason I can't seem to find anything useful when I search. So far I've found posts that say arch doesn't have one built with Python support, and use this <broken link> AUR packa

  • Need to access a context_node in an another view of the same component

    Hi experts, I need to access a context_node which is not in my view but it exist in an another view of the same component. The component is ICCMP_BP_DETAIL. i need the context_node "CUSTOMER" from the view Bupadetail to view Bupacreate. so that i can

  • How do I add photos in photo stream.how do I

    How do I add photos to photos team?

  • OIM Custom validation on entitlement request submission.

    Hi, We have a requirement in OIM to do some custom validation on entitlement request submission through catalogue. Can we leverage the requestdatavalidator here. Is there any other way of doing it? Thanks in advance,

  • Pls guide me in advance java

    hello everyone, I am new to java and learning core java and want to make 'ONLINE JOB PORTAL' project in java. so pls solve my queries 1. what are topics of advance java help in completing this project OR it requires html, dhtml,xml, java script etc.C