Solved

About Checkbox

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…

729 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