How can i get a counter to tell me how many checkboxes have been selected?

package arabiclanguagelearning;
import java.awt.BorderLayout;
import java.awt.Frame;
import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.Rectangle;
import javax.swing.JTextArea;
import com.borland.jbcl.layout.VerticalFlowLayout;
import javax.swing.JLabel;
import javax.swing.*;
import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.CheckboxGroup;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent;
* <p>Title: Arabic Language Learning</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: </p>
* @author iPortal
* @version 1.0
public class ReadingTest extends JDialog implements ItemListener{
    //ImageIcon myImage = new ImageIcon("image.jpg");
    JPanel panel1 = new JPanel();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JButton jButton1 = new JButton(new ImageIcon ("image.jpg"));
    ButtonGroup question1 = new ButtonGroup();
    CheckboxGroup question2 = new CheckboxGroup();
    JTextArea question1Text = new JTextArea();
    JRadioButton q1A = new JRadioButton();
    JRadioButton q1B = new JRadioButton();
    JRadioButton q1C = new JRadioButton();
    JTextArea question2Text = new JTextArea();
    JTextField question2TextArabic = new JTextField();
    JCheckBox jCheckBox1 = new JCheckBox();
    JCheckBox jCheckBox2 = new JCheckBox();
    JCheckBox jCheckBox3 = new JCheckBox();
    JCheckBox jCheckBox4 = new JCheckBox();
    JLabel jLabel2 = new JLabel();
    StringBuffer choices;
    //will keep a count on how many checkboxes selected for question 2
    int count;
    JLabel jLabel4 = new JLabel();
    JLabel jLabel5 = new JLabel();
    JLabel jLabel6 = new JLabel();
    JButton Submit = new JButton();
    JLabel jLabel7 = new JLabel();
    public ReadingTest(Frame owner, String title, boolean modal) {
        super(owner, title, modal);
        try {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jbInit();
            pack();
        } catch (Exception exception) {
            exception.printStackTrace();
    public ReadingTest() {
        this(new Frame(), "ReadingTest", false);
    private void jbInit() throws Exception {
        panel1.setLayout(null);
        this.getContentPane().setLayout(null);
        jLabel1.setFont(new java.awt.Font("Tahoma", Font.BOLD, 24));
        jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel1.setIcon(null);
        jLabel1.setText("Welcome to the reading tutorial");
        jLabel1.setBounds(new Rectangle(49, 4, 509, 67));
        jLabel3.setFont(new java.awt.Font("Tahoma", Font.PLAIN, 14));
        jLabel3.setToolTipText("");
        jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel3.setHorizontalTextPosition(SwingConstants.CENTER);
        jLabel3.setText(
                "Please answer the questions below after reading the text");
        jLabel3.setVerticalTextPosition(SwingConstants.TOP);
        jLabel3.setBounds(new Rectangle(48, 83, 515, 60));
        jButton1.setBounds(new Rectangle(509, 63, 98, 44));
        jButton1.setText("Hide me!");
        jButton1.addActionListener(new ReadingTest_jButton1_actionAdapter(this));
        question1Text.setBackground(Color.lightGray);
        question1Text.setFont(new java.awt.Font("Tahoma", Font.BOLD, 14));
        question1Text.setEditable(false);
        question1Text.setText("What is the first letter of the arabic alphabet?");
        question1Text.setBounds(new Rectangle(64, 158, 319, 19));
        q1A.setFont(new java.awt.Font("Tahoma", Font.BOLD, 16));
        q1A.setText("?");
        q1A.setBounds(new Rectangle(60, 189, 93, 23));
        q1B.setFont(new java.awt.Font("Tahoma", Font.BOLD, 16));
        q1B.setText("?");
        q1B.setBounds(new Rectangle(60, 214, 93, 23));
        q1C.setFont(new java.awt.Font("Tahoma", Font.BOLD, 16));
        q1C.setText("?");
        q1C.setBounds(new Rectangle(60, 241, 93, 23));
        question2Text.setBackground(Color.lightGray);
        question2Text.setFont(new java.awt.Font("Tahoma", Font.BOLD, 14));
        question2Text.setEditable(false);
        question2Text.setText(
                "Choose the two correct words which finish the sentence.");
        question2Text.setBounds(new Rectangle(64, 281, 402, 19));
        question2TextArabic.setFont(new java.awt.Font("Tahoma", Font.BOLD, 16));
        question2TextArabic.setText("?? ????? ??????? ___ ???? ___ ?? ???????");
        question2TextArabic.setBounds(new Rectangle(63, 311, 404, 30));
        this.setForeground(Color.white);
        jCheckBox1.setFont(new java.awt.Font("Tahoma", Font.BOLD, 13));
        jCheckBox1.setText("????");
        jCheckBox1.setBounds(new Rectangle(63, 356, 81, 23));
        jCheckBox1.addActionListener(new ReadingTest_jCheckBox1_actionAdapter(this));
        jCheckBox1.addItemListener(this);
        jCheckBox2.setFont(new java.awt.Font("Tahoma", Font.BOLD, 13));
        jCheckBox2.setText("????");
        jCheckBox2.setBounds(new Rectangle(162, 356, 81, 23));
        jCheckBox2.addItemListener(this);
        jCheckBox3.setFont(new java.awt.Font("Tahoma", Font.BOLD, 13));
        jCheckBox3.setText("??????");
        jCheckBox3.setBounds(new Rectangle(260, 356, 81, 23));
        jCheckBox3.addItemListener(this);
        jCheckBox4.setFont(new java.awt.Font("Tahoma", Font.BOLD, 13));
        jCheckBox4.setText("?????");
        jCheckBox4.setBounds(new Rectangle(359, 355, 81, 23));
        jCheckBox4.addItemListener(this);
        jLabel2.setText("jLabel2");
        jLabel2.setBounds(new Rectangle(63, 402, 234, 32));
        jLabel4.setText("jLabel4");
        jLabel4.setBounds(new Rectangle(63, 433, 254, 28));
        jLabel5.setText("jLabel5");
        jLabel5.setBounds(new Rectangle(63, 465, 194, 37));
        jLabel6.setText("jLabel6");
        jLabel6.setBounds(new Rectangle(63, 500, 258, 32));
        Submit.setBounds(new Rectangle(507, 575, 115, 52));
        Submit.setText("Submit");
        Submit.addActionListener(new ReadingTest_Submit_actionAdapter(this));
        jLabel7.setText("jLabel7");
        jLabel7.setBounds(new Rectangle(472, 480, 95, 34));
        question1.add(q1A);
        question1.add(q1B);
        question1.add(q1C);
        this.getContentPane().add(panel1, null);
        this.getContentPane().add(Submit);
        panel1.add(jLabel1);
        panel1.add(jLabel3);
        panel1.add(q1A);
        panel1.add(q1B);
        panel1.add(q1C);
        panel1.add(question1Text);
        panel1.add(question2Text);
        panel1.add(question2TextArabic);
        panel1.add(jCheckBox1);
        panel1.add(jCheckBox2);
        panel1.add(jCheckBox3);
        panel1.add(jCheckBox4);
        panel1.add(jButton1);
        panel1.add(jLabel6);
        panel1.add(jLabel5);
        panel1.add(jLabel4);
        panel1.add(jLabel2);
        panel1.add(jLabel7);
        panel1.setBounds(new Rectangle(10, 10, 623, 549));
    public void jButton1_actionPerformed(ActionEvent e) {
        this.setVisible(false);
    public void itemStateChanged(ItemEvent e) {
        int index = 0;
        char c = '-';
        Object source = e.getItemSelectable();
//count variable works fine in this part
        if (source == jCheckBox1) {
            index = 0;
            c = 'c';
            //assign new string variable the value of text for the checkbox
            String textSelected = jCheckBox1.getText();
            jLabel2.setText("You checked"+ textSelected);
            count = count + 1;
            jLabel7.setText(Integer.toString(count));
        } else if (source == jCheckBox2) {
            index = 1;
            c = 'g';
            String textSelected = jCheckBox2.getText();
            jLabel4.setText("You checked"+ textSelected);
            count = count + 1;
            jLabel7.setText(Integer.toString(count));
        } else if (source == jCheckBox3) {
            index = 2;
            c = 'h';
            String textSelected = jCheckBox3.getText();
            jLabel5.setText("You checked"+ textSelected);
            count = count + 1;
            jLabel7.setText(Integer.toString(count));
        } else if (source == jCheckBox4) {
            index = 3;
            c = 't';
            String textSelected = jCheckBox4.getText();
            jLabel6.setText("You checked"+ textSelected);
            count = count + 1;
            jLabel7.setText(Integer.toString(count));
        //Now that we know which button was pushed, find out
         //whether it was selected or deselected.
//count variable does not work in this section.
         if (e.getStateChange() == ItemEvent.DESELECTED) {
             c = '-';
             Object deselectedItem = e.getItemSelectable();
             if (deselectedItem==jCheckBox1)
                 jLabel2.setText("You deselected checkbox 1");
                 count = count - 1;
                 jLabel7.setText(Integer.toString(count));
             else if (deselectedItem==jCheckBox2)
                 jLabel4.setText("You deselected checkbox 2");
                 count = count - 1;
                 jLabel7.setText(Integer.toString(count));
             else if (deselectedItem==jCheckBox3)
                 jLabel5.setText("You deselected checkbox 3");
                 count = count - 1;
                 jLabel7.setText(Integer.toString(count));
             else if (deselectedItem==jCheckBox4)
                 jLabel6.setText("You deselected checkbox 4");
                 count = count - 1;
                 jLabel7.setText(Integer.toString(count));
   

you can call your_checkbox.isSelected() to know whether it's selected for all your check boxes !
suppose you have an jcheckbox array : JCheckBox[] myCheckBoxArray = ...;
int counter = 0;
for(int i=0; i<myCheckBoxArray.legth; i++){
  if(myCheckBoxArray.isSelected())
  counter++;
}and that's all

Similar Messages

  • How can I get Verizon to install fiber in my neighborhood? Have been waiting 10 years.

    How can I get Verizon to install fiber in my neighborhood?
    I have been on the notification list for nearly 10 years with no action.
    Current DSL download speed is only 3.0 Mbps, the max available for copper twisted pair, so I am told by tech support.
    Unless Verizon will install fiber in my neighborhood, my only option to obtain faster internet service is to change to another provider, though I would prefer to remain a Verizon customer.
    Any suggestions for alternate providers, under the circumstances?
    Thanks
    Solved!
    Go to Solution.

    Forget it. I've been waiting 13 years and every town around me has Fios, in fact my town is a small [27k population] city who provides the phone exchange numbers for the surrounding towns with Fios! Figure that out. I myself have given up and am moving on to Time Warner for my internet and phone and will not return even if fios does appear before the end times.. They are actually cheaper than verizon when flat rate phone service and real broadband speeds are figured in. Verizon only has last century's DSL technology available. Leave verizon, they don't care if do or not.

  • How can I get record count with a query?

    In Client/Server pplication,the client send a query to server.
    How can server get record count by oracle call interface?
    Is it need execute "select count(*) from ...."?

    Yes.
    Either that or increment a counter for each record fetched and
    loop round until you hit the last record.
    The first method would be more efficient on large datasets.

  • How can I get a count of objects in the near cache? (Extend client)

    Hi,
    I'm trying to figure out how to get the count of objects in my near cache (from c++ client). Knowing the size of the near cache is a key factor when optimizing configurations for performance.
    However if I call size() on the cache handle I get the count of objects in the cache (ie the cluster). How can I get a count of objects in the near cache?
    Thanks
    Rich Carless

    H Rich,
    It may not be ideal, but I think you may be able to infer the size by using the HeapAnalyzer (http://download.oracle.com/docs/cd/E15357_01/coh.360/e15728/classcoherence_1_1lang_1_1_heap_analyzer.html) facility, specifically the "class" based HeapAnalyzer. Its Snapshot representation http://download.oracle.com/docs/cd/E15357_01/coh.360/e15728/classcoherence_1_1lang_1_1_class_based_heap_analyzer_1_1_snapshot.html provides a mapping between class name and ClassStats (http://download.oracle.com/docs/cd/E15357_01/coh.360/e15728/classcoherence_1_1lang_1_1_class_based_heap_analyzer_1_1_class_stats.html) which provides information on how many instances of a given class type are in memory. Note the reported counts are process wide but if your key or value type are distinct you may be able to infer your answer. I realize this is rather complex, my only other suggestion would be to just make some guesses on size and see how they effect performance.
    Mark
    Oracle Coherence

  • How can i get ios 7 in my ipad 2? i have tried to update it but in my setting general there is no icon for software update.so help me please!

    how can i get ios 7 in my ipad 2? i have tried to update it but in my setting>general there is no icon for software update.so help me please!

    If you are using iOS 4 (or earlier) there is no Software Update in Settings. That feature was first added in iOS 5.
    To update you will have to connect your iPad to iTunes on a computer (preferably the one you sync with and backup to).
    See here: http://support.apple.com/kb/HT4972

  • I have purchased tv shows on my I pad in I tunes yet they don't show on my iPad anywhere!i have tried syncing to my pc and they show and can be viewed in there.how can I get them to show on my iPad?i have turned on home sharing as well!

    I have purchased tv shows on my I pad in I tunes yet they don't show on my iPad anywhere!i have tried syncing to my pc and they show and can be viewed in there.how can I get them to show on my iPad?i have turned on home sharing as well!

    Where are you looking on your iPad for the shows?  In iTunes?  If so, look under Videos.

  • How can I get computer to use external DVD drive?I have a HP dvd640 plug in play drive I want to ude but my iMac dosen't see it as connected.

    How can I get *computer* to use external DVD drive? (1.8 GHz PowerPC G5 Version 10.3.9)

    Place cd/dvd in drive.  cd/dvd icon will show on desktop.
    How can I get computer to use external DVD drive?I have a HP dvd640 plug in play drive I want to ude but my iMac dosen't see it as connected.
    What is ude?
    How is it connected?  firewire or usb?
    When connected it should appear in system profiler.
    blue apple > about this mac > more info button. Click on the hardware line. It has a little triangle in front of the work hardware.
    look for firewire or usb.
    Robert

  • How can I get rid of app upgrades, when I no longer have the app?

    How can I get rid of app upgrades , when I no longer have those particular apps?

    If the app is no longer installed on the iPad then you should get prompts about updates to it in the App Store app - as efectively there is nothing for it to update. If you are being prompted to download updates to them then are you sure that they are no longer on the iPad ?
    If you are being prompted on your computer's iTunes then if you delete them for the App part of you computer's Library then you shouldn't be prompted about them.

  • How can i get iCloud on my iPhone 3g it doesn't have software update or any graphics plz help

    please help how can i get graphics and sftware download on my iphone i have no update on my ph either

    If you have a 3G you can't use iCloud as iCloud requires iOS 5 or higher and the 3G cannot be updated beyond iOS 4.2.1. 
    If you have a 3GS, update it to iOS 6 by connecting it to iTunes.  If you aren't prompted to update, go to the Summary tab of your iTunes sync settings and click Check for Update.  After updating you can set it up as shown here: http://www.apple.com/icloud/setup/ios.html.

  • My iPad2 side switch is acting up, it will only allow me to have either sound or rotate. If I unmute the rotate won't work, if I mute the rotate works. How can I get the iPad to unmute and rotate? I have restored, downloaded updates and rebooted.

    My iPad2 side switch is acting up, it will only allow me to have either sound or rotate. If I unmute the rotate won't work, if I mute the rotate works. How can I get the iPad to unmute and rotate? I have restored, downloaded updates and rebooted.

    You should be able to control the function that the side switch isn't controlling via the left-hand end of the taskbar : http://support.apple.com/kb/HT4085 - is the icon that appears there (notification mute or rotation lock) indicating that that function is 'off' ?

  • HT3819 Ever sinve I updated the software on my phone I have not been able to download all my previously bought music onto either my phone or laptop. How can I get all my music on my laptop as I have spent a lot of money on itunes

    Ever sinve I updated the software on my phone I have not been able to download all my previously bought music onto either my phone or laptop. How can I get all my music on my laptop as I have spent a lot of money on itunes

    See Recover your iTunes library from your iPod or iOS device (or purchase history).
    tt2

  • How can i get a solution for this message "Your Apple ID has been disabled"?

    How can i get a solution for this message "Your Apple ID has been disabled"?

    Contact iTunes Store support. That message can mean one of several things:
    Your credit card on file has expired
    The credit card issuer has denied a charge
    Your account has been hacked
    Key information in your account has changed, and Apple needs to contact you to confirm the change.

  • HT201303 It keeps saying that I used a different computer to access my account. I haven't. How can I get it to stop this so I don't have to enter my card number every time?

    It keeps saying that I used a different computer to access my account. I haven't. How can I get it to stop this so I don't have to enter my card number every time?

    It also says that "your account information has changed. Please review your account and email address and approve them for use in the itunes store." It happens EVERY time I buy a new song, a new album, anything. Even if I buy an album and five minutes later, without closing itunes, buy another one, I have to go through this whole process. It's REALLY annoying.

  • How can i get the count vaule from GPIB?

    I want to get the count waule from GPIB ,but I find that the vaule I get from GPIB now is the trace vaule ,
    so I ask How can i get it.

    The count of what? What kind of instrument are you using?

  • How can I get a count at the same time I am inserting into another table

    I have a requirement where I have to find out the count(number of records inserted into another table) at the same time I insert into the table:
    Like
    I am copying records from table B to A, while doing this I have to find out how many records I've inserted since I need this count in subsequent steps
    INSERT INTO A
    SELECT * FROM B
    how can I store the count into any variable while doing above statement
    Please advice

    No, Warren that doesn't work!
    SQL> set serveroutput on
    SQL> declare
      2     vCtr  number := 0;
      3  begin
      4     insert into emp2
      5     select * from emp;
      6
      7     select count(*)
      8       into vCtr
      9       from emp2;
    10
    11     dbms_output.put_line('rows created '||to_char(vCtr));
    12  end;
    13  /
    rows created 15
    PL/SQL procedure successfully completed.
    SQL> declare
      2     vCtr  number := 0;
      3  begin
      4     insert into emp2
      5     select * from emp;
      6
      7     select count(*)
      8       into vCtr
      9       from emp2;
    10
    11     dbms_output.put_line('rows created '||to_char(vCtr));
    12  end;
    13  /
    rows created 30
    PL/SQL procedure successfully completed.
    SQL>

Maybe you are looking for