The Artima Developer Community
Sponsored Link

Java Answers Forum
applet number generator

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
omer

Posts: 1
Nickname: homer12
Registered: Feb, 2004

applet number generator Posted: Feb 2, 2004 5:28 AM
Reply to this message Reply
Advertisement
Hi Everyone

im new to java so any help will be much appreciated. im trying to create an applet which generates positive integers (1,2,3....) and displays each one, together with a message, at 2 second intervals. i need to use clipping to minimise flicker. below is what i have done so:

the output needs to be like:
THE NUMBER IS : 3


import java.awt.*;

public class NumberGenerator extends TaskingApplet
{
Font theFont;
FontMetrics fm;
int stringwidth, stringheight, count;

public void init()
{
theFont = new Font ("Courier", Font.BOLD, 24);
setForeground(Color.blue);
fm = getFontMetrics (theFont);
String str="12345";
count = count + 1;
stringheight = fm.getHeight();
stringwidth = fm.stringWidth(str);
}

public void run()
{
while (true)
{
count = new count();
repaint();
try {Thread.sleep (1000);}
catch (InterruptedException e) { }
}
}

public void update (Graphics g)
{
g.setColor(getBackground());
g.clipRect(10, 50 - stringheight, stringwidth, stringheight);
g.fillRect(0, 0, this.size().width, this.size().height);
g.setColor(getForeground());
paint(g);
}

public void paint (Graphics g)
{
g.setFont (theFont);
g.drawString (count(), 10, 50);
}
}

thanks

Topic: Clear MS-DOS screen Previous Topic   Next Topic Topic: hi group !! Share your views on this........

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use