Solved

About Checkbox

Posted on 1998-07-07
5
204 Views
Last Modified: 2010-08-05
Can anyone please let me know how to get the state of the checkbox and to set the state of the checkbox in runtime.  Also how to detect the checkbox items.

A detailed code in this regard will be very useful for me.

Thanking u in advance
Seena
0
Comment
Question by:seena
  • 2
  • 2
5 Comments
 

Expert Comment

by:musashi
ID: 1225206
this type of documentation is available online, see:
http://java.sun.com/products/jdk/1.1/docs/api/packages.html

specifically for checkboxes, see:
http://java.sun.com/products/jdk/1.1/docs/api/java.awt.Checkbox.html#_top_

0
 

Author Comment

by:seena
ID: 1225207
I have that documentation in my PC but what i need is a code which will explain me clearly how to set and check the checkbox state.

Thanks
0
 
LVL 2

Accepted Solution

by:
aziz061097 earned 50 total points
ID: 1225208

// Save this file in CheckBoxTest.java
// Compile and run it
import java.awt.*;
import java.awt.event.*;

public class CheckBoxTest extends Frame {
      Label lb;
      Checkbox cb;
public static void main(String args[]){

      CheckBoxTest cbFrame = new CheckBoxTest();
      cbFrame.setSize(300,400);
        cbFrame.setVisible(true);
}

CheckBoxTest(){

      setLayout(new FlowLayout());
      cb = new Checkbox("Check and Uncheck me");
      lb = new Label("Check box is not set");

      add(cb);
      add(lb);
      cb.addItemListener(new cbListener());
}

class cbListener implements ItemListener{
      public void itemStateChanged (ItemEvent e){

         System.out.println("State Changed");
         if (cb.getState())
              lb.setText("The Checkbox is set");
         else
            lb.setText("Check box is not set");
      }
   }

}
0
 
LVL 2

Expert Comment

by:aziz061097
ID: 1225209
For setting the state in runtime , you can do cb.setState(true) or cb.setState(false) anywhere in the program where the logic permits. (cb is the checkbox in the above program).
0
 

Author Comment

by:seena
ID: 1225210
Thanks for ur answer aziz

Seena
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now