Solved

displaying text and converting

Posted on 2004-04-17
111
636 Views
Last Modified: 2010-08-05
hello
2 part question

what is the best way to diplay multiple lines of text, i don't want the user to be able to edit, in a frame? do i just draw string?

i want to read a string from a file with numbers something like:
12 34 54 73 97 and so on
I want to convert each number in the string to an integer
so that 12 would be an integer 34 another integer and so on

please give examples
thanks
0
Comment
Question by:Samooramad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 52
  • 32
  • 25
  • +2
111 Comments
 
LVL 4

Expert Comment

by:brunomsilva
ID: 10849778
well,
you could use HTML <html>line1<br>line2</html> for the multiline question

bruno
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10849779
Just use a JTextArea and setEditable(false)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10849790
You could also do this in your frame

JEditorPane textDisplay = new JEditorPane("file:/c/yourFile.txt");
getContentPane().add(textDisplay, BorderLayout.CENTER);

which will display the file
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 86

Expert Comment

by:CEHJ
ID: 10849808
If you need to display AND convert, then you'll need to break up the operation, reading 'manually' from the file
0
 

Author Comment

by:Samooramad
ID: 10849825
I'm not using html bruno
0
 

Author Comment

by:Samooramad
ID: 10849830
>> JTextArea and setEditable(false)
some answers are so simple they make me feel like a moron. I'm sure that will do the trick
0
 

Author Comment

by:Samooramad
ID: 10849844
>>If you need to display AND convert, then you'll need to break up the operation, reading 'manually' from the file
no i don't want to display the file. I just want to break the string up into integers(that have a max of 2 digits) then i will use them seperatly somewhere else
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10849852
I'm getting confused - this is what you said first:

>>what is the best way to diplay multiple lines of text, i don't want the user to be able to edit
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 10849873
Have a look at this example. Then you can add the following functionality

http://javaalmanac.com/egs/java.io/ReadLinesFromFile.html

try {
        BufferedReader in = new BufferedReader(new FileReader("infilename"));
        ArrayList numbers = new ArrayList();
        String str;
        while ((str = in.readLine()) != null) {
            numbers.add(process(str, numbers));
        }
        in.close();
    } catch (IOException e) {
    }



........


