adding some padding around components, placed a "$" before dollar fields, added tooltips (need a little work yet)
git-svn-id: svn://anubis/gvsu@462 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
be378d3719
commit
2882459499
@ -18,10 +18,12 @@ class RetirementCalculatorPanel
|
|||||||
private JComponent makeDivider() { return new JLabel(" "); }
|
private JComponent makeDivider() { return new JLabel(" "); }
|
||||||
|
|
||||||
private HashMap<String, JComponent> myFields;
|
private HashMap<String, JComponent> myFields;
|
||||||
|
private HashMap<JComponent, String> myToolTips;
|
||||||
private JButton myCalculateButton;
|
private JButton myCalculateButton;
|
||||||
private JButton myPrintButton;
|
private JButton myPrintButton;
|
||||||
private JButton myResetButton;
|
private JButton myResetButton;
|
||||||
private JLabel myResultBox;
|
private JLabel myResultBox;
|
||||||
|
private JLabel myToolTipBox;
|
||||||
private JTextField myNameField;
|
private JTextField myNameField;
|
||||||
|
|
||||||
class ComboChoice
|
class ComboChoice
|
||||||
@ -53,14 +55,9 @@ class RetirementCalculatorPanel
|
|||||||
new ComboChoice(97, "97 (Female; 90th percentile)")
|
new ComboChoice(97, "97 (Female; 90th percentile)")
|
||||||
};
|
};
|
||||||
|
|
||||||
public RetirementCalculatorPanel()
|
private static int row = 0;
|
||||||
|
private void addRow(JPanel panel, JComponent c1, JComponent c2)
|
||||||
{
|
{
|
||||||
super(new BorderLayout());
|
|
||||||
|
|
||||||
myModel = new RetirementCalculatorModel();
|
|
||||||
myFields = new HashMap<String, JComponent>();
|
|
||||||
JPanel inner = new JPanel(new GridBagLayout());
|
|
||||||
JComponent field;
|
|
||||||
GridBagConstraints c = new GridBagConstraints();
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
c.fill = GridBagConstraints.HORIZONTAL;
|
c.fill = GridBagConstraints.HORIZONTAL;
|
||||||
c.insets = new Insets(0, 4, 0, 4);
|
c.insets = new Insets(0, 4, 0, 4);
|
||||||
@ -68,143 +65,143 @@ class RetirementCalculatorPanel
|
|||||||
c.gridwidth = 1;
|
c.gridwidth = 1;
|
||||||
c.gridheight = 1;
|
c.gridheight = 1;
|
||||||
c.gridx = 0;
|
c.gridx = 0;
|
||||||
c.gridy = 0;
|
|
||||||
|
|
||||||
c.weightx = 0.0;
|
c.weightx = 0.0;
|
||||||
inner.add(new JLabel("What is your name?", SwingConstants.RIGHT), c);
|
c.gridy = row;
|
||||||
|
panel.add(c1, c);
|
||||||
|
|
||||||
c.gridx++;
|
c.gridx++;
|
||||||
c.weightx = 1.0;
|
c.weightx = 1.0;
|
||||||
|
panel.add(c2, c);
|
||||||
|
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
private void addDollarRow(JPanel panel, JComponent c1, JComponent c2)
|
||||||
|
{
|
||||||
|
JPanel dollar_panel = new JPanel();
|
||||||
|
dollar_panel.setLayout(new BoxLayout(dollar_panel, BoxLayout.X_AXIS));
|
||||||
|
dollar_panel.add(new JLabel("$"));
|
||||||
|
dollar_panel.add(c2);
|
||||||
|
addRow(panel, c1, dollar_panel);
|
||||||
|
}
|
||||||
|
private void addRow(JPanel panel, JComponent c1)
|
||||||
|
{
|
||||||
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
|
c.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
c.insets = new Insets(0, 4, 0, 4);
|
||||||
|
c.ipadx = 2;
|
||||||
|
c.gridwidth = 2;
|
||||||
|
c.gridheight = 1;
|
||||||
|
c.gridx = 0;
|
||||||
|
c.weightx = 0.0;
|
||||||
|
c.gridy = row;
|
||||||
|
panel.add(c1, c);
|
||||||
|
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RetirementCalculatorPanel()
|
||||||
|
{
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
myModel = new RetirementCalculatorModel();
|
||||||
|
myFields = new HashMap<String, JComponent>();
|
||||||
|
myToolTips = new HashMap<JComponent, String>();
|
||||||
|
JPanel inner = new JPanel(new GridBagLayout());
|
||||||
|
myToolTipBox = new JLabel(" ", SwingConstants.CENTER);
|
||||||
|
JComponent field;
|
||||||
|
|
||||||
myNameField = new JTextField();
|
myNameField = new JTextField();
|
||||||
myNameField.addFocusListener(this);
|
myNameField.addFocusListener(this);
|
||||||
inner.add(myNameField, c);
|
myToolTips.put(myNameField, "Enter your name.");
|
||||||
c.gridx--;
|
myToolTipBox.setText("Enter your name.");
|
||||||
c.gridy++;
|
addRow(inner, new JLabel("What is your name?", SwingConstants.RIGHT),
|
||||||
|
myNameField);
|
||||||
|
|
||||||
c.weightx = 0.0;
|
|
||||||
inner.add(new JLabel("What is your age?", SwingConstants.RIGHT), c);
|
|
||||||
c.gridx++;
|
|
||||||
c.weightx = 1.0;
|
|
||||||
field = new JTextField();
|
field = new JTextField();
|
||||||
field.addFocusListener(this);
|
field.addFocusListener(this);
|
||||||
myFields.put("age", field);
|
myFields.put("age", field);
|
||||||
inner.add(field, c);
|
myToolTips.put(field, "Enter your current age.");
|
||||||
c.gridx--;
|
addRow(inner, new JLabel("What is your age?", SwingConstants.RIGHT),
|
||||||
c.gridy++;
|
field);
|
||||||
|
|
||||||
c.gridwidth = 2;
|
addRow(inner, makeDivider());
|
||||||
inner.add(makeDivider(), c);
|
|
||||||
c.gridwidth = 1;
|
|
||||||
c.gridy++;
|
|
||||||
|
|
||||||
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 = new JTextField();
|
||||||
field.addFocusListener(this);
|
field.addFocusListener(this);
|
||||||
myFields.put("income wanted", field);
|
myFields.put("income wanted", field);
|
||||||
inner.add(field, c);
|
myToolTips.put(field, "Enter the amount of income that you would like to receive in a year while you are retired.");
|
||||||
c.gridx--;
|
addDollarRow(inner,
|
||||||
c.gridy++;
|
new JLabel("How much annual income will you want in retirement?",
|
||||||
|
SwingConstants.RIGHT),
|
||||||
|
field);
|
||||||
|
|
||||||
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();
|
field = new JTextField();
|
||||||
field.addFocusListener(this);
|
field.addFocusListener(this);
|
||||||
myFields.put("current income", field);
|
myFields.put("current income", field);
|
||||||
inner.add(field, c);
|
myToolTips.put(field, "Enter the amount of income that you currently receive in a year.");
|
||||||
c.gridx--;
|
addDollarRow(inner,
|
||||||
c.gridy++;
|
new JLabel("What is your current annual income?",
|
||||||
|
SwingConstants.RIGHT),
|
||||||
|
field);
|
||||||
|
|
||||||
c.gridwidth = 2;
|
addRow(inner, makeDivider());
|
||||||
inner.add(makeDivider(), c);
|
|
||||||
c.gridy++;
|
addRow(inner,
|
||||||
inner.add(new JLabel("What is your expected annual income after retirement -"), c);
|
new JLabel("What is your expected annual income after retirement -"));
|
||||||
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();
|
field = new JTextField();
|
||||||
field.addFocusListener(this);
|
field.addFocusListener(this);
|
||||||
myFields.put("employer pension", field);
|
myFields.put("employer pension", field);
|
||||||
inner.add(field, c);
|
myToolTips.put(field, "If your employer has a pension plan that will pay you a certain amount after you retire from them, then enter that amount here.");
|
||||||
c.gridx--;
|
addDollarRow(inner,
|
||||||
c.gridy++;
|
new JLabel(" - from an employer pension plan?",
|
||||||
|
SwingConstants.RIGHT),
|
||||||
|
field);
|
||||||
|
|
||||||
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();
|
field = new JTextField();
|
||||||
field.addFocusListener(this);
|
field.addFocusListener(this);
|
||||||
myFields.put("part time income", field);
|
myFields.put("part time income", field);
|
||||||
inner.add(field, c);
|
myToolTips.put(field, "Enter how much income you expect to make working at a part-time job after retirement.");
|
||||||
c.gridx--;
|
addDollarRow(inner,
|
||||||
c.gridy++;
|
new JLabel(" - from a part-time job?", SwingConstants.RIGHT),
|
||||||
|
field);
|
||||||
|
|
||||||
c.weightx = 0.0;
|
|
||||||
inner.add(new JLabel(" - other?", SwingConstants.RIGHT), c);
|
|
||||||
c.gridx++;
|
|
||||||
c.weightx = 1.0;
|
|
||||||
field = new JTextField();
|
field = new JTextField();
|
||||||
field.addFocusListener(this);
|
field.addFocusListener(this);
|
||||||
myFields.put("other income", field);
|
myFields.put("other income", field);
|
||||||
inner.add(field, c);
|
myToolTips.put(field, "If there is any other annual income you expect to receive after retirement not already accounted for, enter the amount here.");
|
||||||
c.gridx--;
|
addDollarRow(inner, new JLabel(" - other?", SwingConstants.RIGHT), field);
|
||||||
c.gridy++;
|
|
||||||
|
|
||||||
c.gridwidth = 2;
|
addRow(inner, makeDivider());
|
||||||
inner.add(makeDivider(), c);
|
|
||||||
c.gridwidth = 1;
|
|
||||||
c.gridy++;
|
|
||||||
|
|
||||||
c.weightx = 0.0;
|
|
||||||
inner.add(new JLabel("How much savings do you have to date?",
|
|
||||||
SwingConstants.RIGHT), c);
|
|
||||||
c.gridx++;
|
|
||||||
c.weightx = 1.0;
|
|
||||||
field = new JTextField();
|
field = new JTextField();
|
||||||
field.addFocusListener(this);
|
field.addFocusListener(this);
|
||||||
myFields.put("savings", field);
|
myFields.put("savings", field);
|
||||||
inner.add(field, c);
|
myToolTips.put(field, "Enter the amount of money that you have saved right now.");
|
||||||
c.gridx--;
|
addDollarRow(inner,
|
||||||
c.gridy++;
|
new JLabel("How much savings do you have to date?",
|
||||||
|
SwingConstants.RIGHT),
|
||||||
|
field);
|
||||||
|
|
||||||
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 JComboBox(retirement_age_choices);
|
field = new JComboBox(retirement_age_choices);
|
||||||
|
field.addFocusListener(this);
|
||||||
myFields.put("retirement age", field);
|
myFields.put("retirement age", field);
|
||||||
inner.add(field, c);
|
myToolTips.put(field, "Select the age at which you are planning to reture.");
|
||||||
c.gridx--;
|
addRow(inner,
|
||||||
c.gridy++;
|
new JLabel("At what age do you expect to retire?",
|
||||||
|
SwingConstants.RIGHT),
|
||||||
|
field);
|
||||||
|
|
||||||
JPanel p = new JPanel(new BorderLayout());
|
|
||||||
p.setAlignmentX(Component.RIGHT_ALIGNMENT);
|
|
||||||
p.add(new JLabel("What is your life expectancy?",
|
|
||||||
SwingConstants.RIGHT), BorderLayout.CENTER);
|
|
||||||
field = new JComboBox(life_expectancy_choices);
|
field = new JComboBox(life_expectancy_choices);
|
||||||
|
field.addFocusListener(this);
|
||||||
myFields.put("life expectancy", field);
|
myFields.put("life expectancy", field);
|
||||||
p.add(field, BorderLayout.EAST);
|
myToolTips.put(field, "Select what you think your life expectancy is.");
|
||||||
c.gridwidth = 2;
|
addRow(inner,
|
||||||
inner.add(p, c);
|
new JLabel("What is your life expectancy?",
|
||||||
c.gridwidth = 1;
|
SwingConstants.RIGHT),
|
||||||
c.gridy++;
|
field);
|
||||||
|
|
||||||
c.gridwidth = 2;
|
addRow(inner, makeDivider());
|
||||||
inner.add(makeDivider(), c);
|
|
||||||
c.gridwidth = 1;
|
|
||||||
c.gridy++;
|
|
||||||
|
|
||||||
JPanel buttons = new JPanel();
|
JPanel buttons = new JPanel();
|
||||||
buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
|
buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
|
||||||
@ -221,21 +218,17 @@ class RetirementCalculatorPanel
|
|||||||
myResetButton.addActionListener(this);
|
myResetButton.addActionListener(this);
|
||||||
buttons.add(myResetButton);
|
buttons.add(myResetButton);
|
||||||
buttons.add(Box.createHorizontalGlue());
|
buttons.add(Box.createHorizontalGlue());
|
||||||
c.gridwidth = 2;
|
|
||||||
inner.add(buttons, c);
|
|
||||||
c.gridwidth = 1;
|
|
||||||
c.gridy++;
|
|
||||||
|
|
||||||
c.gridwidth = 2;
|
addRow(inner, makeDivider());
|
||||||
inner.add(makeDivider(), c);
|
|
||||||
c.gridwidth = 1;
|
addRow(inner, myToolTipBox);
|
||||||
c.gridy++;
|
|
||||||
|
addRow(inner, buttons);
|
||||||
|
|
||||||
|
addRow(inner, makeDivider());
|
||||||
|
|
||||||
c.gridwidth = 2;
|
|
||||||
myResultBox = new JLabel(" ", SwingConstants.CENTER);
|
myResultBox = new JLabel(" ", SwingConstants.CENTER);
|
||||||
inner.add(myResultBox, c);
|
addRow(inner, myResultBox);
|
||||||
c.gridwidth = 1;
|
|
||||||
c.gridy++;
|
|
||||||
|
|
||||||
JScrollPane scrollpane = new JScrollPane(inner,
|
JScrollPane scrollpane = new JScrollPane(inner,
|
||||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
|
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
|
||||||
@ -261,6 +254,11 @@ class RetirementCalculatorPanel
|
|||||||
{
|
{
|
||||||
((JTextField) e.getComponent()).selectAll();
|
((JTextField) e.getComponent()).selectAll();
|
||||||
}
|
}
|
||||||
|
String tooltip = myToolTips.get(e.getComponent());
|
||||||
|
if (tooltip != null)
|
||||||
|
{
|
||||||
|
myToolTipBox.setText(tooltip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void focusLost(FocusEvent e)
|
public void focusLost(FocusEvent e)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user