The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

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.

You had me stumped for a while there...which was my fault, I misread your code.

Here's the thing, you're instantiating a Progress in your main and calling start(), which calls run() (behind the scenes), fine so far, which subsequently instantiates another Progress, (not so fine) which it, thankfully, doesn't try to start. (starting a Progress in Progress.run() would currently cause a never ending loop of creating and starting Progresses).

So, lose the pb in Progress.run(), you don't need it.

Given that, and the fact that Timer is not a thread, you also don't need to call join from within Progress.

moving on

You have
if (bar.getValue() == bar.getMaximum())
but also
bar.setValue(bar.getValue() + 37);

No multiple of 37 is == 2000, so your condition will never be met, use >= instead.

Thankyou for your help. I hope none of the below make me sound ungrateful or anything like that as i appreciate the help and also know very little. However....

Originally Posted by rushiku

Here's the thing, you're instantiating a Progress in your main and calling start(), which calls run() (behind the scenes), fine so far, which subsequently instantiates another Progress, (not so fine) which it, thankfully, doesn't try to start. (starting a Progress in Progress.run() would currently cause a never ending loop of creating and starting Progresses).

I don't have a start() in my new code(latest post)

Originally Posted by rushiku

So, lose the pb in Progress.run(), you don't need it.

that made it worse. i tried it several ways and it doesn't work

Originally Posted by rushiku

You have
if (bar.getValue() == bar.getMaximum())
but also
bar.setValue(bar.getValue() + 37);

THis code works. The object does "dispose" itself after it has has finished executing.

It is a bad practice to rely on things like this. When setting up a condition where you want to know if something that is being incremented has reached a certain level, always use >=, this way, you don't overshoot and keep going (forever).

"I don't have a start() in my new code(latest post)"
"(not so fine) which it, thankfully, doesn't try to start."

"My code works 99&#37;. All the actions happen as they should"
Many Rube Goldberg contraptions also work.

Okay, we weren't getting anywhere with me trying to help by treating symptoms, so I wrote a program to replicate your program, based on your description of it.

We would have never gotten were you wanted to go if we had continued in the direction I was going...

What I've found out is that, yes, there are threads being spawned, but no, there's no way for you to get to them such that you can join them. So that throws out the whole 'join thread' idea.

What finally worked for me was to use a 'callback'. Technically, there are no 'real' callbacks in Java, so what I did, I feel, was in the spirit of callbacks without really being one. (a callback is when you pass a pointer to a function (C/C++ term for methods) to another object, which then calls the function at an appropriate time, there are no method pointers in Java, hence, no callbacks)

On to the details

In actionPerformed for my button listener, I copy the text from field a, clear the field, and start the progress class. This is important: when I create the progress class, I pass a this reference into the constructor, this gives the progress class access to the button listener (now the progress' 'parent').

The progress class needs this access so that when the bar hits the maximum, it can call the method I added to the button listener, which will place the copied text into field b.

As the method is not called until the progress bar has completed, the text will not appear until after the progress bar goes away.

If you don't follow me or would prefer to see the code, let me know and I'll post it.