|
-
Apr 25th, 2002, 09:42 PM
#1
Drawing characters in different font sizes and colors
Hi
I need help wiht the following problem. Draw randomly generated characters in different font sizes and colors.
Thank you
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Draw extends JFrame
{
public Draw()
{
super( "Drawing Characters" );
setSize( 300, 200 );
setVisible( true );
}
public void paint( Graphics g )
{
super.paint( g );
int xP, yP, zP, s ;
String charArray[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
for( int count = 1; count > 0; count++ )
{
xP = ( int ) ( Math.random() * 256 );
yP = ( int ) ( Math.random() * 256 );
zP = ( int ) ( Math.random() * 256 );
s = ( int ) ( Math.random() * 36 );
g.setColor( new Color( xP, yP, zP ) );
g.setFont( new Font( "Serif", Font.BOLD, s ) );
g.drawString( charArray[ s ], xP, yP );
}
}
public static void main( String args[] )
{
Draw application = new Draw();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|