Welcome to the Java Programming Forums


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.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: JFrame, JPanel and Drawing Rectangles Help

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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?

    Thank You!


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: JFrame, JPanel and Drawing Rectangles Help

    Quote Originally Posted by TheSheepey9 View Post
    I think that the problem involves a paint and repaint method on the JFrame.
    Are you using the paintComponent method to do your drawing?
    Quote Originally Posted by TheSheepey9 View Post
    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.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: JFrame, JPanel and Drawing Rectangles Help

    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    TheSheepey9 (April 23rd, 2013)

  6. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JFrame, JPanel and Drawing Rectangles Help

    Thank You!

Similar Threads

  1. Replies: 5
    Last Post: February 15th, 2013, 05:01 PM
  2. JPanel drawing question
    By peter9207 in forum AWT / Java Swing
    Replies: 3
    Last Post: August 26th, 2011, 01:35 PM
  3. Drawing Rectangles and Lines
    By andreizeus in forum AWT / Java Swing
    Replies: 21
    Last Post: October 28th, 2010, 12:59 PM
  4. drawing a BufferedImage onto a JPanel
    By nemo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 13th, 2010, 07:48 PM
  5. problem with drawing images on JPanel
    By Asido in forum What's Wrong With My Code?
    Replies: 13
    Last Post: July 19th, 2010, 03:07 PM