473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Java GUI, take input from JText class

11
Ok. So, I don't know which class from javax.swing to use for this. I think it's JTextField, but anyway...

I'm looking for a class that allows the user to type in, in this case, integer or double values, which I'll be able to take as a string, change to type I need, then perform operations with them.

Example: 3 text fields. Miles, Gallons, and MPG. If the user puts in info for Miles, and Gallons, I should be able to take the user input, do my operation, then display the result (value for MPG) in the MPG text box.

If it's the JTextField class, I don't know which methods to use for reading the input in the box or the method to display new text in the box after its initial construction.

If anyone can help, it would be greatly appreciated.
Oct 19 '06 #1
4 5730
Koji
11
Omg. I feel so stupid....

.getText() and .setText().... I couldn't find them in the API because they were inherited methods. Omg... Sorry guys, scratch that question. Hahaha.
Oct 19 '06 #2
r035198x
13,262 8TB
Ok. So, I don't know which class from javax.swing to use for this. I think it's JTextField, but anyway...

I'm looking for a class that allows the user to type in, in this case, integer or double values, which I'll be able to take as a string, change to type I need, then perform operations with them.

Example: 3 text fields. Miles, Gallons, and MPG. If the user puts in info for Miles, and Gallons, I should be able to take the user input, do my operation, then display the result (value for MPG) in the MPG text box.

If it's the JTextField class, I don't know which methods to use for reading the input in the box or the method to display new text in the box after its initial construction.

If anyone can help, it would be greatly appreciated.
For input, use JTextfield. To get the data from the textfield use field.getText()

For output do not use a textfield. You just want to display the data so use a JLabel. You can have its initial text to "" (nothing) then when your calculation is complete, use label.setText(result); where result is a string represantation of your result.
Oct 19 '06 #3
r035198x
13,262 8TB
Omg. I feel so stupid....

.getText() and .setText().... I couldn't find them in the API because they were inherited methods. Omg... Sorry guys, scratch that question. Hahaha.
Guess I was just a bit late then!
Oct 19 '06 #4
Koji
11
Thanks for replying though! Oh, and my homework requires that we display the answers in the TextField for the missing information, not in a JLabel. :D

Thanks for your delayed help, hehe.
Oct 19 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
6
by: Rhino | last post by:
I'm trying to debug a simple Java UDF written in the DB2General style within Eclipse. I'm getting a java.lang.UnsatisfiedLinkError when I execute the set() method in the UDF. I know that the...
6
by: aureao4 | last post by:
I'm new to Java and programming. I'm trying to code a payroll program and continue getting errors. The program worked last week, this week I have to add set, get and a class. I've written the class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.