Java Program to write an Applet with Check Boxes handling and display output – Q55
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");
add(Win98);
add(WinNT);
Win98.addItemListener(this);
WinNT.addItemListener(this);
cbg = new CheckboxGroup();
myCheckbox1 = new MyCheckbox("Item 1",cbg,true);
add(myCheckbox1);
myCheckbox2 = new MyCheckbox("Item 2",cbg,false);
add(myCheckbox2);
myCheckbox3 = new MyCheckbox("Item 3",cbg,false);
add(myCheckbox3);
}
public void paint(Graphics g){
msg = "current state: ";
g.drawString(msg,6,80);
msg = "Windows 98/Xp:" + Win98.getState();
g.drawString(msg,6,100);
msg = "Windows NT/2000:" + WinNT.getState();
}
}
class MyCheckbox extends Checkbox{
public MyCheckbox(String label,CheckboxGroup cbg,boolean flag){
super(label,cbg,flag);
enableEvents(AWTEvent.ITEM_EVENT_MASK);
}
protected void processItemEvent(ItemEvent ie){
showStatus("checkbox name/state: " + getLabel() +
"/" + getState());
super.processItemEvent(ie);
}
}
… from College notes (BCA/MCA assignments):
Categories: Java
Java Applet Programs
Comments (0)
Trackbacks (0)
Leave a comment
Trackback




