You are on page 1of 2

import java.awt.

*;
import java.awt.event.ActionEvent;
import javax.swing.*;
import java.awt.Event.*;
import java.awt.event.ActionListener;
import javax.swing.event.*;

public class gbl1 {

List sourceList;
List destinationList;
Button addButton;
Button addAllButton;
Button removeButton;
Button removeAllButton;
Button OKButton;
Button cancelButton;
Button closeButton;
Label sourceLabel;
Label destinationLabel;
Frame aFrame;

GridBagLayout gbl;
GridBagConstraints gbc;

public gbl1() {
sourceList = new List();
destinationList = new List();
addButton = new Button( " >" );
addAllButton = new Button( ">>" );
removeButton = new Button( " >" );
removeAllButton = new Button( ">>" );
OKButton = new Button( "Ok" );
cancelButton = new Button( "Cancel" );
closeButton = new Button( "close" );

closeButton.addActionListener(new ActionListener () {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}

});

sourceLabel = new Label( "Source" );


destinationLabel = new Label( "Destination" );
aFrame = new Frame();
gbl = new GridBagLayout();
gbc = new GridBagConstraints();

aFrame.setLayout( gbl );
buildFrame();
aFrame.setSize( 300,200 );
aFrame.show();
}

public void buildFrame() {


addComponent( 0,0,1,1,aFrame,sourceLabel );
addComponent( 2,0,1,1,aFrame,destinationLabel );
addComponent( 0,1,1,4,aFrame,sourceList );
addComponent( 2,1,1,4,aFrame,destinationList );
addComponent( 1,1,1,1,aFrame,addButton );
addComponent( 1,2,1,1,aFrame,addAllButton );
addComponent( 1,3,1,1,aFrame,removeButton );
addComponent( 1,4,1,1,aFrame,removeAllButton );
addComponent( 0,5,1,1,aFrame,OKButton );
addComponent( 2,5,1,1,aFrame,cancelButton );
addComponent( 4,5,1,1,aFrame,closeButton );

/**
* A helper method to add Components to a Container using
* GridBagLayout
*/
public void addComponent( int x, int y, int w, int h, Container aContainer,
Component aComponent ) {
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = w;
gbc.gridheight = h;
gbl.setConstraints( aComponent, gbc );
aContainer.add( aComponent );
}

public static void main( String[] args ) {


gbl1 myLayout = new gbl1();

}// end class

You might also like