/*
 * 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.Color;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 *
 * @author ta
 */
public class MyJLableWithColor extends JFrame{

    public MyJLableWithColor(String title) throws HeadlessException {
       
     this.setSize(600,800);
     this.getContentPane().setLayout(new GridLayout(1,2,5,5));
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     this.setLocationRelativeTo(null);
     this.setVisible(true);
     
     JLabel lb1,lb2;
     
      lb1 = CreatLable("JLabel 1", Color.yellow, Color.darkGray);
      
      lb2 = CreatLable("JLabel 2", Color.red, Color.CYAN);
        
      
      this.getContentPane().add(lb1);
      this.getContentPane().add(lb2);
      
        
        
        
    }

    private JLabel CreatLable(String text,Color textColor,Color backgroundColor) {
        
      JLabel lb = new JLabel(text);
      
      lb.setHorizontalTextPosition(JLabel.CENTER);
      
      lb.setForeground(textColor);
      
      
      lb.setOpaque(true);
      
      lb.setBackground(backgroundColor);
       return lb; 
    }


    public static void main(String[] args) {
        
        new MyJLableWithColor("MY WINDOW");
        
    }
    
    

    
}
