fixed a few null pointer exceptions

git-svn-id: svn://anubis/gvsu@441 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2009-10-05 00:56:57 +00:00
parent 822355183a
commit 80e706e224
2 changed files with 42 additions and 9 deletions

View File

@ -19,11 +19,13 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener
private JButton myCalculateButton;
private JButton myPrintButton;
private JButton myResetButton;
private JLabel myResultBox;
public RetirementCalculatorPanel()
{
super(new BorderLayout());
myModel = new RetirementCalculatorModel();
myFields = new HashMap<String, JComponent>();
JPanel inner = new JPanel(new GridBagLayout());
class ComboChoice
@ -67,7 +69,8 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener
c.gridy++;
c.weightx = 0.0;
inner.add(new JLabel("What is your current annual income?", SwingConstants.RIGHT), c);
inner.add(new JLabel("What is your current annual income?",
SwingConstants.RIGHT), c);
c.gridx++;
c.weightx = 1.0;
field = new JTextField();
@ -84,7 +87,8 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener
c.gridy++;
c.weightx = 0.0;
inner.add(new JLabel(" - from an employer pension plan?", SwingConstants.RIGHT), c);
inner.add(new JLabel(" - from an employer pension plan?",
SwingConstants.RIGHT), c);
c.gridx++;
c.weightx = 1.0;
field = new JTextField();
@ -94,7 +98,8 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener
c.gridy++;
c.weightx = 0.0;
inner.add(new JLabel(" - from a part-time job?", SwingConstants.RIGHT), c);
inner.add(new JLabel(" - from a part-time job?",
SwingConstants.RIGHT), c);
c.gridx++;
c.weightx = 1.0;
field = new JTextField();
@ -119,7 +124,8 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener
c.gridy++;
c.weightx = 0.0;
inner.add(new JLabel("How much savings do you have to date?", SwingConstants.RIGHT), c);
inner.add(new JLabel("How much savings do you have to date?",
SwingConstants.RIGHT), c);
c.gridx++;
c.weightx = 1.0;
field = new JTextField();
@ -129,7 +135,8 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener
c.gridy++;
c.weightx = 0.0;
inner.add(new JLabel("At what age do you expect to retire?", SwingConstants.RIGHT), c);
inner.add(new JLabel("At what age do you expect to retire?",
SwingConstants.RIGHT), c);
c.gridx++;
c.weightx = 1.0;
ComboChoice[] retirement_age_choices = {
@ -146,7 +153,8 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener
JPanel p = new JPanel(new BorderLayout());
p.setAlignmentX(Component.RIGHT_ALIGNMENT);
p.add(new JLabel("What is your life expectancy?", SwingConstants.RIGHT), BorderLayout.CENTER);
p.add(new JLabel("What is your life expectancy?",
SwingConstants.RIGHT), BorderLayout.CENTER);
ComboChoice[] life_expectancy_choices = {
new ComboChoice(82, "82 (Male; 50th percentile)"),
new ComboChoice(86, "86 (Female; 50th percentile)"),
@ -188,6 +196,12 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener
c.gridwidth = 1;
c.gridy++;
c.gridwidth = 2;
myResultBox = new JLabel(" ");
inner.add(myResultBox, c);
c.gridwidth = 1;
c.gridy++;
JScrollPane scrollpane = new JScrollPane(inner,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
@ -196,9 +210,27 @@ 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());
if (e.getSource() == myCalculateButton)
calculate();
else if (e.getSource() == myResetButton)
reset();
else if (e.getSource() == myPrintButton)
print();
}
private void calculate()
{
myModel.calculate();
}
private void reset()
{
myModel.reset();
}
private void print()
{
calculate();
}
}

View File

@ -8,6 +8,7 @@ public class RetirementCalculatorModel
public RetirementCalculatorModel()
{
myFields = new HashMap<String, Double>();
reset();
}