Java Code


import java.awt.*;
import javax.swing.*;
public class ComponentsWithMethods extends JApplet
{
    JLabel name, imageLabel1, imageLabel2, imageLabel3;    		 // instance data
    JTextField tfield;
    JButton button;
    Image img;
    ImageIcon ic;
    public void init( )
    {
        resize( 550,150 );
        setLayout( new FlowLayout( ) );
        setupName( );
        setupButton( );
        setupImage( imageLabel1,  "door.jpg" );
        setupImage( imageLabel2, "flowers.jpg" );
        setupImage( imageLabel3, "Statue.jpg");
    }
    public void setupName( )
    {
        // sets up the Name label and textfield
        name = new JLabel( "Name: " );
        tfield = new JTextField( 5 );
        add( name );
        add( tfield );	
    }
    public void setupButton( )
    {
       button = new JButton( "GO" );
       add( button );
    }
    public void setupImage( JLabel lab, String myimage)
    {
        img = getImage( getCodeBase( ),  myimage );
        ic = new ImageIcon( img );
        lab = new JLabel( ic );
        add( lab );
    }
}

Back to Code Examples
©2006- by E.S.Boese. All Rights Reserved