My code runs the algorithm in an array and stores the results in an ArrayList. The problem is that I cannot access the contents of the ArrayList for later processing. Although my actual code lasts thousands of lines, I got into a problem and created the problem again in the short code segments below. You can take the three classes below and run them in your IDE without changes to reproduce the problem yourself. As you can see, it fills the ArrayList in makeArrayList.java, but still the contents of the ArrayList array are not subsequently displayed in getArrayList.java.
Can someone show me how to fix the code below so that the contents of the ArrayList become visible / useful in getArrayList.java and in myGUI.java?
Here is the code for the three classes:
Code myGUI.java:
package arrayListPractice; import java.awt.Dimension; import javax.swing.JFrame; public class myGUI extends JFrame { public myGUI() { super("test GUI"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setPreferredSize(new Dimension(300, 200)); getArrayList getArrList = new getArrayList(); getArrList.getPeaks(); this.pack();} public static void main(String args[]) { myGUI myFrame = new myGUI(); myFrame.setVisible(true);}}
Code for getArrayList.java:
package arrayListPractice; import java.util.*; public class getArrayList { public static ArrayList<Integer> PeakList; int myLength = 3500; double[] myArray=new double[myLength]; public ArrayList<Integer> getPeaks(){ for(int h=0;h<myLength;h++){myArray[h]=Math.sqrt((double)h);} PeakList = new makeArrayList(myArray,myLength); System.out.println("in getArrayList.getPeaks, PeakList.size() is: "+PeakList.size()); return PeakList;}}
Code makeArrayList.java:
package arrayListPractice; import java.util.*; public class makeArrayList extends ArrayList<Integer> { ArrayList<Integer> myArrayList= new ArrayList<Integer>(); public makeArrayList(double[] myArray, int arrayLength) {
source share