Ho letto bene il codice e ci sono due cose che non vanno bene:
in generale, per disegnare sul componente, devi utilizzare l'istanza di Graphics g che riceve paintComponent, qualsiasi cosa tu voglia disegnare.
Quindi, DrawCircle non è corretto ed il campo di istanza g2 non serve.
Per fare le cose correttamente potresti fare una cosa del genere:
codice:
/**
* @(#)Tester.java
*
*
* @author Vincenzo
* @version 1.00 2011/2/13
*/
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.util.*;
public class Tester extends JPanel{
private LinkedList<Shape> shapes;
/**
* Creates a new instance of <code>Tester</code>.
*/
public Tester() {
this.shapes = new LinkedList<Shape>();
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
for(Shape s : this.shapes){
((Graphics2D)g).draw( s );
}
}
public void disegnaQuadrato(Point p, int lato){
this.shapes.add( new Rectangle2D.Double(p.x,p.y,lato,lato) );
}
public static void startGUI(){
JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(500, 500));
Tester t = new Tester();
t.disegnaQuadrato(new Point(200, 200), 200);
t.disegnaQuadrato(new Point(150, 150), 100);
frame.add( t );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
SwingUtilities.invokeLater(
new Runnable(){
public void run(){
Tester.startGUI();
}
}
);
}
}