Java Code

import java.awt.*;
import javax.swing.*;
public class AddressApplet extends JApplet
{
	JLabel homeAddress, billingAddress;
	AddressFields home, billing;
	public void init( )
	{
		homeAddress = new JLabel( "Home Address" );
		billingAddress = new JLabel( "Billing Address" );
		home = new AddressFields( );
		billing = new AddressFields( );
		setLayout(new BoxLayout( getContentPane( ), BoxLayout.Y_AXIS ));
		add( homeAddress );
		add( home );
		add( billingAddress );
		add( billing );
	}
}


import java.awt.*; import javax.swing.*; public class AddressFields extends JPanel { // instance variables JLabel name, street, city, state, zip; JTextField tf_name, tf_street, tf_city, tf_state, tf_zip; public AddressFields( ) // constructor { // initialize the instance variables name = new JLabel( "Name:", JLabel.RIGHT ); street = new JLabel( "Street:", JLabel.RIGHT ); city = new JLabel( "City:", JLabel.RIGHT ); state = new JLabel( "State:", JLabel.RIGHT ); zip = new JLabel( "Zip:", JLabel.RIGHT ); tf_name = new JTextField( 20 ); tf_street = new JTextField( 20 ); tf_city = new JTextField( 20 ); tf_state = new JTextField( 20 ); tf_zip = new JTextField( 20 ); // add to the panel setLayout( new GridLayout(5, 2) ); add( name ); add( tf_name ); add( street ); add( tf_street ); add( city ); add( tf_city ); add( state ); add( tf_state ); add( zip ); add( tf_zip ); } }

Return to Code Examples
©2007 E.S.Boese