Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #2228

Re: output to TextArea

From markspace <-@.>
Newsgroups comp.lang.java.help
Subject Re: output to TextArea
Date 2012-11-05 09:41 -0800
Organization A noiseless patient Spider
Message-ID <k78to3$m3r$1@dont-email.me> (permalink)
References <d16bac4f-6997-409e-a7ae-8242371d4b4c@googlegroups.com>

Show all headers | View raw


I'm not sure why this is hard, but I've seen another neophyte do the 
same thing.  To use an object later (for example, to use it to display 
some text as part of a GUI), you have to store the object someplace 
where it will still be in scope and the system can access it.  Local 
scope like you have here is not going to work.

Move the wordArea declaration outside of the shuffle method.  Now at 
least you can add the wordArea to a GUI someplace.  Then just call 
append() to add lines to it.

Read up on how to declare variables in Java.

<http://docs.oracle.com/javase/tutorial/java/javaOO/variables.html>


On 11/5/2012 4:00 AM, Bob wrote:

>     JTextArea wordArea = new JTextArea(15, 20);  <-------------+
>                                                                |
>     public static void shuffle(String dummy, String input){    |
>        // JTextArea wordArea = new JTextArea(15, 20);  --------+
>
>        if(input.length() <= 1)
>        { System.out.println(dummy+input);
            wordArea.append( dummy+input+'\n' ); }  // add this
>        else {
>           for(int i=0; i <input.length();i++){
>              //wordArea.add(String(shuffle(dummy+input.charAt(i), input.substring(0, i) + input.substring(i+1, input.length()))));
>              shuffle(dummy+input.charAt(i), input.substring(0, i) + input.substring(i+1, input.length()));
>           }
>        }
>     }

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

output to TextArea Bob <bherbst65@hotmail.com> - 2012-11-05 04:00 -0800
  Re: output to TextArea markspace <-@.> - 2012-11-05 09:41 -0800
  Re: output to TextArea Jeff Higgins <jeff@invalid.invalid> - 2012-11-05 15:40 -0500
  Re: output to TextArea Roedy Green <see_website@mindprod.com.invalid> - 2012-11-06 09:11 -0800
  Re: output to TextArea Bob <bherbst65@hotmail.com> - 2012-11-07 05:00 -0800

csiph-web