Current location: Hot Scripts Forums » Programming Languages » Everything Java » Font color Help


Font color Help

Reply
  #1 (permalink)  
Old 03-23-04, 03:51 PM
sly0193 sly0193 is offline
New Member
 
Join Date: Mar 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Font color Help

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);
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Font size tag :) Peef HTML/XHTML/XML 9 08-16-08 07:55 PM
font size on IE resize b0yakk HTML/XHTML/XML 7 02-22-04 12:20 PM
font question... b0yakk The Lounge 3 02-22-04 07:15 AM
font colour myo ASP 7 09-24-03 05:37 AM
font script seans9 Script Requests 7 09-10-03 01:15 PM


All times are GMT -5. The time now is 01:04 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.