Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- /*
- CheckBox:-
- ~~~~~~~~~~
- Checkbox();
- Checkbox(String);
- Checkbox(String,boolean);
- Checkbox(String,boolean,CheckboxGroup);
- Checkbox(String,CheckboxGroup,boolean);
- Medhods:-
- String getLabel();
- void setLabel(java.lang.String);
- boolean getState();
- void setState(boolean);
- Object getSelectedObjects()[];
- CheckboxGroup getCheckboxGroup();
- void setCheckboxGroup(CheckboxGroup);
- void addItemListener(ItemListener);
- */
- import java.awt.event.*;
- import java.awt.*;
- import java.applet.*;
- /*
- <applet CODE = "CheckBoxDemo" Height = 400 Width= 400>
- </applet>
- */
- public class CheckBoxDemo extends Applet implements ItemListener
- {
- Checkbox c1, c2, c3, c4;
- String msg = "";
- public void init()
- {
- c1 = new Checkbox("Processor");
- c2 = new Checkbox("Monitor");
- c3 = new Checkbox("Keyboard");
- c4 = new Checkbox("Mouse");
- add(c1);
- add(c2);
- add(c3);
- add(c4);
- c1.addItemListener(this);
- c2.addItemListener(this);
- c3.addItemListener(this);
- c4.addItemListener(this);
- }
- public void itemStateChanged(ItemEvent ce)
- {
- msg = "";
- if(c1.getState())
- {
- msg += "Processor, ";
- }
- if(c2.getState())
- {
- msg += "Monitor, ";
- }
- if(c3.getState())
- {
- msg += "KeyBoard, ";
- }
- if(c4.getState())
- {
- msg += "Mouse, ";
- }
- repaint();
- }
- public void paint(Graphics g)
- {
- g.drawString("You bought : " +msg, 100, 100);
- }
- }

Post new comment