Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

convert String to Color or ColorConstants, help....

807589Dec 27 2008 — edited Dec 28 2008
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 25 2009
Added on Dec 27 2008
8 comments
358 views