FileDocCategorySizeDatePackage
PersonEditorPanel.javaAPI DocExample1794Thu Aug 15 20:46:04 BST 2002com.oreilly.javaxp.junit

PersonEditorPanel

public class PersonEditorPanel extends JPanel

Fields Summary
private JTextField
firstNameField
private JTextField
lastNameField
private Person
person
Constructors Summary
public PersonEditorPanel()


      
        layoutGui();
        updateDataDisplay();
    
Methods Summary
javax.swing.JTextFieldgetFirstNameField()

        return this.firstNameField;
    
javax.swing.JTextFieldgetLastNameField()

        return this.lastNameField;
    
private voidlayoutGui()

        setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        add(new JLabel("First Name:"), gbc);
        add(new JLabel("Last Name:"), gbc);

        gbc.gridx = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        add(this.firstNameField, gbc);
        add(this.lastNameField, gbc);
    
public voidsetPerson(Person person)

        this.person = person;
        updateDataDisplay();
    
private voidupdateDataDisplay()

        if (this.person == null) {
            this.firstNameField.setText("");
            this.lastNameField.setText("");
        } else {
            this.firstNameField.setText(this.person.getFirstName());
            this.lastNameField.setText(this.person.getLastName());
        }
        updateEnabledStates();
    
private voidupdateEnabledStates()

        if (this.person == null) {
            this.firstNameField.setEnabled(false);
            this.lastNameField.setEnabled(false);
        } else {
            this.firstNameField.setEnabled(true);
            this.lastNameField.setEnabled(true);
        }