Hello, everybody. :] This is my first post here, and I'm just happy it's not about something entirely mundane, like array iterating or something.

Basically, I have a JPanel that I'm having a bunch of emulated pixels (drawLines) drawn on randomly on a panel that's 250 x 250. I'm learning Java right now, but I'm tinkering with this because I want to program games, so I figure this would be a decent first step. I still don't fully understand everything that's going on here, but let me post the code I have for the program.

I'd like to know what I can do to make the JPanel actively updating itself... once it gets drawn once, it stays in its drawn position, even though the program is constantly looping and drawing "lines". Like I said, I'm not exactly sure of what's going on, this has just been my tinkering... but if anyone could let me know what I can do or point me in the right direction, it would be much appreciated. Thank you!

Thanks for the response, Darryl. I'll read over that concurrency information and try to make as much sense of it as I can... it may be I need to master more of the Java language before I dabble in all of this so that I can understand it more clearly. I'll try and make something workable with what I know in the meantime, though.

Darryl Burke wrote:
Oh and

I'm just happy it's not about something entirely mundane, like array iterating or something.

Not much above that either.

db

Haha, you mean it's about as mundane? I guess someone beyond my highly limited ;] expertise would probably think so... it sure gets crazy. Anyways, thank you very much again.

Mundane in the sense that at least once a week some bloke comes along with a "weird bug in Java" that ends up being caused by blocking the Event Dispatch Thread of Swing. The main reason is because people jump into code without understanding what they are doing...

You at least are two steps ahead:

- you did not call this a weird bug
- you admitted to jumping into coding without understanding it first ; )

Swing is not for the faint of heart (for one it is a multithreaded environment, quite advanced stuff), I would start your gaming enterprises by creating for example a command line hangman game. It isn't as easy as you would think and it will help you to understand basic application flow. Keep it simple though, just print out how many turns the player has left.

When you've done that you might consider translating it to a Swing version where you actually draw a man being hanged. Morbid fun!

Actually, I've done a bit of simple game programming before with C++ and a graphics library called SFML.... I was able to create Pong, a simple helicopter flying game, and a simple space-type shooter. Even those very simple games ended up being highly complex, at least compared to what I expected before making them. As far as command-line games go, I've made Hangman and Tic-Tac-Toe so far with straight-up C++, as well. It's a very fun and rewarding process to program even the simplest of games, but when you get into graphics and GUI programming, there's so much to absorb, which I think is both good and bad.

Your recommendation on the Swing version of Hangman, though, sounds like it would be fun. I'll probably end up giving that a shot when I learn more about Swing. Tinkering can unfortunately get me only so far. Tell me something, though... I've heard that for game programming, using the AWT is more efficient than using Swing. Is this true? Thank you very much for your reply.

5. Check out javax.swing.Timer you are going to want to use one of these to draw your lines on your Image (see Image.getGraphics())

6. Create an AbstractAction (I think the swing Timer requires an Action / ActionListener - there are two timers in Java and I get confused sry) In the actionPerformed(ActionEvent ev) method add your line drawing without the loop.