saveString with button

edited April 2017 in Library Questions

Hello everyone, I want to save the text written in textArea,

import processing.video.*;
import g4p_controls.*;

import java.awt.Font;
GTextArea textArea;
String txtMain ="";






Capture cam;
GButton btnSave;

int n = 1;

void setup() {
  size(1024,768); 


  textArea = new GTextArea(this, 110, 670, 200, 100, G4P.SCROLLBARS_BOTH | G4P.SCROLLBARS_AUTOHIDE);
  textArea.setFont(new Font("", Font.PLAIN, 20));

    cam = new Capture(this,640,480);
    cam.start();
  }
}

void draw() {
  if (cam.available() == true) {
    cam.read();
  }
  image(cam,0,0,width,height); 
}


public void handleButtonEvents(GButton button, GEvent event) {
  if (button == btnSave) {


}

in reference there is the procedure:

String words = "apple bear cat dog"; String[] list = split(words, ' ');

saveStrings("nouns.txt", list);

I have difficulty understanding how to add in my code, can you help me by explaining?

Thank you!

Answers

  • what is the command to retrieve text from textArea ?

    textArea.getText()?

    if so, then:

    String words = textArea.getText(); 
    
    String[] list = split(words, ' ');
    
    saveStrings("nouns.txt", list);
    
  • Now I understood Chrisir, thank you!

    but for not having the divided text with the split?

  • Answer ✓

    but for not having the divided text with the split?

    In your case you might or not need split. Can you provide a sample text that you want to save?

    Looking at the documentation, you will need an array as the argument for the saveString function: https://processing.org/reference/saveStrings_.html

    You could do:

    String[] wordsArray = {textArea.getText()};  
    saveStrings("nouns.txt", wordsArray );
    

    Kf

  • alright your example, my text does not need to be divided,

    thank you!

Sign In or Register to comment.