How can i make it possible to write freely and save it in processing.

edited December 2017 in How To...

The thing that i would like is to make a program that would let me type anthing that i want, and then when I click on a button the text that i have written in the program will be saved into a txt file.

Answers

  • Answer ✓
    String str = "";
    
    void setup(){
      size(400,400);
    }
    
    void draw(){
      background(0);
      fill(255);
      text(str,20,20,width-40,height-40);
      fill(128);
      if( over() ){
        fill(196);
      }
      rect(width-20,height-20,20,20);
    }
    
    boolean over(){
      return( mouseX>width-20 && mouseY > height-20 );
    }
    
    void keyPressed(){
      if( keyCode == DELETE || keyCode == BACKSPACE ){
        if( str.length() > 0 ){
          str = str.substring(0, str.length()-1);
        }
      } else {
        if( key != CODED ){
          str += key;
        }
      }
    }
    
    void mousePressed(){
      if( over() ){
        saveIt();
      }
    }
    
    void saveIt(){
      String[] strs = { str };
      saveStrings( "text.txt", strs );
    }
    
  • Thanks man, is it possible to trouble you more ?

  • Anyone can help you; this is a public forum.

    You might try posting what it is you want to accomplish. Mention any requirements. Show what you have tried. Tell us what works. Point out what doesn't. Include your code. Be sure to format it properly.

  • Yeah, others will answer too

  • Hi, could you help me?

    is that I want to write and save in a text file, but in a line I specify and save again, always using the same text file.

  • Do you have many lines or one?

  • they are several lines

  • Continued elsewhere

    Close this one

This discussion has been closed.