Hi I have wrote the following up to now but i would like to add another combobox to change the text "sylvain" from black to red and vice-versa.. but i'm new to this Java thing and don't know how. could anyone help me.
Thanks
//*************************************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class SylvainFont extends JApplet
{
private int fontSize = 24;
private int fontStyle = Font.PLAIN;
private String fontName = "Sans Serif";
public SylvainFont()
{
final JLabel label = new JLabel("Sylvain");
label.setFont(new Font(fontName, fontStyle, fontSize));
final JPanel labelPanel = new JPanel(new GridBagLayout());
getContentPane().add(labelPanel, BorderLayout.CENTER);
labelPanel.add(label);
JToolBar toolBar = new JToolBar();
getContentPane().add(toolBar, BorderLayout.NORTH);
final JPanel fontPanel = new JPanel();
fontPanel.add(new JLabel("Font Name"));
final JComboBox fontNameComboBox =
new JComboBox(new String[] { fontName, "TimesNewRoman", "Arial",
"Batang", "Serif" });
fontNameComboBox.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
fontName = (String) fontNameComboBox.getSelectedItem();
label.setFont(new Font(fontName, fontStyle, fontSize));
}
});
fontPanel.add(fontNameComboBox);
fontPanel.add(new JLabel("Font Style"));
final JComboBox fontStyleComboBox =
new JComboBox(new String[] { "Plain","Italic" , "Bold" ,
"Italic & Bold" });
fontStyleComboBox.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
String string =
(String) fontStyleComboBox.getSelectedItem();
if ("Plain".equals(string))
{
fontStyle = Font.PLAIN;
}
else if ("Italic".equals(string))
{
fontStyle = Font.ITALIC;
}
else if ("Bold".equals(string))
{
fontStyle = Font.BOLD;
}
else
{
fontStyle = Font.BOLD | Font.ITALIC;
}
label.setFont(new Font(fontName, fontStyle, fontSize));
}
});
fontPanel.add(fontStyleComboBox);
fontPanel.add(new JLabel("Font Size"));
final JSpinner fontSizeSpinner =
new JSpinner(new SpinnerNumberModel(fontSize, 12, 80, 4));
fontSizeSpinner.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
fontSize = ((Number) fontSizeSpinner.getValue()).intValue();
label.setFont(new Font(fontName, fontStyle, fontSize));
}
});
fontPanel.add(fontSizeSpinner);
toolBar.setLayout(new BoxLayout(toolBar, BoxLayout.Y_AXIS));
toolBar.add(fontPanel);
}
public static void main(String[] args)
{
JFrame frame = new JFrame("Font Selector");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.getContentPane().add(new SylvainFont());
int height = 250;
int width = 600;
frame.setSize(width, height);
frame.setVisible(true);
}
}