View Single Post
Old 12-06-2007, 05:29 PM   PM User | #1
trigger_tre
Regular Coder

 
Join Date: May 2006
Posts: 290
Thanks: 6
Thanked 14 Times in 14 Posts
trigger_tre is an unknown quantity at this point
How do I set font size in java

Hello I am working on an extra credit assignment. Its a simple road sign. I have completed it but I am confused on how to increase the font size.

Here is the component:

Code:
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import javax.swing.JPanel;
import javax.swing.JComponent;

/**
   A component that draws an alien face
*/
public class ExtraCreditComponent_TT extends JComponent
{
   public void paintComponent(Graphics g)
   {
      // Recover Graphics2D
      Graphics2D g2 = (Graphics2D) g;



      // Construct a rectangle with rounded corners
      g2.drawRoundRect( 150, 150, 300, 300, 10, 10 );

      // Draw the red circle
      Ellipse2D.Double circle = new Ellipse2D.Double(155, 155, 290, 290);
      g2.setColor(Color.RED);
      g2.fill(circle);
      g2.draw(circle);

      // Draw the white bar
      Rectangle mouth = new Rectangle(175, 275, 250, 50);
      g2.setColor(Color.WHITE);
      g2.fill(mouth);

      // Draw the greeting
      g2.setColor(Color.WHITE);
      g2.drawString("DO NOT", 200, 250);

      // Draw the greeting
      g2.setColor(Color.WHITE);
      g2.drawString("Enter", 200, 350);
   }
}
Here is my Viewer file:

Code:
import javax.swing.JFrame;

public class ExtraCreditViewer_TT
{
   public static void main(String[] args)
   {
      JFrame frame = new JFrame();
      frame.setSize(600, 600);
      frame.setTitle("Do Not Enter Sign");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      ExtraCreditComponent_TT component = new ExtraCreditComponent_TT();
      frame.add(component);

      frame.setVisible(true);
   }
}

I want to increase the size of the font but I am confused and was unable to google a suitable answer.

Is there a g2.something that I can input the parameter for?

-trigger
trigger_tre is offline   Reply With Quote