-
Graphics? [resolved]
Anybody know how i can do this?
Im just trying to simply make a
circle on a canvas. I can get it to work
as an applet but that's about it.
Thanks :)
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Shape {
public static void main(String[] args){
new Circle();
}
Canvas c;
JFrame jf;
}
class Circle extends Shape{
public Circle() {
c = new Canvas();
jf = new JFrame("Circle!");
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
Dimension size = jf.getSize();
Insets i = jf.getInsets();
int height = size.height - i.top - i.bottom;
int width = size.width - i.left - i.right;
c.setSize(height,width);
jf.getContentPane().add(c);
jf.setSize(400,300);
jf.setVisible(true);
}
public void paint(Graphics g){
g.setColor(Color.red);
g.drawOval(50,50,50,50);
}
}
-
Weeeeeeee. My first red circle! Im so happy. :p
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Shape{
public static void main(String[] args){
new Circle();
}
}
class Circle extends Canvas{
public Circle(){
JFrame jf = new JFrame("Circle!");
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
Dimension size = jf.getSize();
Insets i = jf.getInsets();
int height = size.height - i.top - i.bottom;
int width = size.width - i.left - i.right;
this.setSize(height,width);
jf.getContentPane().add(this);
jf.setSize(400,300);
jf.setVisible(true);
}
public void paint(Graphics g){
g.setColor(Color.red);
g.fillOval(50,50,50,50);
}
}