FileDocCategorySizeDatePackage
OpenAccountDialog.javaAPI DocExample2869Sun Mar 02 22:07:12 GMT 1997bank.client

OpenAccountDialog.java

package bank.client;

import java.awt.Button;
import java.awt.Color;
import java.awt.Dialog;
import java.awt.Event;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Rectangle;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class OpenAccountDialog extends Dialog implements ActionListener,
    TextListener {
    private Label     id_label;
    private TextField id_field;
    private Button    ok_button;
    private Button    cancel_button;
    
    public OpenAccountDialog(Frame parent, boolean modal) {
        super(parent, modal);
        setTitle("Open Customer Accounts");
        setLayout(null);
        addNotify();
        resize(insets().left + insets().right + 309,insets().top +
               insets().bottom + 109);
        setBackground(new Color(12632256));
        { // ID
            id_label = new Label("Customer ID:",Label.RIGHT);
            id_label.reshape(insets().left + 24,insets().top + 12,100,24);
            add(id_label);
            id_field = new TextField();
            id_field.addTextListener(this);
            id_field.reshape(insets().left + 144,insets().top + 12,100,24);
            add(id_field);
        }
        { // buttons
            ok_button = new Button("OK");
            ok_button.addActionListener(this);
            ok_button.reshape(insets().left + 72,insets().top + 60,60,24);
            ok_button.enable(false);
            add(ok_button);
            cancel_button = new Button("Cancel");
            cancel_button.addActionListener(this);
            cancel_button.reshape(insets().left + 156,insets().top + 60,60,24);
            add(cancel_button);
        }
    }

    public synchronized void actionPerformed(ActionEvent event) {
        hide();
        if( event.getSource() == ok_button ) {
            int id;
            
            try {
                BankClient frame = (BankClient)getParent();
                
                id = Integer.parseInt(id_field.getText());
                frame.loadCustomer(id);
            }
            catch( NumberFormatException e ) {// this should not happen
                e.printStackTrace();
            }
        }
    }

    public synchronized void textValueChanged(TextEvent event) {
        String txt = id_field.getText();
        int id;

        if( txt.length() < 1 ) {
            ok_button.enable(false);
            return;
        }
        try {
            id = Integer.parseInt(txt);
            ok_button.enable(true);
        }
        catch( NumberFormatException e ) {
            ok_button.enable(false);
        }
    }
}