Txt Coordinates into chart...

Reply

Join Date: Mar 2006
Posts: 4
Reputation: lev_arris is an unknown quantity at this point 
Solved Threads: 0
lev_arris lev_arris is offline Offline
Newbie Poster

Txt Coordinates into chart...

 
0
  #1
Mar 30th, 2006
Hi guys, I'm currently making a GUI which displays a graph. At the moment it reads coordinates within an array in the code:


public int datax[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
public int datay[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

I need it to take these coordinates from a txt file, which I'm having trouble with.

So far I've made it read in a txt file and output to a text area like this:


public void readFile() {
// Disable read button
readFile.setEnabled(false);

// Dimension data structure
getNumberOfLines();
data = new String[numLines];

// Read file
readTheFile();

// Output to text area
textArea.setText(data[0] + "\n");
for(int index=1; index < data.length;index++)
textArea.append(data[index] + "\n");

// Rnable open button
openFile.setEnabled(true);
}



My code to plot the coordinates using datasets is this:


//Configure dataset
int n = 10;
Dataset dataset = new Dataset (1, 2, n);

for (int k = 0; k < n; ++k)
dataset.set(0, 0, k, datax[k]);

for (int k = 0; k < n; ++k)
dataset.set(0, 1, k, datay[k]);



I need datax and datay to be read in from the txt file though which is formatted simply x val, y val [per line]
3, 4
2, 6
5, 9 etc..

Even if it read the file into an array, then outputted this to the graph, that would work! I know this should be straightforward, but I just can't see how to do it. Some areas of Java I get, others I definately don't :cry: Can anyone possibly suggest a solution?


Thanks
Lev
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Txt Coordinates into chart...

 
0
  #2
Mar 30th, 2006
It seems like all you need to do is read a basic tutorial about file I/O and how to parse that infomation into an array or vector?

There's lot to choose from, consult google.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 4
Reputation: lev_arris is an unknown quantity at this point 
Solved Threads: 0
lev_arris lev_arris is offline Offline
Newbie Poster

Re: Txt Coordinates into chart...

 
0
  #3
Mar 30th, 2006
I've looked through whats on Google, all I'm looking for is something that will feed (parse) the output of the file reader into the datax and datay arrays. My Java is terrible!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Txt Coordinates into chart...

 
0
  #4
Mar 30th, 2006
>My Java is terrible!

So do something about it. Come on kiddo, how hard can it be, read in a file, use the whitespace or comma as a delimiter, push them into a vector then plot them.

Simple as pie.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 4
Reputation: lev_arris is an unknown quantity at this point 
Solved Threads: 0
lev_arris lev_arris is offline Offline
Newbie Poster

Re: Txt Coordinates into chart...

 
0
  #5
Mar 30th, 2006
Can anyone other than this guy give me some advice for the coding? When you've been thrown in at the deep end with Java it isn't 'simple as pie'.... I think it must be something like datax.add(data.toIntArray()); :-S
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Txt Coordinates into chart...

 
0
  #6
Mar 30th, 2006
Originally Posted by lev_arris
Can anyone other than this guy give me some advice for the coding? When you've been thrown in at the deep end with Java it isn't 'simple as pie'.... I think it must be something like datax.add(data.toIntArray()); :-S

Like I said, now is the time to take responsibility for yourself and stop being spoon fed. Grow up and do it yourself.

If you don't know how, then you should have been paying more attention in class instead of looking for nekid ladeeze.

ThanQ
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Txt Coordinates into chart...

 
0
  #7
Mar 30th, 2006
Originally Posted by lev_arris
Hi guys, I'm currently making a GUI which displays a graph. At the moment it reads coordinates within an array in the code:


public int datax[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
public int datay[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

I need it to take these coordinates from a txt file, which I'm having trouble with.

So far I've made it read in a txt file and output to a text area like this:


public void readFile() {
// Disable read button
readFile.setEnabled(false);

// Dimension data structure
getNumberOfLines();
data = new String[numLines];

// Read file
readTheFile();

// Output to text area
textArea.setText(data[0] + "\n");
for(int index=1; index < data.length;index++)
textArea.append(data[index] + "\n");

// Rnable open button
openFile.setEnabled(true);
}



My code to plot the coordinates using datasets is this:


//Configure dataset
int n = 10;
Dataset dataset = new Dataset (1, 2, n);

for (int k = 0; k < n; ++k)
dataset.set(0, 0, k, datax[k]);

for (int k = 0; k < n; ++k)
dataset.set(0, 1, k, datay[k]);



I need datax and datay to be read in from the txt file though which is formatted simply x val, y val [per line]
3, 4
2, 6
5, 9 etc..

Even if it read the file into an array, then outputted this to the graph, that would work! I know this should be straightforward, but I just can't see how to do it. Some areas of Java I get, others I definately don't :cry: Can anyone possibly suggest a solution?


Thanks
Lev
Here are a few steps:

Start with a buffered reader:

  1. BufferedReader br = new BufferedReader(new FileReader(file));
once you have that, then you can read from the file:

  1.  
  2. String in = "";
  3. while ( (in = br.readLine()) != null)
  4. {
  5. //parse the code
  6. //add the arraylist
  7. }

The parsing is the only part that might cause you trouble, but if you use a StringTokenizer then you should have no problem at all.


Like I said, now is the time to take responsibility for yourself and stop being spoon fed. Grow up and do it yourself.

If you don't know how, then you should have been paying more attention in class instead of looking for nekid ladeeze.

ThanQ
What gives you the right to be so harsh? You need to pay more attention in English class.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Txt Coordinates into chart...

 
0
  #8
Mar 31st, 2006
>What gives you the right to be so harsh? You need to pay more attention in English class.

-Ummm ok? Thanx for that mom?

You gotta be joking right? It's simple stuff, I don't see what da problem is? Do your own homework kiddo:eek:
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Txt Coordinates into chart...

 
0
  #9
Mar 31st, 2006
Originally Posted by iamthwee
>What gives you the right to be so harsh? You need to pay more attention in English class.

-Ummm ok? Thanx for that mom?
Don't be a hypocrite. You made a comment worse than I did except in a different context.

You gotta be joking right? It's simple stuff, I don't see what da problem is?
It's simple stuff just like the stuff you post.


Do your own homework kiddo:eek:
It's not my homework and I'm not a 'kiddo'.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Txt Coordinates into chart...

 
0
  #10
Mar 31st, 2006
>Don't be a hypocrite. You made a comment worse than I did except in a different context.

Huh? What are you going on about?

>It's simple stuff just like the stuff you post.

Aaaaaha ha, thanx for helping me tho, I appreciate that?

>It's not my homework and I'm not a 'kiddo'.

I wasn't referring to you :rolleyes:, and I use the word kiddo in a derogatory sense.

ThanQ

P.S can't we just kiss and make up.... prettie please. I much prefer it when we're not fighting. Plus I bet it annoys Dani
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC