Forums Register Login

Swing noob looking to create a simple calculator interface

+Pie Number of slices to send: Send
Hi

This is a simple guitar fret calculator I want to create. I have the program logic working fine and am now trying to make it into a swing interface.

All i need for now is for it to have 2 user input boxes (scale length & number of frets). And then to print the result into another box (bigger box though has to fit about 25 lines)

I am a complete swing noob and have got to the stage where I have 3 boxes but how do go about using the input from the first 2 boxes to print to the 3rd box?

Any help would be great
+Pie Number of slices to send: Send
What have you done so far with the UI design?
+Pie Number of slices to send: Send
So far its just 3 boxes, first 2 accept data but are doing nothing with it

I need to be able to input data (an int) into the first 2 boxes and somehow submit that data so that it can be used in my program logic (or formula) ?? .. and then print the result in the 3rd box..

is this possible ?
+Pie Number of slices to send: Send
Why not. Easiest approach might be to use a button. On button click even you can do the calculation. Another approach would be to use key listeners on input fields, for. e.g when the enter key is pressed do the calculation.
+Pie Number of slices to send: Send
Disagree with you.

I think the first thing to do is get the calculator working without an interface. Run it from the command line. Then consider a GUI later.
+Pie Number of slices to send: Send
Hoping someone can point me in the right direction with this..

Main problem I am getting:

That only the last line of the loop is displayed in the fretScale TextArea. Also i have commented out line 68 just to get the program running but this line is giving a compiler error. Is there an easier was to store the input values to use in this way?



Any questions please ask

+Pie Number of slices to send: Send
This is what I noticed

I have the program logic working fine and am now trying to make it into a swing interface.



So I got I feeling that it must be already running through command line interface.
+Pie Number of slices to send: Send
Probably. I missed that bit, sorry.
+Pie Number of slices to send: Send
It seems that to you need multiple rows to display the output. So JTable might be an option, or may be JTextArea with line break. However JTable would give it a better look.
+Pie Number of slices to send: Send
 

Campbell Ritchie wrote:Disagree with you.

I think the first thing to do is get the calculator working without an interface. Run it from the command line. Then consider a GUI later.



Oh ya I had it working fine .. using Scanner to accept input
+Pie Number of slices to send: Send
 

Swastik Dey wrote:It seems that to you need multiple rows to display the output. So JTable might be an option, or may be JTextArea with line break. However JTable would give it a better look.



Will try JTable

Thanks

edit; i did try JTextArea and then with a line break in the for loop, but this did not help, still only the last iteration (interation 22) was printed. It must be something to do with the JTextArea as when i run a System.out.println in the for loop it prints 22 iterations in the console
+Pie Number of slices to send: Send
You might have used jtextArea.setText, right? So in this case it will always overwrite the previous value. You have to first retrieve the previous value and then call setText again.

Some what like

+Pie Number of slices to send: Send
No i didnt use jTextArea.setText at all .. should I have?
+Pie Number of slices to send: Send
Then how are you displaying text in JTextArea?
+Pie Number of slices to send: Send
Line 66

fretScale.setText("Fret " + i + ": Distance from nut(mm): " + (650 - z) + "mm");



so - yes you are using setText()

but

You have to first retrieve the previous value and then call setText again.

isn't necessary either. JTextArea has method. Use that on Line 66. You can (likely will want) new lines appended each time it loops.


http://docs.oracle.com/javase/7/docs/api/javax/swing/JTextArea.html
+Pie Number of slices to send: Send
Take a look this project. Its not finished calc I made while learning basics of java and swing. Its Eclipse project so just import into your ide and feel free to tweaking. calcsimple
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1027 times.
Similar Threads
Need design help for calculator using AWT only?
Forwarding data changes in MVC
Beginner with GUIs
How to organize a Swing project
Newbie needs help
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:25:38.