Java ArrayList of ArrayList of Integer无法正常工作

Java ArrayList of ArrayList of Integer无法正常工作,java,arraylist,Java,Arraylist,我正在从事一个处理大量整数的项目,我决定使用一个名为ALL_PIXELS的ArrayList。我无法使arrayList或arrayList中的值唯一。当我用for循环中的一些基本测试检查代码时,一切都正常,一旦退出for循环,子数组的所有值都是相同的,它们不应该是相同的。这是我的一些代码,也许有人能帮我。 我用system.Out语句做了很多测试,并对它们进行了注释。我发现问题在于,我的ArrayList ALL_像素在for循环内似乎正常,但在for循环后,其中的所有子数组都是相同的,这是一

我正在从事一个处理大量整数的项目,我决定使用一个名为ALL_PIXELS的ArrayList>。我无法使arrayList或arrayList中的值唯一。当我用for循环中的一些基本测试检查代码时,一切都正常,一旦退出for循环,子数组的所有值都是相同的,它们不应该是相同的。这是我的一些代码,也许有人能帮我。 我用system.Out语句做了很多测试,并对它们进行了注释。我发现问题在于,我的ArrayList ALL_像素在for循环内似乎正常,但在for循环后,其中的所有子数组都是相同的,这是一个问题

package rmi.client;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.ImageProducer;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import java.util.HashMap;

import rmi.Compute;
import rmi.RmiStarter;

