The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Add stylesheet to Java
Gooo
post Aug 8 2009, 11:25 AM
Post #1


Novice
**

Group: Members
Posts: 23
Joined: 16-May 09
Member No.: 8,619



Hi

I'm creating a tag cloud in Java. The words must be different colours.

Is it possible to add a stylesheet to java, and how?, for example:
CODE
word
{
font-family: Arial;
font-size: 30;
}


or can I only use the Graphics class?


Thanks
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 8 2009, 12:00 PM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Maybe this tells you more than it it does me.
http://java.sun.com/j2se/1.4.2/docs/api/ja...StyleSheet.html
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Gooo
post Aug 10 2009, 12:12 AM
Post #3


Novice
**

Group: Members
Posts: 23
Joined: 16-May 09
Member No.: 8,619



Thanks for your help.

I figured it out. Made use of the Graphics class
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Gooo
post Aug 10 2009, 01:27 AM
Post #4


Novice
**

Group: Members
Posts: 23
Joined: 16-May 09
Member No.: 8,619



I've got a question about the paint method.

My Code:
CODE
Integer[] lengths = {1,7,3,12,1};
String[] words = {"horror","thriller","comedy","drama","action"};

public void paint(Graphics g)
    {
        Graphics2D g2;
        g2 = (Graphics2D) g;

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);

        g2.setRenderingHint(RenderingHints.KEY_RENDERING,
                            RenderingHints.VALUE_RENDER_QUALITY);

        int w = getSize().width;
        int h = getSize().height;

        AffineTransform at = new AffineTransform();
        at.setToTranslation(30, 50);

        AffineTransform fontAT = new AffineTransform();
        fontAT.shear(0.2, 0.0);

        FontRenderContext frc = g2.getFontRenderContext();
        String s = new String("Still Life with Text");
        TextLayout tstring = new TextLayout(s, big, frc);

        Font theDerivedFont = big.deriveFont(fontAT);
        String str = new String("Still Life with Slanted Text");
        TextLayout tstring2 = new TextLayout(str, theDerivedFont, frc);

        for(int i = 0; i < lengths.length; i++)
        {
            int totalInt = lengths[i];
            if(totalInt <= 2)
            {
                g2.setFont(small);
                g2.setColor(Color.lightGray);
            }
            else if(totalInt > 2 && totalInt < 7)
            {
                g2.setFont(medium);
                g2.setColor(Color.gray);
            }
            else
            {
                g2.setFont(big);
                g2.setColor(Color.darkGray);
            }
        g2.drawString(words[i], 35, 35);
        }
    }


When the words are displayed they are placed on top of each other. I want the words be written next to each other in the same way they are read in.

I want the output to be:
horror, thriller, comedy, drama, action

How can I modify my method to accommodate this?

Thanks
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2024 - 10:59 PM