public class TestColoredCircle1{
public static void main(String[] args){
Color color = Color.BLUE;
JFrame window = new JFrame("Colored Circle 1");
window.setLocation(100,100);
window.setSize(300,400);
window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
ColoredCircle1 coloredCircle1 = new ColoredCircle1(100,100,50,color, window);
window.getContentPane().add(coloredCircle1);
color = Color.MAGENTA;
ColoredCircle1 coloredCircle2 = new ColoredCircle1(200,200,10,color, window);
window.getContentPane().add(coloredCircle2);
window.setVisible(true);
// window.setVisible(true);
//. In de main methode moet nu een JFrame-object worden gemaakt met location = (100,100)
//en size = (300,400). Creeer 2 ColoredCircle1-objecten.
//Het eerste object heeft coordinaten (x,y,r)= (100,100,50),
//het tweede object heeft coordinaten (x,y,r) = (200,200,100). Laat beide objecten tekenen. Kies de kleuren zelf.
}
}
import java.math.*;
import javax.swing.*;
import java.awt.*;
import java.awt.Graphics.*;
public class ColoredCircle1 extends JPanel{
double xPosition;
double yPosition;
double radius;
double pi = Math.PI;
Color color;
JFrame window;
ColoredCircle1(double x, double y , double r, Color c, JFrame w){
//post: a Circle-object has been created
//with xPosition = x, yPosition = y en radius = r
setXPosition(x);
setYPosition(y);
setRadius(r);
setColor(c);
setWindow(w);
//JFrame frame = new JFrame("Colored Circle");
//window.getContentPane().add(coloredCircle.TestColoredCircle);
//window.getContentPane().add(ColoredCircle);
//frame.setSize(400, 300);
//frame.setVisible(true);
//A JFrame object with location = (100,100) and size = (400,300) has been constructed
}
double getXPosition(){//post: returns xPosition
return xPosition;
}
void setXPosition(double x){//post: has set XPosition to x
xPosition = x;
}
double getYPosition(){//post: returns yPosition
return yPosition;
}
void setYPosition(double y){
//post: has set YPosition to y
yPosition = y;
}
double getRadius(){//post: returns radius
return radius;
}
void setRadius(double r){//post: has set radius to r
radius = r;
}
void setColor(Color c){
color = c;
}
Color getColor(){
return color;
}
JFrame getWindow(){
return window;
}
void setWindow(JFrame w){
window = w;
}
public void paint(Graphics g){
super.paint(g);
//post: the Circle-object has been painted inside a rectangle
//with location=(x-r/2,y-r/2) and size= (width, height)
int x = (int) getXPosition();
int y = (int) getYPosition();
int r = (int) getRadius();
color = getColor();
window = getWindow();
//x-r/2,y-r/2,r,r
g.setColor(color);
g.fillOval(x-r/2,y-r/2,2*r,2*r);
window.getContentPane().setBackground(color);
;
}
}