Border Layout in Java
Java Programming

Border Layout in Java

 

BorderLayout  divides the container into five parts (directions),east,west,north,south,centre. By using this Layout we can place AWT components in each part (different location).

BORDER LAYOUT IN JAVA EXAMPLE

import java.awt.*;

import java.applet.*;

public class bordr extends Applet

{

Button b1,b2,b3,b4,b5;

public void init()

{

b1=new Button(“east”);

b1.setBackground(Color.RED);

b2=new Button(“west”);

b2.setBackground(Color.GREEN);

b3=new Button(“south”);

b3.setBackground(Color.BLACK);

b4=new Button(“north”);

b4.setBackground(Color.BLUE);

b5=new Button(“center”);

b5.setBackground(Color.PINK);

setLayout(new BorderLayout());

add(b1,BorderLayout.EAST);

add(b2,BorderLayout.WEST);

add(b3,BorderLayout.SOUTH);

add(b4,BorderLayout.NORTH);

add(b5,BorderLayout.CENTER);

}}

/*<applet code=”bordr.class” height=300 width=300></applet>*/

BORDER LAYOUT IN JAVA EXAMPLE

Explanation….

In the above example, we create five Buttons controls for the five regions: EAST, WEST, NORTH, SOUTH, and CENTRE. Add() is used for adding the components in BorderLayout.

Recommended Posts

C++ Programming

Visibility modes in C++

In C++, visibility modes refer to the accessibility of class members (such as variables and functions) from different parts of a program. C++ provides three visibility modes: public, private, and protected. These modes control the access levels of class members concerning the outside world and derived classes. Public: Members declared as public are accessible from […]

Rekha Setia 
C++ Programming

Inheritance in C++

In C++, inheritance is a fundamental concept of object-oriented programming (OOP) that allows you to create a new class based on an existing class, known as the base or parent class. The new class is called the derived or child class. Inheritance facilitates code reuse and supports the creation of a hierarchy of classes. There […]

Rekha Setia 
C++ Programming

C++ Classes and Objects

In C++, classes and objects are fundamental concepts that support object-oriented programming (OOP). Here’s a brief overview of classes and objects in C++: Classes: In C++, a class is a user-defined data type that allows you to encapsulate data members and member functions into a single unit. Classes are the building blocks of object-oriented programming […]

Rekha Setia 

1 Comment

  1. I found it useful

Leave A Comment