public class StartComputeTaskMan extends RmiStarter {

// things for the Panel that i can't extend

private static JPanel mainPanel = new JPanel(); // this is what I'll add tocontentPane                                               
private static JPanel panel = new JPanel();
private JComponent[] allComponents = { panel };

final static int FRAME_WIDTH = 2000;
final static int FRAME_HEIGHT = 1500;
final static int MAX_ITERATION = 1000;
final static double ZOOM_FACTOR = 5;

final static double X_LEFT_BOUND = -2.5;
final static double X_RIGHT_BOUND = 1.5;
final static double Y_TOP_BOUND = 1.5;
final static double Y_BOTTOM_BOUND = -1.5;

final static BufferedImage IMAGE = new BufferedImage(FRAME_WIDTH,FRAME_HEIGHT, BufferedImage.TYPE_INT_RGB);
final static int[] COLORS = new int[MAX_ITERATION];
final static ArrayList<ArrayList<Integer>> ALL_PIXELS = new ArrayList<ArrayList<Integer>>();
ArrayList<HashMap<String, Double>> boundsHistory = new ArrayList<HashMap<String, Double>>();
int zoomNum = 0;

// end of global variables

// constructor
public StartComputeTaskMan() {
    super(PI.class);


    for (JComponent comp : allComponents) {
        mainPanel.add(comp);
    }// end for loop

    HashMap<String, Double> map = new HashMap<String, Double>();
    map.put("left", X_LEFT_BOUND);
    map.put("right", X_RIGHT_BOUND);
    map.put("top", Y_TOP_BOUND);
    map.put("bottom", Y_BOTTOM_BOUND);
    boundsHistory.add(map);

    for (int i = 0; i < MAX_ITERATION; i++) {
        COLORS[i] = Color.HSBtoRGB(i / 256f, 1, i / (i + 8f));
    }// end for loop
}// end constructor

public static JComponent getMainComponent() {
    return mainPanel;
}// end JComponent

private static void createAndShowGui() {

    // creating my JFrame only when I need it and where I need it
    JFrame frame = new JFrame("Mandelbrotset");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(getMainComponent());
    frame.pack();
    frame.setLocationByPlatform(true);
    frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
    frame.setVisible(true);
    panel.setSize(FRAME_WIDTH, FRAME_HEIGHT);
    panel.setVisible(true);
    frame.add(panel);
}

@Override
public void doCustomRmiHandling() {
    try {
        System.setProperty("java.rmi.server.hostname", "172.31.98.63"); 
        System.out.println("Getting Registry");
        Registry registry = LocateRegistry.getRegistry("172.31.98.63"); 
        System.out.println("Getting Compute");
        try {
            Compute<Integer> compute = (Compute<Integer>) registry.lookup(Compute.SERVICE_NAME);            
        } catch (NotBoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}//end doCustomRmiHandling

public void doTask() {
    System.out.println("Getting Task");


    //why is this not making ALL_PIXELS unique for each row .............

    for (int i = 0; i < FRAME_HEIGHT; i++) {

        HashMap<String, Double> t = boundsHistory.get(zoomNum);
        PI task = new PI(i, t);
        //this is the problem. some where 
        ArrayList<Integer> temp = new ArrayList<Integer>();
        temp = task.execute();
        //System.out.println(temp);
        ALL_PIXELS.add(temp);
        //System.out.println(ALL_PIXELS.get(i));     //still unique here....WHYYYYYYY
        //System.out.println(temp);     //this shows that temp is a unique array each row

    }// end for loop    



    //why is all pixels seting the same vales to all of its sub arrays
    //System.out.println(ALL_PIXELS.get(3));
    //System.out.println(ALL_PIXELS.get(300));


    System.out.println("Computing");




}// end doTask



public double getScaledX(int x) {
    double returnValue = ((double) x / (double) FRAME_WIDTH)* (boundsHistory.get(zoomNum).get("right")
            - boundsHistory.get(zoomNum).get("left"))+ boundsHistory.get(zoomNum).get("left");      
    return returnValue;
}// end getscaledX

public double getScaledY(int y) {
    double returnValue = ((double) y / (double) FRAME_HEIGHT)* -(boundsHistory.get(zoomNum).get("top") 
            - boundsHistory.get(zoomNum).get("bottom")) + boundsHistory.get(zoomNum).get("top");    
    return returnValue;
}// end getscaledY

public static void main(String[] args) {
    createAndShowGui();//makes our GUI
    StartComputeTaskMan test = new StartComputeTaskMan();
    test.doTask();//fills in ALLPIXELS 

    //all of sub arrays are the same in all pixels



    //makeImage(test);//makes the buffered image
    //paintComponent(null);

}// end main

private static void makeImage(StartComputeTaskMan test) {
    for(int j=0; j<FRAME_HEIGHT;j++){
        for(int i=0;i<FRAME_WIDTH;i++){
            if(ALL_PIXELS.get(j).get(i)<MAX_ITERATION){
                IMAGE.setRGB(j,i,COLORS[ALL_PIXELS.get(j).get(i)-1]);
            }else{
                IMAGE.setRGB(j,i,0);

            }


        }//end nested for loop
    }//end for loop
}//end makeImage



private static void paintComponent(Graphics g){
    g.drawImage(IMAGE, 0, 0, FRAME_WIDTH, FRAME_HEIGHT,null);
}
}// end class
包rmi.client;
导入javax.swing.*;
导入java.awt.*;
导入java.awt.image.buffereImage;
导入java.awt.image.ImageProducer;
导入java.rmi.NotBoundException;
导入java.rmi.RemoteException;
导入java.rmi.registry.LocateRegistry;
导入java.rmi.registry.registry;
导入java.util.ArrayList;
导入java.util.HashMap;
导入rmi.Compute;
进口rmi.rmi启动器;
公共类StartComputerTaskMan扩展了Starter{
//我无法扩展的面板的内容
private static JPanel mainPanel=new JPanel();//这是我将添加到ContentPane的内容
私有静态JPanel panel=newjpanel();
私有JComponent[]所有组件={panel};
最终静态整数帧_宽度=2000;
最终静态内部框架高度=1500;
最终静态int MAX_迭代=1000;
最终静态双变焦系数=5;
最终静态双X_左界=-2.5;
最终静态双X_右界=1.5;
最终静态双Y_上限=1.5;
最终静态双Y_底界=-1.5;
最终静态BuffereImage=新的BuffereImage(帧宽、帧高、BuffereImage.TYPE\u INT\u RGB);
最终静态int[]颜色=新int[MAX_迭代];
最终静态ArrayList ALL_像素=新ArrayList();
ArrayList boundsHistory=新的ArrayList();
int zoomNum=0;
//全局变量结束
//建造师
公共StartComputerTaskman(){
超级(PI级);
对于(JComponent comp:allComponents){
主面板。添加(组件);
}//循环结束
HashMap=newHashMap();
map.put(“左”,X_左界);
map.put(“right”,X_right_BOUND);
地图放置(“顶部”,Y_顶部边界);
地图放置(“底部”,Y_底部边界);
添加(地图);
对于(int i=0;i对于(int j=0;j尝试更改以下行:

    ArrayList<Integer> temp = new ArrayList<Integer>();
    temp = task.execute();
    //System.out.println(temp);
    ALL_PIXELS.add(temp);
ArrayList temp=new ArrayList();
temp=task.execute();
//系统输出打印项次(温度);
所有像素。添加(温度);
致:

ArrayList temp=null;
temp=task.execute();
//系统输出打印项次(温度);
所有像素。添加(新阵列列表(临时));
由于PI类的执行方法是
    ArrayList<Integer> temp = new ArrayList<Integer>();
    temp = task.execute();
    //System.out.println(temp);
    ALL_PIXELS.add(temp);
    ArrayList<Integer> temp = null;
    temp = task.execute();
    //System.out.println(temp);
    ALL_PIXELS.add(new ArrayList<Integer>(temp));