Link to home
Start Free TrialLog in
Avatar of ellandrd
ellandrdFlag for Ireland

asked on

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();
    }
}
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

You need to override paint with a JFrame
Why the array?
Avatar of ellandrd

ASKER

no reason - am planning to contain alot more object in it...
OK ;-)
SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
What is your latest code? What is the output?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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();
    }
}
thanks!
:-)