|
-
Applet question: Changing integers to special string
code:
import javax.swing.*;
import java.awt.Graphics;
public class L5a1 extends JApplet{
int num1,
count;
public void init()
{
String one;
one = JOptionPane.showInputDialog ( "Enter first number, 1-30 please:" );
//converts string to integer
num1 = Integer.parseInt(one);
}
public void paint ( Graphics g )
{
String output = "";
if (num1 > 30 || num1 < 0 )
{
g.drawString("The number does not meet specs!", 10, 10);
}
for (int count = 0; count < num1; count++)
{
g.drawString("*", count, 10);
output += "*";
}
}
}
I need to write an applet that reads five numbers (each between 1 and 30). For each number read, I need todraw a line containing that number of adjacent asterisks. If it reads the number seven, it should print *******.
this is what i have now, but im not sure why the spacing of the astericks are so small, they are bunching up...
please help thanks
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks