我嘗試在第一個數組中保存一些值,然後在第二個數組中的另一個值,我嘗試打印第一個數組並返回第二個數組值。任何想法爲什麼?爲什麼最後一個數組不填寫第一個數組?
這是主要的方法來調用程序
public class testC
{
public static void main(String[] args)
{
groupC trial = new groupC();
trial.setCol(10, 10);
}
}
這是類調用另一個類來獲得顏色和陣列填充每個新座標
public class groupC
{
private color1 col = new color1();
private int[] cola1 = new int[3];
private int[] cola2 = new int[3];
public groupC()
{
}
public void setCol(int xIn, int yIn)
{
cola1 = col.getCol(xIn, yIn);
System.out.println(cola1[0] + " " + cola1[1] + " " + cola1[2]);
/* try next color depending on 1st */
cola2 = col.getCol(xIn + 100, yIn + 100);
System.out.println(cola2[0] + " " + cola2[1] + " " + cola2[2]);
System.out.println("this is 1st color, but why now the same as 2nd ?" + cola1[0] + " " + cola1[1] + " " + cola1[2]);
}
}
這是一流的,它只是變得協調和返回當前顏色值的陣列
import java.awt.Color;
import java.awt.Robot;
import java.awt.AWTException;
public class color1
{
int[] color = new int[3];
public color1()
{
}
public int[] getCol(int xIn, int yIn)
{
// accepts position of color, returns size 3 array of red green blue
// integers
try
{
Robot r = new Robot();
Color x = r.getPixelColor(xIn, yIn);
color[0] = x.getRed();
color[1] = x.getGreen();
color[2] = x.getBlue();
}
catch (AWTException e)
{
e.printStackTrace();
}
return color;
}
}
我假設你已經證明了'color1'類實際上是你的代碼使用'colorD'類。 –
另外,作爲一個附註 - 用BlockCaseLikeThis命名你的'Type',而不是camelCaseWordJoint。語義,並使您的代碼更可重用:) – Unihedron
是的,當我縮短代碼時,有錯誤,colorD是color1,現在正在修復。 – Ubaby