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 BudgetPro351(to be put into net/multitool/gui) and the package statement <strong>on</strong> line 1 ofBudgetPro.java:1 package net.multitool.gui;16.7.1.1 Instance VariablesTake a look at the picture of the BudgetPro GUI. Count the GUI objects thatwe need: four butt<strong>on</strong>s, three labels, and let’s not forget the (empty at first) tableof subaccounts. These are declared in lines 23–31. (Ignore lines 22 and 32for now, we’ll cover them later. Line 34 declares our dialog—more <strong>on</strong> thatlater, too.)21 // gui comp<strong>on</strong>ents22 private JFrame frame; // needed by dialogs to root themselves23 private JLabel nam;24 private JLabel tot;25 private JLabel val;26 private JButt<strong>on</strong> upt<strong>on</strong> = new JButt<strong>on</strong>(new ImageIc<strong>on</strong>("net/multitool/gui/back.gif"));27 private JButt<strong>on</strong> creat = new JButt<strong>on</strong>("new subaccount");28 private JButt<strong>on</strong> view = new JButt<strong>on</strong>("view subaccount");29 private JButt<strong>on</strong> clos = new JButt<strong>on</strong>("quit");3031 private JTable list;32 private AbstractTableModel model;3334 private AcctDialog askem; // make <strong>on</strong>ce, use often16.7.1.2 MainSkip all the way to the last method of the class, line 289 and following. It’s themain() which gets run when we run this class. If we focus <strong>on</strong> the major pieceinvolved in getting our GUI together, it’s these lines:JFrame frame = new JFrame("BudgetPro");frame.getC<strong>on</strong>tentPane().add(status, ...);frame.getC<strong>on</strong>tentPane().add(list, ...);frame.getC<strong>on</strong>tentPane().add(butt<strong>on</strong>s, ...);We’re leaving out lots of intermediate text to emphasize the “real” work.We create a JFrame, the outermost window object. We add into it all the other

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

Saved successfully!

Ooh no, something went wrong!