473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.getGraphics();
board.paintComponent(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 3758
Joe
In article <3f***********************@lovejoy.zen.co.uk>,
ze******@zen.co.uk says...
Graphics g = board.getGraphics();
board.paintComponent(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.speakeasy .net...
In article <3f***********************@lovejoy.zen.co.uk>,
ze******@zen.co.uk says...
Graphics g = board.getGraphics();
board.paintComponent(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.speakeasy .net...
In article <3f***********************@lovejoy.zen.co.uk>,
ze******@zen.co.uk says...

Graphics g = board.getGraphics();
board.paintComponent(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
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...
0
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...
1
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. ...
3
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...
17
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. ...
7
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...
0
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...
1
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...
0
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...
0
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.