import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingConstants; /** * Class displaying the adress output. */ public class AddressOutput extends JFrame { private JLabel lblFirstName; private JLabel lblSecondName; private JLabel lblPhoneNumber; private JLabel lblHouseNumber; private JLabel lblStreetName1; private JLabel lblStreetName2; private JLabel lblCityName; /** * Creates a new instance of AddressOutput */ public AddressOutput(ShortAddress address,boolean displayFull) { super(" Address output"); //Set the layout so all labels are displayed underneath eachother. setLayout(new GridLayout(0,1)); addLabel(lblFirstName,"Firstname : " + address.firstName); addLabel(lblSecondName,"Secondname: " + address.secondName); addLabel(lblPhoneNumber,"Phone number: " + address.phoneNumber); //In this application since I am allways filling a Full Address this code would allways run if I didn't add the displayFull switch.' if(address.getClass().getName() == "FullAddress" && displayFull) { //We are dealing with a full address here. FullAddress fulladdress = (FullAddress)address; addLabel(lblHouseNumber, "House number: " + String.valueOf(fulladdress.housenumber)); addLabel(lblStreetName1,"Streetname : " + fulladdress.streetName1); addLabel(lblStreetName2,"Postalcode: " + fulladdress.streetName2); addLabel(lblCityName,"City name: " +fulladdress.cityName); } } /** *Adds a new label to the form. */ private void addLabel(JLabel label, String text) { label = new JLabel(text); add(label); } }