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 BudgetPro367do here because it can’t be any other type of event—or we wouldn’t have beencalled. All we’re doing with it is checking to see if the user just selected or deselectedsomething. The <strong>on</strong>ly acti<strong>on</strong> we take is to enable or disable the viewbutt<strong>on</strong>.Deep inside the cdacti<strong>on</strong> object is a line that does the real acti<strong>on</strong> thatwe’re after with our selecti<strong>on</strong>. It says:61 int row = list.getSelectedRow();This shows that a JTable (list) has a method, getSelectedRow(), whichwill return the row number of the row that the user has selected (that is,clicked <strong>on</strong>). This is all part of the acti<strong>on</strong> listener (defined <strong>on</strong> lines 54–75 ofBudgetPro) for the View Subaccount butt<strong>on</strong>.54 private Acti<strong>on</strong>Listener cdActi<strong>on</strong> = new Acti<strong>on</strong>Listener()55 {56 public void57 acti<strong>on</strong>Performed(Acti<strong>on</strong>Event e)58 {59 // this is the acti<strong>on</strong> for VIEW subdirectory;60 // a "cd" into the subaccount.61 int row = list.getSelectedRow();62 // System.out.println("Row="+row); // DEBUG; TODO: REMOVE63 if (row > -1) { // <strong>on</strong>ly if a row was selected64 String subname = (String) model.getValueAt(row, 0);// name column65 Account next = current.getSub(subname);66 if (next != null) {67 current = next;68 // System.out.println("cd to:"+current.getName());69 setStatus();70 // notify the table, too71 model.fireTableDataChanged();72 } // TODO: else infodialog or Beep.73 }74 }75 } ;With the row number in hand, the acti<strong>on</strong>Performed() method canthen use the row number to look up the account name. Since the account nameis in the first column (numbered 0) of our table, we call getValueAt(row, 0)to get that name. Then we give the name to the current account to look up thesubaccount (line 65).

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

Saved successfully!

Ooh no, something went wrong!