public void process(String numberLine, List numbers) {
      String[] strNumbers = numberLine.split("\\s");
      for(int i = 0;i < strNumbers.length;i++) {
            numbers.add(new Integer(Integer.parseInt(strNumbers[i])));

      }
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10849876
Oops

>>numbers.add(process(str, numbers));


should be

process(str, numbers);
0
 

Author Comment

by:Samooramad
ID: 10849898
sorry i wasn't clear cehj
the first part has nothing to do with the second i have a frame that will display directions but i couldn't figure out how to display MULTIPLE lines s of text except with JTextArea which can be edited. I didn't know you can disable that

the second part is where i have an applet that uses values(integers) for drawing shapes. i want the added feature of opening a file and reading numbers from the file to use in drawing. to do that i need them converted into integers so that i can use each one to draw a different shape in the applet. I have figured out how to read from a file and how to display what is read in the applet. my problem is they need to be integers so i can use them and i don't know how to break up the string and convert into integers
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10849917
OK. That code i just posted will do that for you. When you come to use them, you need to do another operation, since the list does not contain primitives:

int firstInt = ((Integer)numbers.get(0)).intValue();
0
 

Author Comment

by:Samooramad
ID: 10850029
is there any quick way for me to check if it is working correctly getting it into the drawing part will take me a while
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10850053
Not that i can think of. A small adjustment here:

>>numbers.add(new Integer(Integer.parseInt(strNumbers[i])));


should be

numbers.add(new Integer(Integer.parseInt(strNumbers[i].trim())));
0
 

Author Comment

by:Samooramad
ID: 10850054
numbers would be a list of integers then? is that similar to an array of integers?
0
 

Author Comment

by:Samooramad
ID: 10850061
what does trim do?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10850092
>>numbers would be a list of integers then? is that similar to an array of integers?

yes and yes

>>what does trim do?

removes unwanted space at the ends of the String

0
 

Author Comment

by:Samooramad
ID: 10850121
well thanks cehj. It will take me till tomorrow to find out if its working right(I'm sure it will) you've been great help in just a couple hours :)
I will post any more questions I have same time tomorrow. hope i find you
thanks again
0
 

Author Comment

by:Samooramad
ID: 10850137
one more question

>>BufferedReader in = new BufferedReader(new FileReader("infilename"));
what is infilename? variable? do i use mine?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10850144
ok
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10850154
>>what is infilename? variable? do i use mine?

It's the name of the file to read. You'd use your own
0
 
LVL 92

Expert Comment

by:objects
ID: 10851210
import javax.swing.*;

public class DisplayText
{
   public static void main(String[] args)
   {
      JFrame f = new JFrame();
      JTextArea ta = new JTextArea("first line\nsecond line\nthird line");
      ta.setEditable(false);
      f.getContentPane().add(new JScrollPane(ta));
      f.pack();
      f.show();
   }
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10851218
import java.util.*;

public class DisplayText
{
   public static void main(String[] args)
   {
      String line = "12 34 54 73 97";
      StringTokenizer st = new StringTokenizer(line);
      int values = new int[st.countTokens()];
      int i = 0;
      while (st.hasMoreTokens()) values[i++] = Integer.parseInt(st.nextToken());

      // print it out
      for (int j=0; j<values.length; j++) System.out.println(values[j]);
   }
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10851222
better change the name of that second one:

import java.util.*;

public class ParseText
{
   public static void main(String[] args)
   {
      String line = "12 34 54 73 97";
      StringTokenizer st = new StringTokenizer(line);
      int values = new int[st.countTokens()];
      int i = 0;
      while (st.hasMoreTokens()) values[i++] = Integer.parseInt(st.nextToken());

      // print it out
      for (int j=0; j<values.length; j++) System.out.println(values[j]);
   }
}
0
 

Author Comment

by:Samooramad
ID: 10870765
i'm using list and i got an error:
Error #: 304 : reference to List is ambiguous; both interface java.util.List in package java.util and class java.awt.List in package java.awt match at line 423, column 8
 
what does that mean?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10870793
That's a blunder by Sun. Use the fully qualified names

java.util.List items = new ArrayList();
java.awt.List guiItems = new java.awt.List(....


or whatever
0
 

Author Comment

by:Samooramad
ID: 10870812
got another error from using split method in the code you posted
Error #: 300 : method split(java.lang.String) not found in class java.lang.String at line 411, column 39
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10870851
That means you have an out of date version of Java. I'd recommend you update it unless you have a good reason for not doing so as you'll be missing out on a lot of powerful functionality added in 1.4.

http://java.sun.com/j2se/1.4.2/download.html
0
 

Author Comment

by:Samooramad
ID: 10870934
do i need to download both the software kit and runtime environment?
would it just update the older version or do i install it separetly?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10870983
You may as well get both. Unless you've got a good reason for not doing, i'd uninstall your old version(s) first and then install the new one(s).
0
 

Author Comment

by:Samooramad
ID: 10871025
no reason. I just worry I'll uninstall the working one and won't get the new version installed then I'll be in a mess
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10871172
Well i don't blame you - i get like that myself ;-). If you're not feeling like it at the moment, combine my code with objects StringTokenizer code, then you'll get out of that split() problem
0
 

Author Comment

by:Samooramad
ID: 10871383
so just replace split with string tokenizer?
I'm in the proccess of downloading.. keep your fingers crossed :)
I'll be one sad girl if this doesn't work
0
 

Author Comment

by:Samooramad
ID: 10871572
ok so there was a problem downloading...if there is any possible way to do this for now I'd prefer that.
objects code went right over my head... could you give me an idea how to use it with yours?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10871621
Just change my process method to

public void process(String numberLine, List numbers) {
     StringTokenizer st = new StringTokenizer(numberLine);
     while(st.hasMoreTokens()) {
          numbers.add(new Integer(Integer.parseInt(st.nextToken().trim())));
     }
}
0
 

Author Comment

by:Samooramad
ID: 10871650
ok I'll try it
thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 10872709
> so just replace split with string tokenizer?

see the code I posted earlier :)

> objects code went right over my head

Then ask what you're confused about :)
Though CEHJ's example looks pretty much the same.
0
 
LVL 92

Expert Comment

by:objects
ID: 10872732
save the second example as ParseText.java and run it using:
java ParseText

import java.util.*;

public class ParseText
{
   public static void main(String[] args)
   {
      // line of text to parse

      String line = "12 34 54 73 97";
     
      // tokenize the string

      StringTokenizer st = new StringTokenizer(line);

      // create array to store values

      int values = new int[st.countTokens()];
      int i = 0;

      // read ints from string and store in array

      while (st.hasMoreTokens()) values[i++] = Integer.parseInt(st.nextToken());

      // print it out

      for (int j=0; j<values.length; j++) System.out.println(values[j]);
   }
}
0
 

Author Comment

by:Samooramad
ID: 10883171
if there were only one thing I was confused about i would be specific objects :)
I just didn't get how it would work at all.. I've never used tokenizer either so I'm not exactly what it does
0
 
LVL 92

Expert Comment

by:objects
ID: 10883202
> I've never used tokenizer either so I'm not exactly what it does

I have commented the code above.
0
 

Author Comment

by:Samooramad
ID: 10883224
ok i dont want to print it out. after saving values in the array i want to read them one at a time into another method that will use them to draw.
I'm still trying cehj's code but i'm having problems
0
 

Author Comment

by:Samooramad
ID: 10883387
I can't get past this problem
the method cehj posted so i could transfer my results to another file through a method gives me this error
Error #: 303 : 'this' cannot be referenced from a static context at line 423, column 6also the methos get does not work in the other file
I need to transfer my resulting integers to another file to put in a method one by one like with an index [i]
IT just wont work
0
 
LVL 92

Expert Comment

by:objects
ID: 10883409
> ok i dont want to print it out.

that was just as an example to show what it was doing :)

> after saving values in the array i want to read them one at a time into another method that will use them to draw

just pass the generated array to the method
0
 
LVL 92

Expert Comment

by:objects
ID: 10883419
> the method cehj posted so i could transfer my results to

which uses the same technique as I had suggested :)

