# Thread: Another simple circle problem

1. Member
Join Date
Aug 2011
Posts
12
Rep Power
0

## Another simple circle problem

How do I add multiple circle objects to the window?

Greencircle class

Java Code:
```package pack1;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;

public class Greencircle extends Frame{

Shape circle;

public Greencircle(int positionxIn, int positionyIn, int radiusIn){
px = positionxIn;
py = positionyIn;
}

public void paint(Graphics g){
Graphics2D ga = (Graphics2D)g;
ga.draw(circle);
ga.setPaint(Color.green);
ga.fill(circle);
}
}```
Blackcircle

Java Code:
```package pack1;
import java.awt.*;
import java.awt.geom.*;

public class Blackcircle extends Frame{

Shape dot;

public Blackcircle(int positionxIn, int positionyIn, int radiusIn){
px = positionxIn;
py = positionyIn;
}

public void paint(Graphics g){
Graphics2D ga = (Graphics2D)g;
ga.draw(dot);
ga.setPaint(Color.black);
ga.fill(dot);
}
}```
Runner with main

Java Code:
```package pack1;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowEvent;

public class Runner {

public static void main(String[] args){
Greencircle gc = new Greencircle(50,60,70);
Blackcircle rb1 = new Blackcircle(100, 200, 5);
System.out.println("hello");
Frame f1 = new Frame();
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
f1.setSize(300, 250);
f1.setVisible(true);
[COLOR="red"]// f1.add(gc); //this is the part I don't know[/COLOR]
System.out.println(gc);
System.out.println(rb1);
}
}```

2. Um, create multiple instances and store them in a List?

3. Or don't extend jframe, just make circle a class which knows how to draw itself. Create a few and then draw them all on a JPanel and add the panel to a jframe.

4. Member
Join Date
Aug 2011
Posts
12
Rep Power
0
I need different circle types, a total of 3 different classes.

5. My advice still holds. A circle is not a jframe, so it shouldn't inherit from it.

Create three classes that look like this:

Java Code:
```public class Circle{
public void drawCircle(Graphics g){
//draw the circle here
}
}```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•