FileDocCategorySizeDatePackage
InterestRateDialog.javaAPI DocExample2849Sun Dec 14 22:47:40 GMT 2003oreilly.hcj.datamodeling

InterestRateDialog

public class InterestRateDialog extends JDialog implements ActionListener
Demonstrates using constraints in a GUI.
author
Robert Simmons jr. (kraythe)
version
$Revision: 1.4 $

Fields Summary
private JButton
okBtn
Holds the ok button.
private JTextField
interestRateField
Holds the balance field.
Constructors Summary
private InterestRateDialog()
Creates a new ConstraintGUIDemo object.

		setModal(true);

		final Container contentPane = getContentPane();
		contentPane.setLayout(new GridLayout(3, 1));

		JLabel interestRateLabel =
			new JLabel("Enter an Interst Rate (Between "
			           + LiabilityAccount.INTEREST_RATE_CONSTRAINT.getMinValue()
			           + " and "
			           + LiabilityAccount.INTEREST_RATE_CONSTRAINT.getMaxValue() + ")");
		contentPane.add(interestRateLabel);

		interestRateField = new JTextField(15);
		contentPane.add(interestRateField);

		okBtn = new JButton("OK");
		okBtn.addActionListener(this);
		contentPane.add(okBtn);

		pack();
	
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent event)

see
java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)

		Object src = event.getSource();
		if (src == okBtn) {
			float value = Float.parseFloat(interestRateField.getText());
			try {
				LiabilityAccount.INTEREST_RATE_CONSTRAINT.validate(new Float(value));
				// do something with the value. 
				dispose();
			} catch (final ConstraintException ex) {
				Toolkit.getDefaultToolkit()
				       .beep();
				interestRateField.requestFocus();
				interestRateField.selectAll();
			}
		}
	
public static final voidmain(java.lang.String[] args)
Run the demo.

param
args Command line arguments.

		InterestRateDialog demo = new InterestRateDialog();
		demo.show();
		System.exit(0);