?
Solved

About Checkbox

Posted on 1998-07-07
5
Medium Priority
?
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 150 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month12 days, 6 hours left to enroll

752 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