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 PostEach container (JFrame, JPanel etc) has its own layout manager, so eg you could have a flowlayout for the frame, add a panel to that, and have a grid layout for the panel. You can't have 2 layout managers for the same container.
In this case, there's no need a …
Jump to PostExcellent!
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 Postwhether it is desirable or not, is for you to decide (or your client/professor/employer)
Jump to PostIt 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 …
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.