The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

JFrame, JPanel and Drawing Rectangles Help

Hello, First off, I am trying to create a very simple start screen layout(one that has a title at the top with buttons(rectangles) that change colors if the mouse is over top and have strings drawn on top of them) but I ran into a problem with the rectangles.
The problem was that the rectangles and Strings were flickering and after many google attempts, I think that the problem involves a paint and repaint method on the JFrame.
My question is what component could hold a game menu without flickering and how would I connect that to the main JFrame?

Re: JFrame, JPanel and Drawing Rectangles Help

I think that the problem involves a paint and repaint method on the JFrame.

Are you using the paintComponent method to do your drawing?

Originally Posted by TheSheepey9

My question is what component could hold a game menu without flickering and how would I connect that to the main JFrame?

Any container that can display an image should do so without flicker. Are you calling repaint()?
Post your drawing code if you don't mind. It will be much easier to help fix the flicker if we can see the cause of it.

Re: JFrame, JPanel and Drawing Rectangles Help

I tried the paint(); and paintComponent(); and it still flickered.
I don't think i was using a container as i was using one Class called Main and painting the images(in this case, rectangles) directly on the JFrame.
Unfortunately, I am not able to display the code as i got frustrated and kind of deleted the project....... bu I think I know whyat I did wrong(I think i need a new class that extends a JPanel and print the graphics to that and have the JPanel appear on top the JFrame).
Thanks Again.