This is a JApplet.
the Radio Buttons for colos work.. why won't the Checkboxes work?
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class CheckRadioTest extends JApplet implements ItemListener
{
//private String CurrentComboName = "Select One";
private int currentStyle = Font.PLAIN;
//private int intBold = Font.PLAIN;
//private int intItalic = Font.PLAIN;
private Color currentColor = Color.black;
private JCheckBox cbBold , cbItalic ;
private JRadioButton rbRed , rbGreen , rbBlue; // mga Item... dili Action... ang button usa ra siya... Itemssssssssssssssssssssssss .. mao nang ItemEvent
private ButtonGroup ColorSelectGroup;
public void init()
{
Container c = getContentPane();
c.setLayout(null);
cbBold = new JCheckBox("Bold");
cbItalic = new JCheckBox("Italic");
rbRed = new JRadioButton("Red");
rbGreen = new JRadioButton("Green");
rbBlue = new JRadioButton("Blue");
cbBold.setSize(100,30);
cbItalic.setSize(100,30);
rbRed.setSize(100,20);
rbGreen.setSize(100,20);
rbBlue.setSize(100,20);
cbBold.setLocation(100,85);
cbItalic.setLocation(100,125);
rbRed.setLocation(310,60);
rbGreen.setLocation(310,100);
rbBlue.setLocation(310,150);
cbBold.addItemListener(this);
cbItalic.addItemListener(this);
rbRed.addItemListener(this);
rbGreen.addItemListener(this);
rbBlue.addItemListener(this);
c.add(cbBold);
c.add(cbItalic);
c.add(rbRed);
c.add(rbGreen);
c.add(rbBlue);
ColorSelectGroup = new ButtonGroup();
ColorSelectGroup.add(rbRed);
ColorSelectGroup.add(rbGreen);
ColorSelectGroup.add(rbBlue);
//NameComboBox = new JComboBox(Name);
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.orange);
g.drawRoundRect(75, 50 , 125 ,140 , 10 , 10); // x , y, width, length , height , thickness
g.drawRoundRect(275 , 50 ,125 , 140 , 10 , 10);
g.setColor(currentColor);
g.setFont(new Font("Courier", Font.PLAIN, 15));
g.drawString("HIGHTECH SIYA!!!" ,100, 30);
}
public void itemStateChanged (ItemEvent e)
{
if(e.getSource() == cbBold)
{
if(e.getStateChange() == ItemEvent.SELECTED)
currentStyle = Font.BOLD; //intBold
if(e.getStateChange() == ItemEvent.DESELECTED)
currentStyle = Font.PLAIN; //intBold
repaint();
}
if(e.getSource() == cbItalic)
{
if(e.getStateChange() == ItemEvent.SELECTED)
currentStyle = Font.ITALIC; //intItalic
if(e.getStateChange() == ItemEvent.DESELECTED)
currentStyle = Font.PLAIN; //intItalic
repaint();
}
if(e.getSource() == rbRed)
currentColor = Color.red;
else if(e.getSource() == rbGreen)
currentColor = Color.green;
else if(e.getSource() == rbBlue)
currentColor = Color.blue;
//if (e.getSource() == NameComboBox)
//Current = Name [NameComboBox.index()];
}
}