/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package swingdemo;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.HeadlessException;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author hi
 */
public class SwingDemo extends JFrame {

    /**
     * @param args the command line arguments
     */
    
    
    public SwingDemo(String title) throws HeadlessException {
        super(title);
        this.setSize(400,600);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        creatAndShow();
    }
    
    

    public static void main(String[] args) {
        // TODO code application logic here
        new SwingDemo("My Window");
    }

    private void creatAndShow() {
        
       //Tạo một layout chứa các layout con
        JPanel jpnBorder = new JPanel();
        jpnBorder.setLayout(new BorderLayout());
        Font ft = new Font("Arial",Font.BOLD|Font.ITALIC,25);
        
        
        
        //Tạo layout phía Bắc
        JPanel jpnNorth = new JPanel();
        jpnNorth.setBackground(Color.red);
        jpnNorth.setPreferredSize(new Dimension(0,50));
        JLabel lbNorth = new JLabel("North");
        lbNorth.setForeground(Color.WHITE);
        lbNorth.setFont(ft);
        jpnNorth.add(lbNorth);
        jpnBorder.add(jpnNorth,BorderLayout.NORTH);
        
        
        
        //Tạo layout phía Nam
        JPanel jpnSouth = new JPanel();
        jpnSouth.setBackground(Color.red);
        jpnSouth.setPreferredSize(jpnNorth.getPreferredSize());
        JLabel lbSouth = new JLabel("South");
        lbSouth.setForeground(Color.WHITE);
        lbSouth.setFont(ft);
        jpnSouth.add(lbSouth);
        jpnBorder.add(jpnSouth,BorderLayout.SOUTH);
        
        
        
        //Tạo layout phía Tây
        JPanel jpnWest = new JPanel();
        jpnWest.setBackground(Color.BLUE);
        jpnWest.setLayout(new BorderLayout());
        JLabel lbWest = new JLabel("WEST",JLabel.CENTER);
        lbWest.setFont(ft);
        lbWest.setForeground(Color.DARK_GRAY);
        jpnWest.add(lbWest,BorderLayout.CENTER);
        jpnBorder.add(jpnWest,BorderLayout.WEST);
         
         
         
         
        
        
        //Tạo layout phía Đông
        JPanel jpnEast = new JPanel();
        jpnEast.setBackground(Color.BLUE);
        JLabel lbEast = new JLabel("EAST",JLabel.CENTER);
        lbEast.setFont(ft);
        lbEast.setForeground(Color.WHITE);
        jpnEast.setLayout(new BorderLayout());
        jpnEast.add(lbEast,BorderLayout.CENTER);
        jpnBorder.add(jpnEast,BorderLayout.EAST);
       
        
        
        
        //Tạo layout trung tâm 
        JPanel jpnCenter = new JPanel();
        jpnCenter.setLayout(new BorderLayout());
        jpnCenter.setBackground(Color.LIGHT_GRAY);
        JLabel lbCenter = new JLabel("CENTER",JLabel.CENTER);
        lbCenter.setFont(ft);
        lbCenter.setForeground(Color.WHITE);
        jpnCenter.add(lbCenter,BorderLayout.CENTER);
        jpnBorder.add(jpnCenter,BorderLayout.CENTER);
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        Container con = getContentPane();
        con.add(jpnBorder);
        
    }
    
}
