|
-
short, simple applet question
Hi,
I am very new to java and am just trying to get to grips with the basics of
applets.
I currently have two problems. I have wrote a short applet that shows these
(along with the HTML code to display it). This is not the code I am working
on, but it shows the issues I am having with the other code. It compiles
fine.
By looking at the code you should be able to make out my first problem quite
easily. Here, I want to display the 'counter' variable on the screen.
However, this varaible is displayed only after the program has finished
(instead of displaying numbers from 1 to 45000 on the screen, it just goes
through the program and displays 45000 only).
My second problem is that I do not want the counter variable to ever
increase beyond 45000 (to 90000, to 135000, to 180000, etc) every time the
HTML screen is refreshed.
Thanks in advance for any suggestions you can offer:
Tom (tomee@bigfoot.com):
import java.awt.*;
public class TestLoop extends java.applet.Applet {
static int counter = 0;
public void start()
{
TestLoop loop1 = new TestLoop();
loop1.runTheLoop();
} //end of start
public void runTheLoop()
{
int index = 1;
while (index <= 45000)
{
index++;
counter++;
repaint();
}}
public void paint(Graphics screen) {
screen.drawString("The number is ... " + counter, 5, 30);
}
} // end of class
//*********** TestLoop.html ***********-
<HTML>
<HEAD>
<TITLE>Person</TITLE>
</HEAD>
<BODY>
<APPLET
CODE=TestLoop.class
WIDTH=500
HEIGHT=500>
</APPLET>
</BODY>
</HTML>
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