我正在使用自定义颜色来制作一个小应用程序来显示随机制作的颜色,颜色将是椭圆形和它下面的 RGB 组件编号。外部 JFrame 将有 3 个选项卡,用于按 RGB 的饱和度从最低到最高对颜色进行排序,例如:粉红色比红色亮,因此它会在列表中首先分类为红色。但是我似乎在驱动程序之间发送排序后的颜色数据以对数据进行排序和驱动程序以绘制椭圆时遇到问题。我收到错误消息“找不到符号”。如果有人指出我做错了什么,那将是一个很大的帮助。
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class Graphic extends JFrame
{
public static void main(String[] args)
{
ArrayList<Colorsorter> derp = new ArrayList<Colorsorter>();
Colorsorter oneColor = new Colorsorter(0,0,0);
int R;
int G;
int B;
Random colorgen = new Random();
for(int n = 0; n < 50; n++)
{
R = colorgen.nextInt(256);
G = colorgen.nextInt(256);
B = colorgen.nextInt(256);
oneColor = new Colorsorter(R,G,B);
derp.add(oneColor);
}
}
public Graphic()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500,1000);
setVisible(true);
}
public void paint(Graphics page)
{
for(int h = 0; h < 10; h++)
{
for(int l = 0; l < 5; l++)
{
page.setColor(new Color(255,215,0));
page.drawOval(50+(l*100), 40+(h*100), 100, 40);
page.fillOval(50+(l*100), 40+(h*100), 100, 40);
page.setColor(new Color(0, 0, 0));
page.drawString("Red: " + oneColor.getRed()+ " " + "Green: " + oneColor.getGreen() + " " + "Blue: " + oneColor.getBlue(), 20+(100*l), 90+(100*h));
}
}
}
}
// 司机
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class Colorsorter extends Color implements Comparable <Colorsorter>
{
public Colorsorter()
{
super(0,0,0);
}
public Colorsorter (int r, int g, int b)
{
super(r,g,b);
}
public String toString()
{
return("Red: " + getRed() + " " + "Green: " + getGreen() + " " + "Blue: " + getBlue() + " " + "\n");
}
public int compareTo (Colorsorter colorsort)
{
return getRed() - colorsort.getRed();
}
}
我在第 44 行得到错误: Graphic.java:44: error: cannot find symbol page.drawString("Red: " + oneColor.getRed()+ " " + "Green: " + oneColor.getGreen()... .; .................................................. .................... ^