【发布时间】:2015-04-09 17:21:34
【问题描述】:
作为程序的一部分,我需要在颜色数组中存储随机颜色。基本上,我创建了一个应该返回一个新的随机颜色的方法,我已经测试过了,它可以工作。我遇到的问题是如何在另一个类和方法中调用它。我尝试了很多东西,但没有一个有效。我在下面粘贴相关代码,顶部是颜色数组的实例化。
static Color[] colors = new Color [10000];
public static Color randomColor() {
return new Color(generator.nextInt(256), generator.nextInt(256), generator.nextInt(256));
}
private class DotsListener implements MouseListener, MouseMotionListener, ActionListener
{
public void mousePressed(MouseEvent event)
{
if(SwingUtilities.isLeftMouseButton(event))
{
pointList.add(event.getPoint());
sizes[pointList.size()] = SIZE;
colors[pointList.size()]= new Color(event.randomColor());
【问题讨论】:
-
将其作为参数传递?不确定您的问题到底是什么。
标签: java arrays oop colors casting