BorderLayout Example In java

Ads
 

BorderLayout Example In java

In this section, you will learn how to create BorderLayout in java awt package. The Border Layout is arranging and resizing components to set in five position which is used in this program. The java program uses and declares all positions as a NORTH, SOU

In this section, you will learn how to create BorderLayout in java awt package. The Border Layout is arranging and resizing components to set in five position which is used in this program. The java program uses and declares all positions as a NORTH, SOU

BorderLayout Example In java

     

Introduction

In this section, you will learn how to create BorderLayout in java awt package. The Border Layout is arranging and resizing components to set in five position which is used in this program. The java program uses and declares all positions as a  NORTH, SOUTH, WEST, EAST, and 
CENTER. Here, you will understand about this position how to use in this program.

Program Description:

Following program uses the BorderLayout class for creating Button and set on the frame. Here, define the class named BorderLayoutExample for using  this program. This Java Application uses BorderLayout for setting the position on the frame.

BorderLayout(): This is default constructors of the class Border layout class. This class constructs a new border layout without any gaps between components.  

Here is the code of this program:

import java.awt.*;
import java.awt.event.*;

public class BorderLayoutExample {

  public static void main(String[] args) {
  Frame frame= new Frame("BorderLayout Frame");
  Panel pa= new Panel();
  Button ba1= new Button();
  Button ba2=new Button();
  Button ba3=new Button();
  Button ba4=new Button();
  Button ba5=new Button();
  frame.add(pa);
  pa.setLayout(new BorderLayout());
  pa.add(new Button("Wel"), BorderLayout.NORTH);
  pa.add(new Button("Come"), BorderLayout.SOUTH);
  pa.add(new Button("Rose"), BorderLayout.EAST);
  pa.add(new Button("India"), BorderLayout.WEST);
  pa.add(new Button("RoseIndia"), BorderLayout.CENTER);
  frame.setSize(300,300);
  frame.setVisible(true);
  frame.addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent e){
  System.exit(0);
  }
  });
  }  
}

Output this program:

Download this program.

Ads

Ads