Hello,
me again :-). This time I need to build a small calculator-like GUI, like this:
This time I thought I'd ask a few questions before I start building it!
1)In terms of layout, I was thinking to use the GridLayout again: one for the text field and one for the buttons. Now, do I need a to include a FlowLayout as well or can I leave it out?
2)the buttons: it seems to me to be a bit tedious to add 16 different JButton variables, each of them for a different button as required. So, would it be doable to have an array of buttons and insert them in the panel with a loop perhaps? The only thing is, how would I assign the correct labels to the button if I add them in a loop?!
thanks
Violet_82 89 Posting Whiz in Training
Recommended Answers
Jump to PostYes, and I would place the buttons as a GridLayout inside a JPanel, so the JFrame has a text field and a JPanel, one above the other.
A loop to create the buttons is a good idea. There's no need to have an array of buttons - once created and …
Jump to Postwhether it is desirable or not, is for you to decide (or your client/professor/employer)
Jump to Postor just making sure it can't be resized.
Jump to Postwhich is actually what I was talking about :)
resizing it might make your layout manager(s) to fill up the newly added "free space", which setting your JFrame to non-resizable should be able to deal with.
Jump to Postif you set it on the main JFrame, indeed you can't. it's (as far as I've known) the only guaranteed way to keep your components in the location/order you designed them to be when using layoutmanagers, but then again I haven't used Swing that much, might be my knowledge here …
All 18 Replies
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Violet_82 89 Posting Whiz in Training
Violet_82 89 Posting Whiz in Training
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Violet_82 89 Posting Whiz in Training
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Violet_82 89 Posting Whiz in Training
stultuske 1,116 Posting Maven Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
stultuske 1,116 Posting Maven Featured Poster
Violet_82 89 Posting Whiz in Training
stultuske 1,116 Posting Maven Featured Poster
Violet_82 89 Posting Whiz in Training
stultuske 1,116 Posting Maven Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Violet_82 89 Posting Whiz in Training
faizlo 0 Newbie Poster
Violet_82 89 Posting Whiz in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.