simple points cant find error

what is wrong with this?

public class Main extends JFrame {
    /** Creates a new instance of Main */
    public Main() {
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.getContentPane().add(new JPanel());
        this.setSize(new Dimension(550,500));
        this.setVisible(true);
    }
   
    public void paintComponent(Graphics g) {
        super.paintComponent( g ) ;
        Graphics2D g2d = ( Graphics2D ) g ;
        Shape shape[] = new Shape[1] ;
        shape[ 0 ] = new Rectangle(100, 100, 200, 300);
        g2d.draw( shape[ 0 ] ) ;
    }
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Main();
    }
}
LVL 16
ellandrdAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
I mean you should override paint, not paintComponent
0
 
CEHJCommented:
You need to override paint with a JFrame
0
 
CEHJCommented:
Why the array?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
ellandrdAuthor Commented:
no reason - am planning to contain alot more object in it...
0
 
CEHJCommented:
OK ;-)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
0
 
Mayank SConnect With a Mentor Associate Director - Product EngineeringCommented:
0
 
ellandrdAuthor Commented:
sorry guys i had to head off for a few mins that time..

right ive tried overriding the jframe, but my shapes dont appear?

i also looked at the two links and try adopting example code to fit mine, but still my shapes dont appear...

am i missing anything above?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
What is your latest code? What is the output?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
If I compile and run http://www.javaalmanac.com/egs/java.awt/BasicDraw.html on Java 5/ Windows server 2003, I see a JFrame opening up with a circle drawn on it.
0
 
ellandrdAuthor Commented:
all i get is my Jframe...

sorry i have just changed it around;

public class Main extends JFrame{
    /** Creates a new instance of Main */
    public Main() {
        super();
        setVisible(true);
        pack();
    }
   
    public void paintComponent(Graphics g) {
        super.paintComponent( g ) ;
        Graphics2D g2d = ( Graphics2D ) g ;
        GeneralPath gp = new GeneralPath();
        gp.moveTo(50f, 50f);
        gp.moveTo(100f, 50f);
        gp.moveTo(50f, 100f);
        gp.moveTo(0f, 50f);
        gp.closePath();
        g2d.draw(gp);
    }
   
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Main();
    }
}
0
 
ellandrdAuthor Commented:
thanks!
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.