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,
actionHow can I modify my method to accommodate this?
Thanks