> a method gives me this error

post the code u are currently using and i'll sort out the problem
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10883422
Make sure you are not calling instance methods from static methods
0
 
LVL 92

Expert Comment

by:objects
ID: 10883476
Thats not the problem, if you look at the error the problem is that 'this' is being used in a static method.
this cannot be used from a static method.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10883505
It could well be the problem if they are are instance methods of classes that form instance variables
0
 

Author Comment

by:Samooramad
ID: 10883549
is there a way to transfer them without sing "this"?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10883555
What is your class called? Have you create an instance of it?
0
 
LVL 92

Expert Comment

by:objects
ID: 10883556
this refers to the current object, a static method does not have a current object so it cannot be used.
One option would be to make the method not static. ie. remove the static keyword.
0
 

Author Comment

by:Samooramad
ID: 10883569
I'm using the code cehj posted exactly that way.. them i passed the list to set method and tried to "get" it from the other file. that did'nt work so i tried passing the integer values throught the methods after this line of code
 int firstInt = ((Integer)numbers.get(0)).intValue();
all the code I used was in the original file... the only thing I tried to was "Get" them in the other file then i got the error
"Spots.java": Error #: 300 : method getNumber() not found in class at line 400, column 62
0
 
LVL 92

Expert Comment

by:objects
ID: 10883588
What is it specifically you want to do, and how do you need it to fit into your code.
0
 

Author Comment

by:Samooramad
ID: 10883596
please help.. I'm a hopless case and I'm getting really frustrated. I've been working on this same bit for days and can't figure out how to fix it
0
 

Author Comment

by:Samooramad
ID: 10883615
the methods were static then i changed them.. what are they supposed to be?
0
 
LVL 92

Expert Comment

by:objects
ID: 10883645
can you post your code where you are trying to handle this
0
 

Author Comment

by:Samooramad
ID: 10883647
objects....
what does st.countTokens() do?
does it count the characters or something like that?
0
 
LVL 92

Expert Comment

by:objects
ID: 10883664
> what does st.countTokens() do?

It returns the number of token in the line, in this case it would be the number of integers.

Does your text file contain more than one line?

0
 

Author Comment

