13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

16.7 Getting Down to Cases: Designing a GUI for BudgetPro353With a BorderLayout, if you put something in the NORTH secti<strong>on</strong>, it willappear across the top area of that c<strong>on</strong>tainer. If you resize the c<strong>on</strong>tainer (e.g.,drag the window edges), it will take extra space and use it for horiz<strong>on</strong>tal, butnot vertical, stretching. That is, the objects w<strong>on</strong>’t get bigger than they need tovertically, though they will stretch wider. The same is true for SOUTH, but theobjects are at the bottom rather than top of the c<strong>on</strong>tainer. Putting somethingin EAST or WEST will move them to the left or right of the c<strong>on</strong>tainer. For thesetwo areas, though, space when resizing a window is added to the objects vertically,but not horiz<strong>on</strong>tally. Putting an object in EAST or WEST will let it gettaller, but not wider.The CENTER area, the default locati<strong>on</strong> if you use the add() method withno sec<strong>on</strong>d parameter, will use extra space both vertically and horiz<strong>on</strong>tally.Adding more than <strong>on</strong>e object into a regi<strong>on</strong> (e.g., NORTH) will result in <strong>on</strong>lythe last item added being displayed. For this reas<strong>on</strong>, too, <strong>on</strong>e often builds intermediatec<strong>on</strong>tainers to hold several objects. Then the single c<strong>on</strong>tainer object isadded to <strong>on</strong>e of BorderLayout’s regi<strong>on</strong>s.16.7.2.1 Simple JLabelsLet’s look at the simplest of the three pieces that we create for our GUI—thetop line of informati<strong>on</strong> indicating the status of the account. In lines 88–107we create this porti<strong>on</strong> of the GUI.88 private Comp<strong>on</strong>ent89 createStatus()90 {91 JPanel retval = new JPanel(); // default: flow layout9293 upt<strong>on</strong>.addActi<strong>on</strong>Listener(upActi<strong>on</strong>);9495 nam = new JLabel("Account: Name");96 tot = new JLabel("Total: $");97 val = new JLabel("Remaining: $");9899 retval.add(upt<strong>on</strong>);100 retval.add(nam);101 retval.add(tot);102 retval.add(val);103104 setStatus();105106 return retval;107 } // createStatus

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!