File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes 2d arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "2d arrays" Watch "2d arrays" New topic

2d arrays

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

I have a file of seven columns, each column contains approximately 100 numbers in length,
I need to take these seven columns of data into an array and then access the array accordingly in terms of the columns which I will then use to plot many graphs. At any one time I will access only two columns.
I already have the graph plotting program and the graph will be displayed on an applet in a web page on the WWW.
The person who accesses the web page will want certain columns plotting against other columns so the web page needs to take in this data (i.e. which column to plot against which), select the appropriate columns in the array and then plot the graph. All this has to be done using a gui. Any suggestions on appropriate code.
Have you got any idea on how to do this.
I appreciate the help
Andrew Stevenson
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
You will first need a method to read the contents of the file and store it in an array. The array should be two dimensional. First dimension is 7 and the second dimension can be 100 if you are sure that is as many items each column can contain, OR you can create the second dimension for each column at runtime for the required length.
The next thing you will need is a convenient interface to the graph-plotting routine which will take a two single dimension array as the argument representing the two sets of data for the graph ( I am hoping you already have such an interface ).
Once you have these two components, your program flow should look like this.
1. Create a two-dimensional array( lets assume they are all int )
int graphData[][] = new int[7][100]
2. Read contents of the file into the array.
3. Display GUI, get the two columns from the user, say
nFirstColToDraw, nSecondColToDraw
4. Call the method plotGraph( graphData[nFirstColToDraw],
graphData[nSecondColToDraw] )

If the plotting logic is also a part of the same class as the one that holds the graphData, then you might just want to pass the two integer values nFirstColToDraw, nSecondColToDraw to the method and retrieve the graphData[nFirstColToDraw] and graphData[nSecondColToDraw] inside the method. This is just a matter of how you design your classes.

Hope this helps,

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
I agree. Here's the link:
subject: 2d arrays
It's not a secret anymore!