/*
 * 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 SwingPacket;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

/**
 *
 * @author AM
 */
public class DemoSwing extends JFrame {

    JLabel jlbten,jlbdiachi;
    
    JTextField jtxten;
    
    JTextArea jtadiachi;
    
    JButton jbt;
    
    
    
    public DemoSwing(String title) throws HeadlessException {
           super(title);
        this.setSize(400,250);
      
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        creatAndShow();
        
    }

    private void creatAndShow() {
        
        //Tạo panle cha , thiết lập bố cục theo dòng
        JPanel jpn = new JPanel();
        jpn.setLayout(new FlowLayout());
        
        //Tạo panel chứa các ô nhập liệu và label
        JPanel jpnthongtin = new JPanel(new GridLayout(3,2,10,10));
        Border border = BorderFactory.createLineBorder(Color.RED);
        
        //Tạo border 
        TitledBorder borderTitle = BorderFactory.createTitledBorder(border,"THÔNG TIN");
        jpnthongtin.setBorder(borderTitle);
                
        jlbten = new JLabel("Nhập tên :");
        jlbten.setForeground(Color.yellow);
        jlbdiachi = new JLabel("Nhập ý kiến : ");
        jlbdiachi.setForeground(Color.YELLOW);
        Font font = new Font("Font.BOLD",20,20);
        jlbten.setFont(font);
        jlbdiachi.setFont(font);
        jlbten.setOpaque(true);
        jlbdiachi.setOpaque(true);
        jlbten.setBackground(Color.red);
        jlbdiachi.setBackground(Color.red);
        
      
        
        
        jtxten = new JTextField(15);
        jtadiachi = new JTextArea(4,10);
        JScrollPane jsc = new JScrollPane(jtadiachi,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        
        jpnthongtin.add(jlbten);
        jpnthongtin.add(jtxten);
        
        jpnthongtin.add(jlbdiachi);
        jpnthongtin.add(jsc);
        
        
        jpn.add(jpnthongtin);
        
        
        //Tạo panel thứ 3 chứa ô submit
        JPanel jpndefine = new JPanel(new FlowLayout());
        jbt = new JButton("SUBMIT");
        jbt.setFont(font);
        jpndefine.add(jbt);
        
        jpn.add(jpndefine);
        
        
        //Gán sự kiện
        jbt.addActionListener(new action());
        
        
        
        
        
        
        
        this.getContentPane().add(jpn);
       }
    
    class action implements ActionListener
    {

        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showConfirmDialog(rootPane,"Thông tin bạn đã được gửi đến chúng tôi");
        }
        
    }
    
    public static void main(String[] args) {
        new DemoSwing("My window");
    }
    
    
}
