Loading...
Logo
Processing Forum
I modified this code from one of the G4P examples:
Copy code
  1. public void txf1_change1(GTextField tc, GEvent event) { //_CODE_:textfield2:640996:
      switch(event) {
  2.   case ENTERED:
        sentense=tc.getText();
        System.out.println(sentense);
        sentense="";
        tc.setText("");
        break;
      default:
        break;
      }
    }
 
This works great within my code where I have a text field and want its string contents printed every time I hit the enter key.
 
Since I am only checking for one thing I thought the case/switch approach was not needed so I tried
Copy code
  1. if (event == ENTERED){
  2.     sentense=tc.getText();
        System.out.println(sentense);
        sentense="";
        tc.setText("");
  3. }
 
but it wouldn't understand ENTERED...  Not sure why it can get it in CASE but not in IF?????

Replies(2)

There is a difference between switch and if statements which I won't go into but the solution is

Copy code
  1. if (event == GEvent.ENTERED){
  2.     sentense=tc.getText();
  3.     System.out.println(sentense);
  4.     sentense="";
  5.     tc.setText("");
  6. }
Awesome thanks!!