Results 1 to 5 of 5
Thread: Checking textfield text
- 06-13-2012, 10:24 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Checking textfield text
For some reason i cant check if a textbox has text in it here is my current code but it wont work
Java Code:public void actionPerformed(ActionEvent e) { if (e.getSource() == button1) { String refined; if(input.getText().equals(""))//here is the problem it*** it wont work { refined = String.valueOf((int)Math.random()); } else { refined = input.getText(); } try { int output = (int) s1.getValue(); new Pong(output,refined); dispose(); }catch(Exception e1){} } } }
- 06-13-2012, 10:26 PM #2
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Re: Checking textfield text
the if statement never returns true even if there is no text in the field
-
Re: Checking textfield text
Have you placed in println statements that would test the code to make sure that your assumptions aren't incorrect?
For example:
etc...Java Code:public void actionPerformed(ActionEvent e) { System.out.println("1: inside of actionPerformed"); if (e.getSource() == button1) { System.out.println("2: source == button1"); System.out.println("3: input.getText() := \"" + input.getText() + "\""); String refined; // I'd test it input.getText().trim().isEmpty() if(input.getText().equals(""))//here is the problem it*** it wont work { System.out.println("4: input.getText() is empty"); refined = String.valueOf((int)Math.random()); System.out.println("5: refined := " + refined); } else { refined = input.getText(); } try { int output = (int) s1.getValue(); new Pong(output,refined); dispose(); }catch(Exception e1) { e.printStackTrace(); // *** don't leave this empty!!! } } } }Last edited by Fubarable; 06-13-2012 at 11:20 PM.
- 06-14-2012, 12:37 AM #4
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Re: Checking textfield text
ive checked in my pong class it wont work i even made a debugging program
-
Re: Checking textfield text
Similar Threads
-
Save text in Textfield to an array
By Norah in forum New To JavaReplies: 1Last Post: 06-12-2012, 05:00 PM -
Textfield not displaying correct text
By nksjolinder1 in forum AWT / SwingReplies: 6Last Post: 10-25-2011, 09:33 PM -
checking entered text in a text box?
By nickburris in forum New To JavaReplies: 2Last Post: 06-24-2011, 02:09 AM -
textfield - printstream - text file - to much text
By keneid in forum New To JavaReplies: 2Last Post: 06-14-2010, 10:18 AM -
accessing the text of textfield of one class in another
By vasavi.singh in forum Advanced JavaReplies: 3Last Post: 04-05-2009, 02:54 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks