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.

Appendix BA Java Swing GUI for BudgetPro5352425 // right justify the numeric field26 amntField.setHoriz<strong>on</strong>talAlignment(JTextField.RIGHT);2728 // TODO: so that will do a create29 // this.getInputMap().put(KeyStroke.getKeyStroke("Enter"), "create");30 /*31 Acti<strong>on</strong> myActi<strong>on</strong> = new AbstractActi<strong>on</strong>("doSomething") {32 public void acti<strong>on</strong>Performed() {33 doSomething();34 }35 };36 myComp<strong>on</strong>ent.getActi<strong>on</strong>Map().put(myActi<strong>on</strong>.get(Acti<strong>on</strong>.NAME), myActi<strong>on</strong>);37 */3839 //--------------------------------------------------Label <strong>on</strong> top----40 JLabel label = new JLabel(""41 + "Enter the info to create a subaccount."42 + "");43 label.setHoriz<strong>on</strong>talAlignment(JLabel.LEFT);44 F<strong>on</strong>t f<strong>on</strong>t = label.getF<strong>on</strong>t();45 label.setF<strong>on</strong>t(label.getF<strong>on</strong>t().deriveF<strong>on</strong>t(f<strong>on</strong>t.PLAIN, 14.0f));4647 //--------------------------------------------------Text Fields-----48 String[] labels = {"(Sub)Account Name: ", "Dollar Amount: "};49 JTextField [] fields = {nameField, amntField};50 int numPairs = fields.length;5152 //Create and populate the panel.53 JPanel textes = new JPanel(new SpringLayout());54 for (int i = 0; i < numPairs; i++) {55 JLabel l = new JLabel(labels[i], JLabel.TRAILING);56 textes.add(l);57 l.setLabelFor(fields[i]); // not nec. since we have no kb shortcuts58 textes.add(fields[i]);59 }6061 //Lay out the panel.62 SpringUtilities.makeCompactGrid(textes,63 numPairs, 2, //rows, cols64 6, 6, //initX, initY65 6, 6); //xPad, yPad666768 //--------------------------------------------------Butt<strong>on</strong>s <strong>on</strong> bottom69 JButt<strong>on</strong> createButt<strong>on</strong> = new JButt<strong>on</strong>("Create");70 createButt<strong>on</strong>.addActi<strong>on</strong>Listener(new Acti<strong>on</strong>Listener() {71 public void acti<strong>on</strong>Performed(Acti<strong>on</strong>Event e) {72 nameField.grabFocus(); // before leaving, ready for next time.

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

Saved successfully!

Ooh no, something went wrong!