Solved

About Checkbox

Posted on 1998-07-07
5
208 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

733 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