import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class MainFrame2 
extends JFrame 
implements ActionListener {
	
	public MainFrame2 (String caption) {
		super (caption);
	}
	
	public void initFrame() {
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(400, 400);
		
		// #1
		/* this.getContentPane().setLayout(new BorderLayout());
		this.getContentPane().add(new JLabel("Type here:"), BorderLayout.NORTH);
		// this.getContentPane().add(new JButton("Press me"), "South");
		// make the button an observer 
		// add the event import at top and the implements ActionListener
		// and implement the method actionPerformed
		JButton button = new JButton("Press me");
		button.addActionListener(this);
		this.getContentPane().add(button, "South"); */
		
		// #2
		/* this.getContentPane().setLayout(new FlowLayout());
		this.getContentPane().add(new JLabel("Type here:"), "NORTH");
		JButton button = new JButton("Press me");
		button.addActionListener(this);
		this.getContentPane().add(button, "South"); */
		
		// #3
		/* this.getContentPane().setLayout(new GridLayout(2, 1));
		// this.getContentPane().setLayout(new GridLayout(1, 2));
		this.getContentPane().add(new JLabel("Type here:"), "NORTH");
		JButton button = new JButton("Press me");
		button.addActionListener(this);
		this.getContentPane().add(button, "South"); */
		
		// #4 
		this.getContentPane().setLayout(new GridLayout(2, 2));
		
		JPanel topleft = new JPanel();
		topleft.setLayout(new BorderLayout());
		JLabel label1 = new JLabel("  Type here ===>");
		label1.setFont(new Font("Serif", Font.BOLD, 26));
		label1.setForeground(Color.magenta);
		topleft.setBackground(Color.cyan);
		topleft.add(label1, "Center");
		// topleft.add(label1, BorderLayout.NORTH);
		this.getContentPane().add(topleft);
		
		JPanel topright = new JPanel();
		topright.setLayout(new BorderLayout());
		JTextArea textArea1 = new JTextArea();
		textArea1.setLineWrap(true);      // fix non-line wrapping
		textArea1.setWrapStyleWord(true);
		JScrollPane pane = new JScrollPane(textArea1);
		topright.add(pane);
		this.getContentPane().add(topright); 
		// textArea1.setPreferredSize(new Dimension(100, 100));
		// this.getContentPane().add(textArea1);
		
		JPanel lowerleft = new JPanel();
		lowerleft.setLayout(new BorderLayout());
		JButton button = new JButton("Press me");
		button.setFont(new Font("ComicSansMS", Font.ITALIC, 18));
		lowerleft.setBackground(Color.orange);
		button.setForeground(Color.red);
		lowerleft.add(button);
		button.addActionListener(this);
		this.getContentPane().add(lowerleft);
		
		JPanel lowerright = new JPanel();
		lowerright.setLayout(new BorderLayout());
		JTextArea textArea2 = new JTextArea();
		JScrollPane pane2 = new JScrollPane(textArea2);
		pane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		lowerright.add(pane2);
		this.getContentPane().add(lowerright); 
		
		
		this.setVisible(true);				
	}

	public void actionPerformed(ActionEvent event) {
		// System.out.println("Pressed button!");
		// OR
		JOptionPane.showMessageDialog(null, "Button Clicked! Yay!");
	}

}
