Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!

Knute Snortum

+ Follow
since Apr 20, 2013
Knute likes ...
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
After 25 years of programming, Knute has retired to be a professional musician. Knute first learned BASIC and Cobol on a CPM Timeshare system circa 1985. He spent way too long coding in one flavor of Business Basic or another. Going back to college, he learned C and a whole new world opened up to him. Knute likes Perl and Java, for completely opposite reasons. Knute is a complex person.
Portland, Oregon
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt Green check

Recent posts by Knute Snortum

Hello all,

I am writing a proof-of-concept class to determine how to pause and resume a thread doing a cyclical process in Swing. The idea is to have an instance field called paused that the thread polls.  When the field is true, thread process will call Object.wait() to pause.  Then when the main proccess wants to resume, the paused field is set to false and an Object.notify() is called.

The thread process pauses just fine but when it comes to resuming, it never sees the notify() from the main process. Any help would be welcome.  Below is my code.

I wrote:I now have instructions to be able to pause the generation display, unpause, and restart, meaning to wipe the "universe" clean and start with a new random universe.

From my research it looks like I will have to run the evolve code in a Thread and communicate to that thread from the EDT.  I'm not good at Threads.  Maybe I should start a new topic since we're talking about something different than the subject of this topic?
3 weeks ago

Rob Camick wrote:Also in your painting code I question if you need:

since the drawing of the gridlines should paint the outline of each cell.

At least the painting looks the same to me when I remove the code.

That's weird, because when I remove that line, almost all the grid line disappear.  I am on Linux Ubuntu, if that makes a difference.
3 weeks ago

Rob Camick wrote:Even though you stop updating the panel after a fixed number of generations the Timer still fires events.

You can stop the Timer with code like:

Thank you, this works.  However, I now have instructions to be able to pause the generation display, unpause, and restart, meaning to wipe the "universe" clean and start with a new random universe.  Timer has a restart, but this is different than what I need.  There doesn't seem to be pause and unpause methods.  Is there an idiom in Swing for pausing the event loop?  Someone here said Thread.sleep() and Swing don't play well together, and that seems to be the case, as this code just freezes the UI:
3 weeks ago

Rob Camick wrote:

there are noticeable pauses between each time the screen repaints)

That is because you have the "time to generations" set to 300. Try something like 15 to increase the animation.

Decreasing the time between generations doesn't change the effect.  Say we're at 300 ms.  I will see two or three generations go by with 300 ms between them.  Then I will see a generation that takes 500 ms or so, then two or three at 50 ms and so on.  This effect seems to go away after about 100 generations, so it may have to do with caching.
3 weeks ago
Updated my code so that it both starts by the SwingUtilities.invokeLater() and uses the Swing Timer.  The display is "correct" (no distortion of the graphics) but still jerky (there are noticeable pauses between each time the screen repaints).  I have updated GitHub.
3 weeks ago
Okay, I just tried this:
... and the display was messed up.  The text part (JLabels) didn't display until the last generation was done, and the graphical part was shifted a few pixels ro the right.  I have no idea why this would be so.
3 weeks ago
I saw that bit of code on some examples and not on others so I "tried" it and it "didn't work."  I know that's vague but it was many iterations ago in the version of my code.  I'll try launching with the invokeLater()  now in conjunction with  timer code and see how that works.
3 weeks ago
Campbell: just saw you post.  My understanding is that double-buffering is enabled by default.  Is that correct?
3 weeks ago
Yes, that did it!  Thanks!

I still have the problem of the screen updating in a "jerky" manner.  Instead of using gameOfLifePanel.repaint() I used gameOfLifePanel.paintImmediately(0, 0, length, length).  This improved things, but not entirely.  
3 weeks ago
I was thinking of painting everything all over again for each generation, but would this cause a flicker?  I'll give it a try.
3 weeks ago
Hi all,

I am trying to create a Swing GUI for the Game of Life implementation I wrote.  This is a challenge from, so it comes with some restrictions, such as I have to have a class called "GameOfLife" that extends JFrame.  I hear that's not the best way to do things, but oh well.

So the problem.  In the Game of Life, you have an n x n grid with cells that die or come to life based on some simple rules.  My problem is how to display this correctly. I currently have a GameOfLifeGrid class that extends JPanel that prints lines in a nice grid.  Then I have another class, GameOfLifeCell, that extends JPanel and draws a filled square when the cell is "alive" and clears when it's dead. I have an array of arrays of GameOfLifeCells that correspond to a similar structure of booleans that inform me whether to make the filled square visible or not.

Problem is, it doesn't work.  First, the cells don't line up with the grid.  Second, I can only get one cell to become visible.  It's not always the same cell, though.  I have the whole application at, but here are some snippets:

[Edit: the above URL now points to the latest version.  To see the version at the point in time this post was written, see ]

3 weeks ago
You're right.  Sorry.
1 month ago
Could be, but it's a long shot.  I have a very basic built-in video card on the Linux box I tested the code on.
1 month ago