ellandrd
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.setDefaultCloseOperat ion(JFrame .EXIT_ON_C LOSE);
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();
}
}
public class Main extends JFrame {
/** Creates a new instance of Main */
public Main() {
this.setDefaultCloseOperat
this.getContentPane().add(
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();
}
}
You need to override paint with a JFrame
Why the array?
ASKER
no reason - am planning to contain alot more object in it...
OK ;-)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
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();
}
}
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();
}
}
ASKER
thanks!
:-)