This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

GetText in a string?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I've recently started playing around Java, just as a hobby but I came across a problem I don't know how to solve :-(.

I have a jFrame program where I need my button to generate a file (so far so good). This file needs to be text of a script I already made but in this script there are 2 parts that need to be set in the program (through jtextField). I put the JTextFields into the code so its easier to see what I mean but it will obviously generate a file with "jTextfield1.GetText();" rather than actually fetching the text and importing it:-D

 
Saloon Keeper
Posts: 6216
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question is not very clear but I'm guessing you want to turn
into
 
Carey Brown
Saloon Keeper
Posts: 6216
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to make your variable and method names more descriptive. "jTextField2" doesn't tell me what to expect in the text field. A better name would have been "timeToMeetTextField", or, as some prefer, just "timeToMeet".
 
Dave Machek
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your replies.

So basically I have a text field - jTextField1(Sleep) and jTextField2 (TimeToMeet). Into these text fields I input time and latency. I need the program to generate the script where only things that are different every time are the Time and Latency.

So the text (ahk) file should look like this:



The bolded parts are the ones that need to be generated within the script and are read from the textFields I have in the program. I am sorry if I am nto making myself clear enough.. If it's still unclear, let me know I will try to rephrase it. Cheers!
 
Carey Brown
Saloon Keeper
Posts: 6216
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Dave Machek
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Sleep and TimeToMeet in parentesis are just to explain what they do. They were just jTextField. I changed them now to TimeToMeetTextField and SleepTextFields as you suggested
 
Carey Brown
Saloon Keeper
Posts: 6216
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Machek wrote:The Sleep and TimeToMeet in parentesis are just to explain what they do. They were just jTextField. I changed them now to TimeToMeetTextField and SleepTextFields as you suggested

Close, but variable and method names need to begin with a lower case letter.
 
Dave Machek
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohhh, that's also good to know, thank you!

So the problem stays, when I run the program, the output is:



I need it to be:



Where as the green values from line 7 and 9 are taken from a text field where a user of the program (mostly me, hah) types them. If I try going with:



It gives me an error: Not a statement,
";" expected.
 
Dave Machek
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry, not nobleTime but timeToMeetTextField indeed
 
Carey Brown
Saloon Keeper
Posts: 6216
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Was missing concatenate operator (+), and shouldn't have had the extra (;).
 
Dave Machek
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried compiling that, returned with one error:

 
Carey Brown
Saloon Keeper
Posts: 6216
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the String concatenate operator (+), you end up with an expression (not a statement).
String s = CONSTANT + variable + CONSTANT;
 
Carey Brown
Saloon Keeper
Posts: 6216
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Machek wrote:I tried compiling that, returned with one error:


Post more of the code so that I can see the context.
 
Carey Brown
Saloon Keeper
Posts: 6216
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Machek wrote:I tried compiling that, returned with one error:


I'm guessing that you ended up deleting the (+) operator that follows this. I didn't mean to imply that you should remove that.
 
Dave Machek
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry it must be frustrating for you, the code will probably be super messy for you:

 
Carey Brown
Saloon Keeper
Posts: 6216
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Dave Machek
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much. Not only for making it work but also helping me understand
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!