forgive me if there is already a thread on here dealing with this but I can't seem to find one that deals with my specific task.
I'm new to Java having only ever coded in BASIC and Z80 Assembly at various points in my life. I'm slowly getting the hang of it but I'm struggling with a task I'm doing as part of a course I'm studying.
I need to create some basic Graphics, a circle, a square and so on, then I need to store them as objects in a linked list. I have managed to easily draw the objects and store them in a linked list but I can't figure out how to create a method that will then take whats stored in the list and paint them inside a JFrame.
Here is my code: public class Shape extends JFrame {
public void paint(Graphics g){
LinkedList<Object> ll = new LinkedList<Object>();
setSize(800,600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Circle c = new Circle();
c.setHeight(100);
c.setWidth(100);
c.setXpos(100);
c.setYpos(250);
ll.add(c);
Square s = new Square();
s.setHeight(100);
s.setWidth(100);
s.setXpos(300);
s.setYpos(250);
ll.add(s);
Bar b = new Bar();
b.setHeight(100);
b.setWidth(200);
b.setXpos(500);
b.setYpos(250);
ll.add(b);
}
and an example of the code in the Circle Class (which is pretty much the same for the square etc..)
public class Circle {
private int xpos;
private int ypos;
private int width;
private int height;
public void paint(Graphics g) {
g.setColor(Color.RED);
g.fillOval(xpos, ypos, width, height);
}
public void setXpos(int xpos) {
this.xpos = xpos;
}
public void setYpos(int ypos) {
this.ypos = ypos;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
Basically I have a total mental block on how to get what's contained in the LinkedList to the JFrame.
Any help is greatly appreciated!