The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

simple question about clipping

Posted by Bev on August 01, 2001 at 5:49 AM

Hi,

I am studying a long distance course in Java (I have no prior programming experience) and have come unstuck on what is probably rather a simple question: as follows:

"Design and implement an applet which generates positive integers and displays each one together with a suitable message (i.e "The number is: 2") at 2 second intervals. The font should be Courier, bold, 24 points. Use clipping to minimise flicker"

My answer thus far:

import java.awt.*;
public class NumberGenerator extends Tasking Applet
{
Font theFont;
int count, stringwidth, stringheight;
FontMetrics fm;

public void init()

{
theFont = new Font ("Courier, Font.BOLD, 24);
setForeground(Color.blue);
fm = getFontMetrics(theFont);
count = count+1;
stringheight = fm.getHeight
stringwidth = ?????????
etc.......

I am assuming thus far that I have got everything correct but I am having difficulty with working out the call to return the width in pixels and assign it to the stringwidth variable -

I thought it might be: stringwidth = fm.getWidth(count); but this doesn't seem to work.

Any assistance would be greatly appreciated.
Many thanks
Bev.






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us