Threading and Application.doEvents()...

O

OziRus

I'm currently coding a find-match game (a kind of memory game). I've
coded in C# but not
yet with Java. I'm working on it but I've a problem as follows;

In the beginning, all pictures are closed. When one of my pictures is
clicked, it will be
opened. Then when second is clicked it will be compared with first. If
first and second is
same, they will be remained opened but when they aren't same, the
second and first will be
shown 1 second then both of them will be closed. I've coded it but I
have some problems
about threading. When I click second (an image that is diffent from
first clicked) they both
are suddenly closed. Second can't be seen. But I want the diffent two-
images remains in
screen for 1 seconds. For this, I wrote a Thread.Sleep(1000); but it
doesn't work. It waits
while second-clicked is still closed. Second can't be seen. I wrote a
Application.doEvents() before Sleep(1000) then Sleep(1000) in c# and
it worked but I don't know how to do Application.doEvents() in Java.
(If I don't write Application.doEvents() in my C# code, It works like
my java program as you might understand...)

Thanks.
 
L

Lew

OziRus said:
I wrote a
Application.doEvents() before Sleep(1000) then Sleep(1000) in c# and
it worked but I don't know how to do Application.doEvents() in Java.
(If I don't write Application.doEvents() in my C# code, It works like
my java program as you might understand...)

What does Application.doEvents() do?

-- Lew
 
D

Dag Sunde

Lew said:
What does Application.doEvents() do?

-- Lew

If it is anything like VB, it let the application's internal "messagepump"
thru
for a while. Letting queued-up events run before continuing.
 
L

Lew

Dag said:
If it is anything like VB, it let the application's internal "messagepump"
thru
for a while. Letting queued-up events run before continuing.

I am not aware of anything like that in Java.

OTOH, the original problem can probably be solved with a little rethink around
the 'synchronized' keyword.

Could be the solution wouldn't even need a Thread.sleep().

-- Lew
 
D

Daniel Pitts

I'm currently coding a find-match game (a kind of memory game). I've
coded in C# but not
yet with Java. I'm working on it but I've a problem as follows;

In the beginning, all pictures are closed. When one of my pictures is
clicked, it will be
opened. Then when second is clicked it will be compared with first. If
first and second is
same, they will be remained opened but when they aren't same, the
second and first will be
shown 1 second then both of them will be closed. I've coded it but I
have some problems
about threading. When I click second (an image that is diffent from
first clicked) they both
are suddenly closed. Second can't be seen. But I want the diffent two-
images remains in
screen for 1 seconds. For this, I wrote a Thread.Sleep(1000); but it
doesn't work. It waits
while second-clicked is still closed. Second can't be seen. I wrote a
Application.doEvents() before Sleep(1000) then Sleep(1000) in c# and
it worked but I don't know how to do Application.doEvents() in Java.
(If I don't write Application.doEvents() in my C# code, It works like
my java program as you might understand...)

Thanks.

Instead...
You're "clicked" event will be fired. That triggers the showing of the
image.. You set a Timer for 1000 ms, and the Timer fires an event
which hides the image.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top