by:Samooramad
ID: 10883692
try {
        File file = new File(fileName);
        BufferedReader in = new BufferedReader(new FileReader(fileName));////add
        ArrayList numbers = new ArrayList();
        String str;

        while ((str = in.readLine()) != null) {
            process(str, numbers); }
        in.close();

        //jTextArea1.setText(new String(data, 0, chars_read));
    }
    catch (IOException e) {}
}
//////////////////////////////
public void process(String numberLine, java.util.List numbers) {
     StringTokenizer st = new StringTokenizer(numberLine);
     while(st.hasMoreTokens()) {
          numbers.add(new Integer(Integer.parseInt(st.nextToken().trim())));
     firstInt = ((Integer)numbers.get(0)).intValue();
     setNumber(firstInt);
     }
}


that is the code I'm using... I want to read the string from a file, separate into integers then take each integer into another file. I tried using a getNumber method that returns the value of the integer after i set it but the set and get methods don't seem to be visible in the other file
so in a nutshell everything i did including code and declarations and methods are in the first file
all i want to do in the second file is get the value of the integers one by one using an index if possible
0
 

Author Comment

by:Samooramad
ID: 10883705
it should only contain one line
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10883723
The method containing that try block should not be static
0
 

Author Comment

by:Samooramad
ID: 10883731
>>What is your class called? Have you create an instance of it?sorry cehj i just saw this comment

do you mean the file? visualize.java
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 10883732
try {
        File file = new File(fileName);
        BufferedReader in = new BufferedReader(new FileReader(fileName));////add
       StringTokenizer st = new StringTokenizer(in.readLine());

       // create array to store values

       int[] values = new int[st.countTokens()];
       int i = 0;

       // read ints from string and store in array

        while (st.hasMoreTokens()) values[i++] = Integer.parseInt(st.nextToken());

        in.close();

        // now do what you want with your int array.

    }
    catch (IOException e) {}
0
 
LVL 92

Expert Comment

by:objects
ID: 10883742
to loop thru the values in your array you would then use:

