diff --git a/cs623/proj1/Makefile b/cs623/proj1/Makefile index 1ce1411..5c79e8f 100644 --- a/cs623/proj1/Makefile +++ b/cs623/proj1/Makefile @@ -1,11 +1,14 @@ MAINCLASS := RetirementCalculator +CLASSES := $(patsubst %.java,%.class,$(wildcard *.java)) -all: - javac *.java +all: $(CLASSES) + +%.class: %.java + javac $^ .PHONY: run -run: +run: $(CLASSES) java $(MAINCLASS) clean: diff --git a/cs623/proj1/RetirementCalculator.java b/cs623/proj1/RetirementCalculator.java index 2bea63b..45ba165 100644 --- a/cs623/proj1/RetirementCalculator.java +++ b/cs623/proj1/RetirementCalculator.java @@ -13,34 +13,98 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener { private RetirementCalculatorModel myModel; - private HashMap myFields; - - public class Field extends JTextField - { - private String myName; - - public Field(String name, String dflt) - { - super(dflt); - myName = name; - } - - public String getName() { return myName; } - } - - public void addField(JPanel addto, String caption, String name, String dflt) - { - addto.add(new JLabel(caption)); - Field field = new Field(name, dflt); - myFields.put(name, field); - addto.add(field); - } - public RetirementCalculatorPanel() { - JPanel inner = new JPanel(new GridLayout(3, 2)); - inner.add(new JLabel("How much annual income will you want in retirement?")); - inner.add(new JTextField()); + super(new BorderLayout()); + JPanel inner = new JPanel(new GridBagLayout()); +// inner.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); + JComponent field; + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.ipadx = 2; + c.gridwidth = 1; + c.gridheight = 1; + c.gridx = 0; + c.gridy = 0; + + c.weightx = 0.0; + inner.add(new JLabel("How much annual income will you want in retirement?", SwingConstants.RIGHT), c); + c.gridx++; + c.weightx = 1.0; + field = new JTextField(); + field.setMinimumSize(new Dimension(1, 1)); + inner.add(field, c); + c.gridx--; + c.gridy++; + + c.weightx = 0.0; + inner.add(new JLabel("What is your current annual income?", SwingConstants.RIGHT), c); + c.gridx++; + c.weightx = 1.0; + field = new JTextField(); + inner.add(field, c); + c.gridx--; + c.gridy++; + + c.gridwidth = 2; + inner.add(new JLabel("What is your expected annual income after retirement -"), c); + c.gridwidth = 1; + c.gridy++; + + c.weightx = 0.0; + inner.add(new JLabel(" - from an employer pension plan?", SwingConstants.RIGHT), c); + c.gridx++; + c.weightx = 1.0; + field = new JTextField(); + inner.add(field, c); + c.gridx--; + c.gridy++; + + c.weightx = 0.0; + inner.add(new JLabel(" - from a part-time job?", SwingConstants.RIGHT), c); + c.gridx++; + c.weightx = 1.0; + field = new JTextField(); + inner.add(field, c); + c.gridx--; + c.gridy++; + + c.weightx = 0.0; + inner.add(new JLabel(" - other?", SwingConstants.RIGHT), c); + c.gridx++; + c.weightx = 1.0; + field = new JTextField(); + inner.add(field, c); + c.gridx--; + c.gridy++; + + c.weightx = 0.0; + inner.add(new JLabel("At what age do you expect to retire?", SwingConstants.RIGHT), c); + c.gridx++; + c.weightx = 1.0; + field = new JSpinner(new SpinnerNumberModel(65, 0, 150, 1)); + inner.add(field, c); + c.gridx--; + c.gridy++; + + JPanel p = new JPanel(new BorderLayout()); + p.setAlignmentX(Component.RIGHT_ALIGNMENT); + p.add(new JLabel("What is your life expectancy?", SwingConstants.RIGHT), BorderLayout.CENTER); + String[] choices = { + "82 (Male; 50th percentile)", + "86 (Female; 50th percentile)", + "89 (Male; 75th percentile)", + "92 (Female; 75th percentile)", + "94 (Male; 90th percentile)", + "97 (Female; 90th percentile)" + }; + field = new JComboBox(choices); + p.add(field, BorderLayout.EAST); + c.gridwidth = 2; + inner.add(p, c); + c.gridwidth = 1; + c.gridy++; + JScrollPane scrollpane = new JScrollPane(inner, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); @@ -49,6 +113,9 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener public void actionPerformed(ActionEvent e) { + System.out.println("Event:"); + System.out.println(e.getActionCommand()); + System.out.println(e.paramString()); } }