Hi,
I want to convert the english name of a color(e.g. red, blue, orange etc) to a color or coloconstant, but I can't. The color name is supposed to be taken from the suer arguement. Below is my code, but I don't know how to convert a string to ColorConstant. Any helpful input is appreciated.
import java.awt.Color;
import java.awt.Font;
import javax.swing.JApplet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleConstants.ColorConstants;
/** @author Kaka */
public class DisplayMessage extends JApplet {
@Override
public void init() {
// Get parameter values from the HTML file
String fontName = null, fontColor = null;
int fontSize = 0;
String message = getParameter("MESSAGE");
int x = Integer.parseInt(getParameter("X"));
int y = Integer.parseInt(getParameter("Y"));
fontName = getParameter("FONTNAME");
fontColor = getParameter("COLOR").toUpperCase();
fontSize = Integer.parseInt("FONTSIZE");
//Color color = Color.getColor(fontColor.toUpperCase());
// Create a message panel
MessagePanel messagePanel = new MessagePanel(message);
messagePanel.setXCoordinate(x);
messagePanel.setYCoordinate(y);
// Set the font of the message
messagePanel.setFont(new Font(fontName, fontColor, fontSize));
// add the message panel to the applet
add(messagePanel);
}
}
Thank you peace.