for (int i=0; i<values.length; i++)
{
   int value = values[i];
   // do as needed
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10883762
>>do you mean the file? visualize.java

If you've got a class called 'visualize' containing the try block you just posted, you should be creating an instance of it
0
 
LVL 92

Expert Comment

by:objects
ID: 10883769
import java.util.*;
import java.io.*;

public class ParseText
{
   public static void main(String[] args)
   {
     try
     {
        File file = new File(args[0]);
        BufferedReader in = new BufferedReader(new FileReader(file));
       StringTokenizer st = new StringTokenizer(in.readLine());

       // create array to store values

       int[] values = new int[st.countTokens()];
       int i = 0;

       // read ints from string and store in array

        while (st.hasMoreTokens()) values[i++] = Integer.parseInt(st.nextToken());

        in.close();

        // now do what you want with your int array.

    for (int i=0; i<values.length; i++)
   {
      int value = values[i];
      // do as needed
    }

    }
    catch (IOException e)
   {
      ex.printStackTrace();
   }
  }
}
0
 

Author Comment

by:Samooramad
ID: 10883800
>>The method containing that try block should not be static
it isn't... I just called it
void openfile(filename)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10883838
OK. So in main you should have something like

visualize v = new visualize();
v.openFile(args[0]);
0
 

Author Comment

by:Samooramad
ID: 10883860
>>If you've got a class called 'visualize' containing the try block you just posted, you should be creating an instance of it
I'm not sure I know what you mean
0
 
LVL 92

Expert Comment

by:objects
ID: 10883865
the code you are using is unnecessarilt compilicated, you don't need to worry about using an ArrayList and can just use an int array.
0
 

Author Comment

by:Samooramad
ID: 10883869
objects
do i put "public class ParseText"
in a separate file or in my original file.. if so how do i get the other file to see int[] values ?
0
 
LVL 92

Expert Comment

by:objects
ID: 10883876
all you need is this:

try {
        BufferedReader in = new BufferedReader(new FileReader(fileName));
       StringTokenizer st = new StringTokenizer(in.readLine());

       // create array to store values

       int[] values = new int[st.countTokens()];
       int i = 0;

       // read ints from string and store in array

        while (st.hasMoreTokens()) values[i++] = Integer.parseInt(st.nextToken());

        in.close();

     setNumber(values[0]);
    }
    catch (IOException e) {}
0
 

Author Comment

by:Samooramad
ID: 10883878
>>OK. So in main you should have something like
but my main is in a completly different file... does that make any difference?
0
 
LVL 92

Expert Comment

by:objects
ID: 10883879
> do i put "public class ParseText"
> in a separate file or in my original file..

That should be put in a seperate file and was just intended as an example as i don't have your code to see how to incorporate it.
The code above that i just posted should drop into your class.
0
 
LVL 92

Expert Comment

by:objects
ID: 10883882
> but my main is in a completly different file... does that make any difference?

Certainly does, not sure why he suggested that.
How do you call this method?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10883889
The following is a runnable version of the code you posted. See the comment in capitals:

import java.io.*;
import java.util.*;

public class visualize {

      public static void main(String[] args) {
            visualize v = new visualize();
            v.openFile(args[0]);
      }

      public void openFile(String fileName) {
            try {
                  File file = new File(fileName);
                  BufferedReader in = new BufferedReader(new FileReader(fileName));
                  ////add
                  ArrayList numbers = new ArrayList();
                  String str;
                  while ((str = in.readLine()) != null) {
                        process(str, numbers);
                  }
                  in.close();

            }
            catch (IOException e) {
                  e.printStackTrace();
            }
      }

      public void process(String numberLine, java.util.List numbers) {
            StringTokenizer st = new StringTokenizer(numberLine);
            while (st.hasMoreTokens()) {
                  numbers.add(new Integer(Integer.parseInt(st.nextToken().trim())));
                  int firstInt = ((Integer) numbers.get(0)).intValue();
                  // DO YOUR SET NUMBER HERE
                  //setNumber(firstInt);
                  System.out.println(firstInt);
                  
            }
      }

}
0
 

Author Comment

by:Samooramad
ID: 10883898
>>setNumber(values[0]);
how do i write set method without using " this"? that was causing another error
0
 
LVL 92

Expert Comment

by:objects
ID: 10883910
> how do i write set method without using " this"?

make your method non-static.
0
 
LVL 92

Expert Comment

by:objects
ID: 10883919
eg.

public void openFile(String fileName)
{
try {
        BufferedReader in = new BufferedReader(new FileReader(fileName));
       StringTokenizer st = new StringTokenizer(in.readLine());

       // create array to store values

       int[] values = new int[st.countTokens()];
       int i = 0;

       // read ints from string and store in array

        while (st.hasMoreTokens()) values[i++] = Integer.parseInt(st.nextToken());

        in.close();

     setNumber(values[0]);
    }
    catch (IOException e) {}
}
0
 

Author Comment

by:Samooramad
ID: 10883921
ok so say the file with main is called fileone...all this has is a few basic lines
then there is filetwo where i have the code you wrote and the bulk of my program...this is where i want to open file and read and turn into integers
then in filethree which is incharge of the drawing part all i want is to get the integer values i got as a result of code in filetwo
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10883931
btw, why are you interested in them being integers?
0
 

Author Comment

by:Samooramad
ID: 10883935
>> make your method non-static
i did
0
 
LVL 92

Expert Comment

by:objects
ID: 10883945
>>> make your method non-static
>i did

post the error, and your method.
0
 

Author Comment

by:Samooramad
ID: 10883951
>>btw, why are you interested in them being integers?
 the code written for drawing only accepts integers as values..thats why i need to pass integers
0
 

Author Comment

by:Samooramad
ID: 10883970
I still get
Error #: 300 : method getNumbers() not found in class Spots at line 400, column 62
spots is the applet I'm trying to pass the integer to
are getNumber and setNumber supposed to be written in a specific way?
0
 
LVL 92

Expert Comment

by:objects
ID: 10883972
> Error #: 300 : method getNumbers() not found in class Spots at line 400, column 62

then you need a reference to your Spots instance and use:

spots.setNumber(values[0]);
0
 

Author Comment

by:Samooramad
ID: 10883977
//methods to get and set
 public void setNumber(int number) {
     this.number = number;
}
 public int getNumber() {
     return number;
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10883982
if it isn't already available as a member variable in that class then you could possibly also pass it as a parameter to the method:

public void openFile(Spots spots, String fileName)
{
   ...

0
 

Author Comment

by:Samooramad
ID: 10883992
>>then you need a reference to your Spots instance and use:

spots.setNumber(values[0]);
what about get? which happens inside spots?
0
 

Author Comment

by:Samooramad
ID: 10884006
>>then you need a reference to your Spots instance and use:

spots.setNumber(values[0]);
now i get this error:
Error #: 300 : method setNumber(int) not found in class java.applet.Applet at line 413, column 12
0
 

Author Comment

by:Samooramad
ID: 10884019
also got
"Spots.java": Error #: 300 : method getNumbers() not found in class Spots at line 400, column 62
0
 
LVL 92

Expert Comment

by:objects
ID: 10884030
Where is spots variable declared?
0
 

Author Comment

by:Samooramad
ID: 10884042
public void openFile(Spots spots, String fileName)
{

didn't work
do i need to put the set and get methods in the second file instead of the first?
0
 

Author Comment

by:Samooramad
ID: 10884057
Where is spots variable declared?
thats the name of the second file(the applet)
i have it declared at the begining of the first file (visualize)
as Applet Spots = new Spots();
0
 
LVL 92

Expert Comment

by:objects
ID: 10884100
> Applet Spots = new Spots();

change that to:

Spots spots = new Spots();
0
 

Author Comment

by:Samooramad
ID: 10884148
Spots spots = new Spots();
did that and spots.setNumber(values[0]);
still get
Error #: 300 : method setNumber(int) not found in class visualizer.Spots at line 414, column 12
0
 
LVL 92

Expert Comment

by:objects
ID: 10884170
can u post your spots class, that error is saying it does not have a setNumber() method but earlier you said it did.
0
 

Author Comment

by:Samooramad
ID: 10884185
its very long..do u want me to post it all?
0
 
LVL 92

Expert Comment

by:objects
ID: 10884197
ok, just post the setNumber() method.
0
 

Author Comment

by:Samooramad
ID: 10884201
node._node(vertices[i].x -10,vertices[i].y-10,getNumbers(),vertices[i].c,vertices[i].c2,g);

this is the line in spots i want to pass the integer to
it calls a method "node" inside the classs "node" and i want to pass the integer where get numbers is
0
 

Author Comment

by:Samooramad
ID: 10884216
i didn't put setNumber in spots
just in visualize file where the openfile code u posted is
i only want to use getNumber in spots
0
 

Author Comment

by:Samooramad
ID: 10884237
public void setNumber(int number) {
     this.number = number;}

 public int getNumber() {
     return number;
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10884242
if setNumber is in visualize then just use:

setNumber(values[0]);

Then in your spot class you will need to have a visulaize instance to call getNumber():

int i = myvisualize.getNumber();
0
 

Author Comment

by:Samooramad
ID: 10884244


int number;

public void setNumber(int number) {
     this.number = number;}

 public int getNumber() {
     return number;
}
0
 

Author Comment

by:Samooramad
ID: 10884253
ok
is it right to have the get and set methods in visualize and not in spots? or is that causing some problem?
0
 

Author Comment

by:Samooramad
ID: 10884268
>>Then in your spot class you will need to have a visulaize instance to call getNumber():
so
visualize myvisualize = new visualize();
then
int i = myvisualize.getNumber();

like that?
0
 
LVL 92

Expert Comment

by:objects
ID: 10884450
> like that?

no

> is it right to have the get and set methods in visualize and not in spots?

its hard to say without knowing more about your design.
But from what you've stated in this question it would seem more appropriate to have it in the Spots class.
eg. move the following from visualize to spots:

int number;

public void setNumber(int number) {
     this.number = number;}

 public int getNumber() {
     return number;
}
0
 
LVL 1

Expert Comment

by:vishalbhando
ID: 10898185
This will solve your problem..


Reader r = new BufferedReader(new InputStreamReader(new FileIntputStream("yourFileName")));
StreamTokenizer st = new StreamTokenizer(r);
int tokenType=0;
while((tokenType=st.nextToken())!=StreamTokenizer.TT_EOF){
      if(tokenType==StreamTokenizer.TT_NUMBER){
      System.out.print((int)st.nval);
      }
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10913045
8-)
0
 

Author Comment

by:Samooramad
ID: 10913063
it finally woked! thanks
0
 

Author Comment

by:Samooramad
ID: 10913071
uuh worked
0
 
LVL 92

Expert Comment

by:objects
ID: 10913860
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question