473,586 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble using Thread.sleep(). .....

Hello,

Basically this is my problem. I am programming minesweeper in java. I have
a panel in the background on which I draw all the mines/numbers etc. and
then I have an array of buttons that sit on top of them.

I am developing a solver and need a pause between each move the algorithm
makes. I know from my past experience that you have to use something along
the lines of :-

Graphics g = board.getGraphi cs();
board.paintComp onent(g);
g.dispose();

to get the board to update after each successive move but I seem to be
having problems getting it working properly.

- If I use the above to repaint the background then all the buttons
disappear.
- If I use the above to repaint all the buttons it doesnt actually repaint
them, it just goes grey.
-If I try and repaint both, wherever moves are made by the computer you can
see the relevant square in the background but none of the other buttons are
drawn and its just grey instead.

After completeing the algorithm it all redraws as normal.

I just want everything to refresh as normal when each move by the computer
is made, can anyone help me out?

Thx in advance
Jul 17 '05 #1
3 3768
Joe
In article <3f************ ***********@lov ejoy.zen.co.uk> ,
ze******@zen.co .uk says...
Graphics g = board.getGraphi cs();
board.paintComp onent(g);
g.dispose();


What type is the board object? I think you'll need to have each button
repaint itself individually. I think the easiest way to do this would be
to extend the JPanel class and have it display either a grey face or the
mines/numbers/greyspace behind the face.



--

Fuck George W. Bush!!!
Jul 17 '05 #2
Board is an instance of a object that extends a JPanel and I draw the
solution on the panel and then paint the buttons on top of the panel.

The problem is that when the thread starts sleeping paintComponent is never
executed in any of the components and at the moment when I try to draw every
button onto the panel it just doesnt.
"Joe" <sf***@spamcop. net> wrote in message
news:MP******** *************** *@sfo.news.spea keasy.net...
In article <3f************ ***********@lov ejoy.zen.co.uk> ,
ze******@zen.co .uk says...
Graphics g = board.getGraphi cs();
board.paintComp onent(g);
g.dispose();


What type is the board object? I think you'll need to have each button
repaint itself individually. I think the easiest way to do this would be
to extend the JPanel class and have it display either a grey face or the
mines/numbers/greyspace behind the face.



--

Fuck George W. Bush!!!

Jul 17 '05 #3
Lee Garrington wrote:
Board is an instance of a object that extends a JPanel and I draw the
solution on the panel and then paint the buttons on top of the panel.

The problem is that when the thread starts sleeping paintComponent is never
executed in any of the components and at the moment when I try to draw every
button onto the panel it just doesnt.
"Joe" <sf***@spamcop. net> wrote in message
news:MP******** *************** *@sfo.news.spea keasy.net...
In article <3f************ ***********@lov ejoy.zen.co.uk> ,
ze******@zen. co.uk says...

Graphics g = board.getGraphi cs();
board.paintComp onent(g);
g.dispose();


What type is the board object? I think you'll need to have each button
repaint itself individually. I think the easiest way to do this would be
to extend the JPanel class and have it display either a grey face or the
mines/numbers/greyspace behind the face.



--

Fuck George W. Bush!!!


Is letting Swing repaint it not an option for some reason? Why not call
JPanel.repaint( ) to request this, and then wait for Swing's own code to
handle everythign smoothly.

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
2867
by: Anthony Baxter | last post by:
On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.3.1 (final). Python 2.3.1 is a pure bug fix release of Python 2.3, released in late July. A number of obscure crash-causing bugs have been fixed, various memory leaks have been squished, but no new features have been added to the...
0
2282
by: Santa | last post by:
I am using Fritz Onion's "Asynchronous Pages" approach as mentioned in the article http://msdn.microsoft.com/msdnmag/issues/03/06/Threading/default.aspx to increase the performance of my ASPX page.I am using the Custom thread pool as given in the article's sample. Implementation: =============== In AsyncPage.aspx I inhereted AsyncPage...
1
1217
by: Fernando Rodríguez | last post by:
Hi, I don't the difference between the wait|sleep|join states and the suspended one. Could someone please explain this? O:-) Any pointers to multithreading tutorials would be appreciated to. Thanks :-)
3
2936
by: Stephen Miller | last post by:
I have an ASP.Net application that sends a NetworkStream to a .Net Service, which has a TcpListener listening on a port for the ASP.Net client. When it receives a request it creates a new thread with the AddressOf a class that runs a long data intensive process that can take between 1-15 minutes and results in the creation of a uniquely named...
17
6404
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. Note, the Windows task manager shows 2 CPUs on the Performance tab with hyper-threading is turned on. Both Python 2.3.5 and 2.4.3 (downloaded from...
7
3307
by: MLH | last post by:
This was contributed by someone in this NG last year... Sub WaitFor(psngSeconds As Single) ' wait for specified number of seconds ' Copyright Trevor Best (tre...@besty.org.uk) <-OK, so I added thisline. Dim sngStart As Single Dim sngET As Single
0
2676
by: Buckaroo Banzai | last post by:
Hello, newbie here... I'm writing this program but when I click the start button which should initiate either the Hare or the Tortoise, it does not, this is the first time I use threads, so the problem might be the way I'm passing the value. can someone please take a look at this code and maybe give me some guidance on what I'm doing wrong....
1
2729
by: danfolkes | last post by:
Hey Everyone, I am trying to send repeated messages from a "Node" to a "Server". It works the first time I send the from the Node to Server, but after that it either errors, or does not do anything. I would love some help, here is the code: import socket import thread import time
0
1393
by: Tim Golden | last post by:
Lowell Alleman wrote: Well you've certainly picked a ticklish area to run into problems with ;). First, forget about the threading aspects for the moment. AFAICT the smallest program which reproduces your problem is: <code> import signal
0
1505
by: HxRLxY | last post by:
I am currently working on a GUI. The idea is that when the user clicks a given button, that portion of the interface will slide into view from the main JFrame. The code I have written and included constitutes an initial test at the basic mechanics of animation. Everything works alright with my code, but the animation seems choppy. Any tips or...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.