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 4 of 4

Thread: I don't know what's wrong

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    20
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default I don't know what's wrong

    I'm trying to display an oval but the oval doesn't show.
    This is my code:

    package guitut;
    import javax.swing.*;
    import java.awt.*;
     
    public class GUItut {
    static int x = 50;
    static int y = 50;
      private static class BallAnimate extends JPanel {
          public void paintComponent(Graphics g)
          { super.paintComponent(g);
          g.drawOval(x, y, 50, 100);
     
      }
    }
        public static void main(String[] args) {
          BallAnimate displayPanel = new BallAnimate();
           JPanel content = new JPanel();
           content.add(displayPanel);
     
          JFrame window = new JFrame();
       window.setContentPane(content);
          window.setSize(400,400);
          window.setVisible(true);
        }
    }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: I don't know what's wrong

    What happens when you resize the GUI?
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    17
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: I don't know what's wrong

    First of all...you must add your content do "window". second, if you put into panel another panel you need to set LayoutManager

  4. The Following User Says Thank You to remigio For This Useful Post:

    Shivam24 (July 25th, 2011)

  5. #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: I don't know what's wrong

    For debugging these kinds of problems I set the colors of the different components to see where and if they are showing up.
    Try adding this after you create the object:

    displayPanel.setBackground(Color.yellow);

Similar Threads

  1. WHAT IS WRONG HERE PLEASE?
    By mjava in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 27th, 2010, 08:29 PM
  2. Not sure what is wrong with this
    By jwb4291 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: June 29th, 2010, 02:23 PM
  3. Something is wrong? Please help.
    By DestinyChick1225 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 29th, 2010, 07:47 AM
  4. What's wrong?!
    By deeerek in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 22nd, 2010, 07:11 PM
  5. don't know what's wrong
    By james in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 15th, 2010, 07:37 PM