Checkbox
Choice
CheckboxGroup (Radio Buttons)
Public void itemStateChanged(ItemEvent)
{
------
------
}
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class FrameCheckbox extends Applet implements ItemListener
{
Checkbox cb1, cb2, cb3;
public void init()
{
cb1 = new Checkbox("Java");
cb2 = new Checkbox("VB");
cb3 = new Checkbox("C++");
add(cb1);
add(cb2);
add(cb3);
cb1.addItemListener(this);
cb2.addItemListener(this);
cb3.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
repaint();
}
public void paint(Graphics g)
{
g.drawString("Books Selected",100,100);
if(cb1.getState())
{
g.drawString("Java",100,120);
}
if(cb2.getState())
{
g.drawString("VB",100,130);
}
if(cb3.getState())
{
g.drawString("C++",100,140);
}
}
}
import java.applet.*;
import java.awt.event.*;
public class FrameCheckbox extends Applet implements ItemListener
{
Checkbox cb1, cb2, cb3;
public void init()
{
cb1 = new Checkbox("Java");
cb2 = new Checkbox("VB");
cb3 = new Checkbox("C++");
add(cb1);
add(cb2);
add(cb3);
cb1.addItemListener(this);
cb2.addItemListener(this);
cb3.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
repaint();
}
public void paint(Graphics g)
{
g.drawString("Books Selected",100,100);
if(cb1.getState())
{
g.drawString("Java",100,120);
}
if(cb2.getState())
{
g.drawString("VB",100,130);
}
if(cb3.getState())
{
g.drawString("C++",100,140);
}
}
}
Click new -> File -> html and save this file as FrameCheckbox.html
<BODY>
<Applet code=FrameCheckbox.class height=200 width=400 >
</Applet>
</BODY>
<BODY>
<Applet code=FrameCheckbox.class height=200 width=400 >
</Applet>
</BODY>
Applet : This is to display Radio Buttons.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class FrameCheckboxGroup extends Applet implements ItemListener
{
Checkbox cb1, cb2;
CheckboxGroup cbg1;
public void init()
{
cbg1 = new CheckboxGroup();
cb1 = new Checkbox("Male",cbg1,false);
cb2 = new Checkbox("Female",cbg1,false);
add(cb1);
add(cb2);
cb1.addItemListener(this);
cb2.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
repaint();
}
public void paint(Graphics g)
{
g.drawString("Sex is : ",100,100);
if(cb1.getState())
{
g.drawString("Male",150,100);
}
if(cb2.getState())
{
g.drawString("Female",150,100);
}
}
}
Click new -> File -> html and save this file as FrameCheckboxGroup.html
<BODY>
<Applet code=FrameCheckboxGroup.class height=200 width=400 >
</Applet>
</BODY>
import java.applet.*;
import java.awt.event.*;
public class FrameCheckboxGroup extends Applet implements ItemListener
{
Checkbox cb1, cb2;
CheckboxGroup cbg1;
public void init()
{
cbg1 = new CheckboxGroup();
cb1 = new Checkbox("Male",cbg1,false);
cb2 = new Checkbox("Female",cbg1,false);
add(cb1);
add(cb2);
cb1.addItemListener(this);
cb2.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
repaint();
}
public void paint(Graphics g)
{
g.drawString("Sex is : ",100,100);
if(cb1.getState())
{
g.drawString("Male",150,100);
}
if(cb2.getState())
{
g.drawString("Female",150,100);
}
}
}
Click new -> File -> html and save this file as FrameCheckboxGroup.html
<BODY>
<Applet code=FrameCheckboxGroup.class height=200 width=400 >
</Applet>
</BODY>
Applet : Choice (Dropdown List)
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class FrameChoice extends Applet implements ItemListener
{
Choice c;
public void init()
{
c = new Choice();
c.add("Select Option");
c.add("Under Graduate");
c.add("Graduate");
c.add("Post Graduate");
add(c);
c.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
repaint();
}
public void paint(Graphics g)
{
g.drawString("Qualification : ",100,100);
String s1 = c.getSelectedItem();
if(s1 == "Under Graduate")
{
g.drawString("Under Graduate",200,100);
}
if(s1 == "Graduate")
{
g.drawString("Graduate",200,100);
}
if(s1 == "Post Graduate")
{
g.drawString("Post Graduate",200,100);
}
}
}
import java.applet.*;
import java.awt.event.*;
public class FrameChoice extends Applet implements ItemListener
{
Choice c;
public void init()
{
c = new Choice();
c.add("Select Option");
c.add("Under Graduate");
c.add("Graduate");
c.add("Post Graduate");
add(c);
c.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
repaint();
}
public void paint(Graphics g)
{
g.drawString("Qualification : ",100,100);
String s1 = c.getSelectedItem();
if(s1 == "Under Graduate")
{
g.drawString("Under Graduate",200,100);
}
if(s1 == "Graduate")
{
g.drawString("Graduate",200,100);
}
if(s1 == "Post Graduate")
{
g.drawString("Post Graduate",200,100);
}
}
}
Click new -> File -> html and save this file as FrameChoice.html
<BODY>
<Applet code=FrameChoice.class height=200 width=400 >
</Applet>
</BODY>
<BODY>
<Applet code=FrameChoice.class height=200 width=400 >
</Applet>
</BODY>