BorderLayoutPolicy-Java

Understanding The Border Layout Policy in GUI

“Understanding The Border Layout Policy in GUI” helps you get better understanding of Border Layout System in Java.

Try to resize the window once you execute the code and see what happen!

BorderLayoutPolicy Class :


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class BorderLayoutPolicy extends JFrame implements ActionListener {

//Attributes
JButton north = new JButton("NorthButton");
JButton south = new JButton("SouthButton");
JButton center = new JButton("CenterButton");
JButton east = new JButton("EastButton");
JButton west = new JButton("WestButton");

public BorderLayoutPolicy() {
setTitle("An Example of understanding the BorderLayout Policy");
setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,400);
setLocation(200,200);
add("North", north);
add("South", south);
add("Center", center);
add("East", east);
add("West", west);
setVisible(true);
}

public void actionPerformed(ActionEvent e) {

}

}

The Class Tester:


public class BorderLayoutPolicyTester {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new BorderLayoutPolicy();

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *