Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

StringTokenizer/TextField  RSS feed

 
Stephen Donovn
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again

In the code below I'm trying to achieve a user entering a time in hours/mins/seconds and then using string tokenizer to get the first value before the ':' and displaying that in my output textfield.

I've said it before but only 5 weeks into my course and have no programming experience so finding things a little tough but despite endless reading can't figure it out.

I understand tokenizer is not the thing to do now (split better???) but have to use that for a forthcoming assignment so would like to find a solution.

Any help appreciated.

Thanks

Steve

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't actually said what the problem is. TellTheDetails.
 
Rob Camick
Ranch Hand
Posts: 2754
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't mix AWT and Swing components.

You are using a JFrame which is Swing, there all you other components should be Swing as well (JTextField, JLabel).


You defined a variable named "input" to be a (J)TextField, so you don't want to define another variable by the same name. To access the text in the text field you would do something like:

 
Campbell Ritchie
Sheriff
Posts: 53769
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using StringTokenizer(←link)? If you read the link you find it is considered legacy code.
 
Stephen Donovn
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply - that helped point me in the right direction of what to read up on and worked out the solution and all working.

Thanks again

Code I used to fix the issue (note I changed the name of my textfields from original values of 'input' to 'hour' and 'output' to 'hoursare'.

 
Stephen Donovn
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The assignment I have coming up says to use Stringtokenizer, so wanted to understand it better.

It's working which is main thing for me at the moment. Will research other methods in place of.

Thanks

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!