Вы ищете это?
Вы можете объявить классы MyCircle
и DrawingPane
в отдельных файлах .Java.
Я уверен, что это даст ответ на "Я хочу иметь возможность развернуть цвет в качестве параметра и вызвать метод из другого метода в другом классе."
public class TestingX12 {
public static void main(String args[]) {
new TestingX12();
}
public TestingX12() {
//create list of circles
List<MyCircle> circList = new ArrayList<MyCircle>();
circList.add(new MyCircle(new Rectangle(100, 20, 120, 30), Color.red));
circList.add(new MyCircle(new Rectangle(150, 50, 80, 50), Color.yellow));
circList.add(new MyCircle(new Rectangle(30, 90, 30, 110), Color.blue));
DrawingPane dp = new DrawingPane(circList);
JFrame frame = new JFrame("JToolTip Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(dp);
frame.setSize(400, 450);
frame.setVisible(true);
}
class MyCircle {
Rectangle rectangle;
Color color;
public MyCircle(Rectangle r, Color c) {
this.rectangle = r;
this.color = c;
}
}
public class DrawingPane extends JPanel {
List<MyCircle> circles;
public DrawingPane(List<MyCircle> circles) {
this.circles = circles;
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Rectangle rect;
for (int i = 0; i < circles.size(); i++) {
rect = circles.get(i).rectangle;
g.setColor(circles.get(i).color);
g.fillOval(rect.x, rect.y, rect.width, rect.height);
System.out.println("Drawing...");
}
}
}
}