This only does either BOLD or ITALIC...
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class CheckRadioTest extends JApplet implements ItemListener
{
//private String CurrentComboName = "Select One";
private JLabel headingLabel;
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 static String[] words = {"hohoho" , "hahaha" , "hihihi" , "hehehe"};
public static JComboBox myfirstcombobox = new JComboBox(words);
private JButton buttonAppend,buttonExit;
private ButtonEventHandler eventHandler;
public void init()
{
Container c = getContentPane();
c.setLayout(null);
headingLabel = new JLabel ("Default Text" , SwingConstants.CENTER);
headingLabel.setFont(new Font("Courier", Font.PLAIN, 12));
cbBold = new JCheckBox("Bold");
cbItalic = new JCheckBox("Italic");
rbRed = new JRadioButton("Red");
rbGreen = new JRadioButton("Green");
rbBlue = new JRadioButton("Blue");
//BUTTONS EVENT HANDLER
eventHandler = new ButtonEventHandler();
//EXIT BUTTON
buttonExit = new JButton("Change Text");
buttonExit.addActionListener(eventHandler);
cbBold.setSize(100,30);
cbItalic.setSize(100,30);
rbRed.setSize(100,10);
rbGreen.setSize(100,10);
rbBlue.setSize(100,10);
myfirstcombobox.setSize(100,30);
headingLabel.setSize(130,40);
buttonExit.setSize(130,30);
cbBold.setLocation(100,85);
cbItalic.setLocation(100,125);
rbRed.setLocation(310,60);
rbGreen.setLocation(310,100);
rbBlue.setLocation(310,150);
myfirstcombobox.setLocation(20,10);
headingLabel.setLocation(125,10);
buttonExit.setLocation(20,200);
cbBold.addItemListener(this);
cbItalic.addItemListener(this);
rbRed.addItemListener(this);
rbGreen.addItemListener(this);
rbBlue.addItemListener(this);
myfirstcombobox.addItemListener(this);
c.add(cbBold);
c.add(cbItalic);
c.add(rbRed);
c.add(rbGreen);
c.add(rbBlue);
c.add(myfirstcombobox);
c.add(headingLabel);
c.add(buttonExit);
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 , 24); // x , y, width, length , height , thickness
g.drawRoundRect(275 , 50 ,125 , 140 , 10 , 24);
g.setColor(currentColor);
g.setFont(new Font("Times New Roman", Font.PLAIN, 15));
g.drawString("super.paint(g)" ,300, 30);
}
private class ButtonEventHandler implements ActionListener
{
public void actionPerformed (ActionEvent a)
{
String str = myfirstcombobox.getSelectedItem().toString();
headingLabel.setText(str);
}
}
public void itemStateChanged (ItemEvent e)
{
if(e.getSource() == cbBold)
{
if(e.getStateChange() == ItemEvent.SELECTED)
{currentStyle = Font.BOLD; //intBold = Font.BOLD;
headingLabel.setFont(new Font("Courier", Font.BOLD, 12));}
if(e.getStateChange() == ItemEvent.DESELECTED)
{currentStyle = Font.PLAIN; //intBold = Font.PLAIN;
headingLabel.setFont(new Font("Courier", Font.PLAIN, 12));
repaint();}
}
if(e.getSource() == cbItalic)
{
if(e.getStateChange() == ItemEvent.SELECTED)
{currentStyle = Font.ITALIC; //intItalic = Font.Italic;
headingLabel.setFont(new Font("Courier", Font.ITALIC, 12));
repaint();}
if(e.getStateChange() == ItemEvent.DESELECTED)
{currentStyle = Font.PLAIN; //intItalic = Font.PLAIN;
headingLabel.setFont(new Font("Courier", Font.PLAIN, 12));
repaint();}
}
if(e.getSource() == rbRed)
{
currentColor = Color.red;
headingLabel.setForeground(Color.red);
repaint();
}
else if(e.getSource() == rbGreen)
{
currentColor = Color.green;
headingLabel.setForeground(Color.green);
repaint();
}
else if(e.getSource() == rbBlue)
{
currentColor = Color.blue;
headingLabel.setForeground(Color.blue);
repaint();
}
//if (e.getSource() == NameComboBox)
//Current = Name [NameComboBox.index()];
}
}