package COM.xinit.demon.co.uk.3tier.tradertool;
import java.awt.*;
import java.awt.event.*;
import database.*;
public class CustomerDialogue extends Dialog implements ActionListener {
Button ok;
Button delete;
TextField ssn;
TextField name;
TextArea address;
boolean addmode = false;
TraderApplication app;
public CustomerDialogue ( TraderApplication ta,
Frame parent ) {
super ( parent );
app = ba;
createGUI();
}
public CustomerDialogue ( TraderApplication ta,
Frame parent,
boolean modal ) {
super ( parent, modal );
app = ba;
createGUI();
}
public CustomerDialogue ( TraderApplication ta,
Frame parent,
String title ) {
super ( parent, title );
app = ba;
createGUI();
}
public CustomerDialogue ( TraderApplication ta,
Frame parent,
String title,
boolean modal ) {
super ( parent, title, modal );
app = ba;
createGUI();
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == ok) {
if (addmode) {
app.addClient(ssn.getText(),name.getText(),address.getText());
} else {
app.editClient(ssn.getText(),name.getText(),address.getText());
}
} else if (ae.getSource() == delete) {
app.deleteClient(ssn.getText());
}
setVisible(false);
}
private void createGUI () {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we)
{
we.getWindow().setVisible(false);
}
}
);
GridBagLayout gb = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
Font labelfont = new Font("Helvetica",Font.BOLD,15);
Label l1 = new Label("SSN:");
l1.setFont(labelfont);
Label l2 = new Label("Name:");
l2.setFont(labelfont);
Label l3 = new Label("Address:");
l3.setFont(labelfont);
ssn = new TextField();
name = new TextField();
address = new TextArea(4,30);
ok = new Button ( "OK" );
ok.addActionListener(this);
delete = new Button ( "Delete" );
delete.addActionListener(this);
Button cancel = new Button ( "Cancel" );
cancel.addActionListener(this);
ok.setFont(labelfont);
cancel.setFont(labelfont);
delete.setFont(labelfont);
setLayout ( gb );
gbc.insets = new Insets ( 5,5,5,5 );
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.VERTICAL;
gb.setConstraints(l1,gbc);
add (l1);
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gb.setConstraints(ssn,gbc);
add (ssn);
gbc.weightx = 0.0;
gbc.fill = GridBagConstraints.VERTICAL;
gbc.gridwidth = 1;
gb.setConstraints(l2,gbc);
add (l2);
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gb.setConstraints(name,gbc);
add (name);
Panel p1 = new Panel ();
p1.setLayout(new BorderLayout());
p1.add("North",l3);
gbc.fill = GridBagConstraints.VERTICAL;
gbc.weightx = 0.0;
gbc.gridwidth = 1;
gb.setConstraints(p1,gbc);
add (p1);
gbc.anchor = GridBagConstraints.WEST;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gb.setConstraints(address,gbc);
add (address);
GridBagLayout ngb = new GridBagLayout();
Panel p2 = new Panel ();
p2.setLayout ( ngb );
gbc.gridwidth = 1;
ngb.setConstraints(ok,gbc);
p2.add(ok);
ngb.setConstraints(delete,gbc);
p2.add(delete);
gbc.gridwidth = GridBagConstraints.REMAINDER;
ngb.setConstraints(cancel,gbc);
p2.add(cancel);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weighty = 0.0;
gb.setConstraints(p2,gbc);
add (p2);
}
public void makeAdd()
{
setTitle ( "Add New Client" );
ssn.setEditable(true);
ssn.setText("");
name.setText("");
address.setText("");
delete.setEnabled(false);
addmode = true;
}
public void makeEdit()
{
setTitle ( "Edit Client" );
ssn.setEditable(false);
delete.setEnabled(true);
addmode = false;
}
public void loadClient(CustomerRec client)
{
ssn.setText(client.getSSN());
name.setText(client.getName());
address.setText(client.getAddress());
}
}
Last Updated