introduced ComboChoice utility class

git-svn-id: svn://anubis/gvsu@438 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2009-10-04 21:15:15 +00:00
parent 5efa416c43
commit 9f5cc1a9ef

View File

@ -20,6 +20,18 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener
super(new BorderLayout());
JPanel inner = new JPanel(new GridBagLayout());
// inner.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
class ComboChoice
{
private String myDesc;
private int myVal;
ComboChoice(int val, String desc)
{
myDesc = desc;
myVal = val;
}
public String toString() { return myDesc; }
public int getVal() { return myVal; }
}
JComponent field;
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
@ -91,7 +103,12 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener
inner.add(new JLabel("At what age do you expect to retire?", SwingConstants.RIGHT), c);
c.gridx++;
c.weightx = 1.0;
Integer[] retirement_age_choices = { 55, 60, 65, 70 };
ComboChoice[] retirement_age_choices = {
new ComboChoice(55, "55"),
new ComboChoice(60, "60"),
new ComboChoice(65, "65"),
new ComboChoice(70, "70")
};
field = new JComboBox(retirement_age_choices);
inner.add(field, c);
c.gridx--;
@ -100,15 +117,15 @@ 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);
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)"
ComboChoice[] life_expectancy_choices = {
new ComboChoice(82, "82 (Male; 50th percentile)"),
new ComboChoice(86, "86 (Female; 50th percentile)"),
new ComboChoice(89, "89 (Male; 75th percentile)"),
new ComboChoice(92, "92 (Female; 75th percentile)"),
new ComboChoice(94, "94 (Male; 90th percentile)"),
new ComboChoice(97, "97 (Female; 90th percentile)")
};
field = new JComboBox(choices);
field = new JComboBox(life_expectancy_choices);
p.add(field, BorderLayout.EAST);
c.gridwidth = 2;
inner.add(p, c);