public class TestPane extends JPanel { private List<Shape> shapes; public TestPane() { shapes = new ArrayList<>(25); shapes.add(new Rectangle(10, 10, 20, 20, Color.RED)); shapes.add(new Oval(15, 15, 40, 20, Color.RED)); } @Override public Dimension getPreferredSize() { return new Dimension(200, 200); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); for (Shape shape : shapes) { Graphics2D g2d = (Graphics2D) g.create(); shape.paint(g2d); g2d.dispose(); } } }
s.paint(graphics); if (s instanceof Plot) { Plot p = (Plot) s;