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 Post— JamesCherrill 4,733Yes, 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 Post— JamesCherrill 4,733Excellent!
One small point - always set the layout manager before adding anything to a container as the parameters on the add method are interpreted diferently by different layout managers and results may be unpredictable.ps Have you tried re-sizing your window with the mouse?
Jump to Post— stultuske 1,129whether it is desirable or not, is for you to decide (or your client/professor/employer)
Jump to Post— JamesCherrill 4,733It should respect the minimum size you specified, but you may have less luck trying to set a max size. One thing can do is add a listener for the frame being re-sized and forcing it back when it goes out of the "desirable" range. (Probably not worth worrying about ā¦
Jump to Post— stultuske 1,129or just making sure it can't be resized.
All 20 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,129 Posting Maven Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
stultuske 1,129 Posting Maven Featured Poster
Violet_82 89 Posting Whiz in Training
stultuske 1,129 Posting Maven Featured Poster
Violet_82 89 Posting Whiz in Training
stultuske 1,129 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
Anderson Will -8 Newbie Poster
rproffitt commented: 12 years later. Did you add value here? Or just zombie posting? +0
Prime Name -4 Newbie Poster
rproffitt commented: 12 years later. Did you add value here? Or just zombie posting? -4
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.
