Home > Java > Java Program to write an Applet with Check Boxes handling and display output – Q55

Java Program to write an Applet with Check Boxes handling and display output – Q55

January 28, 2009 Leave a comment Go to comments

Q55: Java Program to write an applet, which shows a two set of check boxes. The first set is independent and second set belongs to a checkbox group (like radio buttons). Whichever check box is selected by the user, it should be displayed on the screen.

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

abstract class Ap_CheckboxGroupDemo extends Applet implements ItemListener{
 	String msg = "";
 	Checkbox Win98, WinNT;
 	CheckboxGroup cbg;
 	Button Win;
 	MyCheckbox myCheckbox1,myCheckbox2,myCheckbox3;

 	public void init(){
 		Win98 = new Checkbox("Windows 98/Xp");
 		WinNT = new Checkbox("Windows NT/2000");
 		cbg = new CheckboxGroup();
 		myCheckbox1 = new MyCheckbox("Item 1",cbg,true);
 		myCheckbox2 = new MyCheckbox("Item 2",cbg,false);
 		myCheckbox3 = new MyCheckbox("Item 3",cbg,false);
	public void paint(Graphics g){
		msg = "current state: ";
 		msg = "Windows 98/Xp:" + Win98.getState();
 		msg = "Windows NT/2000:" + WinNT.getState();

class MyCheckbox extends Checkbox{
 	public MyCheckbox(String label,CheckboxGroup cbg,boolean flag){
	protected void processItemEvent(ItemEvent ie){
		showStatus("checkbox name/state: " + getLabel() + 
 					"/" + getState());

… from College notes (BCA/MCA assignments):

Categories: Java Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: