Compellingly Beautiful Software
Products Programming Contact
This user interface is a typical fragment of a larger application. It's quite simple, really, and you can hope that it will be simple to build. Will that hope hold up in practice? What will you or your development tools have to do? Remember, component layout is only part of the problem: then you have to make it work.
You can code this UI in Java®, or you can code it in Slamdunk, the exciting new user interface framework from brising.com. You'll get a real Java UI either way, but look at these two code samples, and decide which one you would rather write and maintain. Actually, these two samples don't do exactly the same thing: the Slamdunk UI does more, and is easier to integrate and reuse, too.
Ready to learn more about Slamdunk?
(cp (lg 4 1)(bi "Name" (cf))(bi "Address" (cf))(bi "Phone" (cf))(cb null "clear"))
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
import javax.swing.border.*;
public class PersonPanel extends JPanel
implements ActionListener,FocusListener,PropertyChangeListener
{
// INSTANCE VARIABLES
Person person;
JTextField address;
JTextField name;
JTextField phone;
JButton clear;
// CONSTRUCTORS
/* This constructor initializes all of my subordinate components. */
public PersonPanel()
{
super();
clear = new JButton ("clear");
address = new JTextField();
name = new JTextField();
phone = new JTextField();
clear .addActionListener(this);
address.addActionListener(this);
name .addActionListener(this);
phone .addActionListener(this);
address.addFocusListener(this);
name .addFocusListener(this);
phone .addFocusListener(this);
address.setBorder(new TitledBorder("Address"));
name .setBorder(new TitledBorder("Name" ));
phone .setBorder(new TitledBorder("Phone" ));
clear .setToolTipText("clear" );
address.setToolTipText("Address");
name .setToolTipText("Name" );
phone .setToolTipText("Phone" );
setLayout(new java.awt.GridLayout(4,1));
add(name );
add(address);
add(phone );
add(clear );
enableAll(false);
}
// PUBLIC INSTANCE METHODS
/* These three methods respond to events from my subordinate components. */
public void actionPerformed(ActionEvent event)
{
final Object source = event.getSource();
if (false){} // do nothing, but simplify maintenance editing
else if (source == clear)
person.clear ();
else if (source == address)
person.setAddress(address.getText());
else if (source == name)
person.setName (name .getText());
else if (source == phone)
person.setPhone (phone .getText());
else
throw new RuntimeException
("ActionEvent from unknown source: "+source);
}
public void focusGained(FocusEvent event)
{} // do nothing
public void focusLost (FocusEvent event)
{
final Object source = event.getSource();
if (false){} // do nothing, but simplify maintenance editing
else if (source == address)
person.setAddress(address.getText());
else if (source == name)
person.setName (name .getText());
else if (source == phone)
person.setPhone (phone .getText());
else
throw new RuntimeException
("FocusEvent from unknown source: "+source);
}
/* These two methods deal with model acquisition. */
public Person getPerson()
{return person;}
public void setPerson(Person aPerson)
{
if (null != person)
person.removePropertyChangeListener(this);
if (null != aPerson)
{
person = aPerson;
person.addPropertyChangeListener(this);
address.setText(person.getAddress().toString());
name .setText(person.getName ().toString());
phone .setText(person.getPhone ().toString());
enableAll(true);
}
else
{
person = null;
address.setText("");
name .setText("");
phone .setText("");
enableAll(false);
}
}
/* This method responds to changes in my model. */
public void propertyChange(PropertyChangeEvent event)
{
final String update = event.getPropertyName();
final Object value = event.getNewValue();
final String string = null != value ? value.toString() : "";
if (false){} // do nothing, but simplify maintenance editing
else if (update == Person.updateAddress)
address.setText(string);
else if (update == Person.updateName )
name .setText(string);
else if (update == Person.updatePhone )
phone .setText(string);
else
throw new RuntimeException
("Unknown property for "+getClass().getName()+": "+update);
}
// PROTECTED INSTANCE METHODS
/* This is a utility method. */
protected void enableAll(boolean enabled)
{
clear .setEnabled(enabled);
address.setEnabled(enabled);
name .setEnabled(enabled);
phone .setEnabled(enabled);
}
}
Ready to learn more about Slamdunk?
© 2004 brising.com