Solved

About Checkbox

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

762 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

23 Experts available now in Live!

Get 1:1 Help Now