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


Groups > comp.lang.java.help > #2227 > unrolled thread

output to TextArea

Started byBob <bherbst65@hotmail.com>
First post2012-11-05 04:00 -0800
Last post2012-11-07 05:00 -0800
Articles 5 — 4 participants

Back to article view | Back to comp.lang.java.help


Contents

  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

#2227 — output to TextArea

FromBob <bherbst65@hotmail.com>
Date2012-11-05 04:00 -0800
Subjectoutput to TextArea
Message-ID<d16bac4f-6997-409e-a7ae-8242371d4b4c@googlegroups.com>
Hi All, 
The shuffle output is now 
System.out.println(dummy+input); 
I would want to know what to code it so 
that it appears in the JTextArea.
(code snip)

   public void actionPerformed(ActionEvent e) {
      String text = wordField.getText() ;

      if (e.getActionCommand().equals("GrabItAll")) {
         shuffle("",text);
      }else if (e.getActionCommand().equals("close")) {System.exit(0);}
   }
   
   public static void shuffle(String dummy, String input){
      JTextArea wordArea = new JTextArea(15, 20);
      
      if(input.length() <= 1) 
        System.out.println(dummy+input); 
      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()));
         }   
      }
   } 

TIA
Bob

[toc] | [next] | [standalone]


#2228

Frommarkspace <-@.>
Date2012-11-05 09:41 -0800
Message-ID<k78to3$m3r$1@dont-email.me>
In reply to#2227
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()));
>           }
>        }
>     }

[toc] | [prev] | [next] | [standalone]


#2229

FromJeff Higgins <jeff@invalid.invalid>
Date2012-11-05 15:40 -0500
Message-ID<k797r1$qg8$1@dont-email.me>
In reply to#2227
On 11/05/2012 07:00 AM, Bob wrote:

> I would want to know what to code it so
> that it appears in the JTextArea.

Have you seen the sscce thing? Yes.
What add method(s) does the JTextArea class expose?
What method(s) does the JTextArea class expose
that would help you achieve your goal?
Here's a hint: you can look in the documentation.

[toc] | [prev] | [next] | [standalone]


#2230

FromRoedy Green <see_website@mindprod.com.invalid>
Date2012-11-06 09:11 -0800
Message-ID<s4hi98h66bg7dkujd1p0obr5anvpsr49dg@4ax.com>
In reply to#2227
On Mon, 5 Nov 2012 04:00:35 -0800 (PST), Bob <bherbst65@hotmail.com>
wrote, quoted or indirectly quoted someone who said :

>I would want to know what to code it so 
>that it appears in the JTextArea.

see http://mindprod.com/jgloss/jtextarea.html
for sample code.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
Ironically, even though the Internet was created by the US military 
[DARPA (Defense Advanced Research Projects Agency)]
to withstand a nuclear attack, it is almost defenceless against malice
from any of its users

[toc] | [prev] | [next] | [standalone]


#2231

FromBob <bherbst65@hotmail.com>
Date2012-11-07 05:00 -0800
Message-ID<517b1215-fb33-4845-a17d-9ca1813cbcb0@googlegroups.com>
In reply to#2227
On Monday, November 5, 2012 7:00:36 AM UTC-5, Bob wrote:
> Hi All, 
> 
> The shuffle output is now 
> 
> System.out.println(dummy+input); 
> 
> I would want to know what to code it so 
> 
> that it appears in the JTextArea.
> 
> (code snip)
> 
> 
> 
>    public void actionPerformed(ActionEvent e) {
> 
>       String text = wordField.getText() ;
> 
> 
> 
>       if (e.getActionCommand().equals("GrabItAll")) {
> 
>          shuffle("",text);
> 
>       }else if (e.getActionCommand().equals("close")) {System.exit(0);}
> 
>    }
> 
>    
> 
>    public static void shuffle(String dummy, String input){
> 
>       JTextArea wordArea = new JTextArea(15, 20);
> 
>       
> 
>       if(input.length() <= 1) 
> 
>         System.out.println(dummy+input); 
> 
>       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()));
> 
>          }   
> 
>       }
> 
>    } 
> 
> 
> 
> TIA
> 
> Bob

Hi All,  
My program is completed.
Thanks to all who helped out. 
Bob

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.help


csiph-web