Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 3.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
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
Old 12-06-2007, 06:27 PM   PM User | #2
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
Java World gives a pretty easy solution to understand as well as an explanation.

Java World
__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch
Aradon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:04 PM.


Advertisement
Log in to turn off these ads.