If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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.

Re: short, simple applet question

your applet just does what you wanted, but before it is shown. If you want
to see the running of the number, you should do it after the applet is
shown. Many ways such as add button to trigger it, or use javascript to
trigger the applet, or ......

Re: short, simple applet question

TestLoop loop1 = new TestLoop();
Browser automatically creates copy of applet
class, in this case TestLoop. Your statement
creates a second instance of the class.

I tried some threading with sleeping which
seemed to allow repainting to proceed.
My version seemed to work OK on my system.
(Ignore the deprecation error for the stop method.
It might be replaced by the interrupt method???).

"Tom" <tomee@bigfoot.com> wrote:
>
>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>
>
>
>
>
>