FileDocCategorySizeDatePackage
SomeGUIPanel.javaAPI DocExample2673Sun Dec 14 22:47:30 GMT 2003oreilly.hcj.references

SomeGUIPanel

public class SomeGUIPanel extends JPanel implements ActionListener, PropertyChangeListener
A demo gui panel with a memory leak.
author
Robert Simmons jr. (kraythe)
version
$Revision: 1.3 $

Fields Summary
public SomeDataClass
dataObject
The object being managed.
JTextField
valueField
Holds the field used for value input.
Constructors Summary
public SomeGUIPanel(SomeDataClass obj)
Creates a new SomeGUIPanel object.

param
obj The object to manage.


	            	 
	    
		this.setLayout(new GridLayout(1, 2));
		JLabel label = new JLabel("Age: ", SwingConstants.RIGHT);
		this.add(label);
		this.valueField = new JTextField();
		this.valueField.addActionListener(this);
		this.add(this.valueField);
		changeObject(obj);
	
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent event)

see
java.awt.event.ActionListener

		if (event.getSource() == this.valueField) {
			try {
				int temp = Integer.parseInt(this.valueField.getText());
				this.dataObject.setAge(temp);
			} catch (final NumberFormatException ex) {
				Toolkit.getDefaultToolkit()
				       .beep();
			}
		}
	
public voidchangeObject(SomeDataClass obj)
Change the managed object to another one.

param
obj The object to manage.

		this.dataObject = obj;
		this.dataObject.addPropertyChangeListener(this);
		this.valueField.setText(Integer.toString(obj.getAge()));
	
public voidpropertyChange(java.beans.PropertyChangeEvent event)

see
java.beans.PropertyChangeListener

		if (event.getSource() == this.dataObject) {
			this.valueField.setText(Integer.toString(this.dataObject.getAge()));
		}