By now, we've established two basic propositions:
1) Panels are containers for holding other components
2) there are layouts besides the old "flow" layout
So let's explore these ideas a little longer. Another type of layout is called the "border": you have the four points of the compass -- north south east west -- as well as a region called the center. Let's add a second Panel to our frame, give it a border layout, then add some buttons to that panel to see what a border layout looks like
Here's how you do it:
A) declare a second Panel -- just copy it the way you already did it, and give it a different name
B) declare some buttons, like so:
Button uno, dos, tres, quattro;
C) just below the line that dded the first Panel to the frame:
onePanel.add(myFirstPanel); //add panel to frame
Add a second Panel, pretty much the same way you added the first one, only DONT use a grid layout, use a border layout, like so:
panelTwo.setLayout(new BorderLayout());
assuming that you named your Panel "panelTwo"; if you called it something else, then use YOUR name, m'OK?
D) add the first button to the "north" part of your border, like so:
uno = new Button("one"); panelTwo.add("North", uno);
and add one of the other buttons to the south border in a similar fashion; c'mon, its not THAT hard!
re-compile, and see what you get. If it works, then add buttons to the other parts of your border layout.
Cheers,
Uncle Paulie
Thursday, February 19, 2009
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment