[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

simple points cant find error

Posted on 2006-05-04
13
Medium Priority
?
181 Views
Last Modified: 2010-03-31
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();
    }
}
0
Comment
Question by:ellandrd
  • 5
  • 4
  • 4
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16605310
You need to override paint with a JFrame
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16605325
Why the array?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16605338
no reason - am planning to contain alot more object in it...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:CEHJ
ID: 16605354
OK ;-)
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16605392
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 600 total points
ID: 16605452
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16605703
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 16605727
What is your latest code? What is the output?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1400 total points
ID: 16605731
I mean you should override paint, not paintComponent
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16605740
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
 
LVL 16

Author Comment

by:ellandrd
ID: 16605741
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
 
LVL 16

Author Comment

by:ellandrd
ID: 16605789
thanks!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16605856
:-)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question