mport javax.swing.*;import java.awt.BorderLayout;import java.awt.Component;import java.awt.Container;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.TextArea;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;public class ChatGUI extends JPanel{ private JPanel pnlChatGUI; private JPanel pnlMain; // Phonebook Panel private TextArea txtChat; private JTextField txtInput; private JMenuBar menuBar; private JMenu menu; private JMenuItem menuItem; public ChatGUI () { JFrame frame = new JFrame("Phonebook"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(480,480); frame.setVisible(true); menuBar = new JMenuBar(); menu = new JMenu("test2"); menuItem = new JMenuItem("test"); menu.add(menuItem); menuBar.add(menu); pnlChatGUI = new JPanel ( new GridBagLayout()); txtChat = new TextArea(); txtInput = new JTextField(); pnlMain = new JPanel(new GridBagLayout()); addComponent(pnlMain, txtChat , 0, 0, 1, 1, 1, 1,GridBagConstraints.BOTH); addComponent(pnlMain, txtInput , 0, 1, 1, 1, 1, 1,GridBagConstraints.BOTH); addComponent(pnlChatGUI,pnlMain, 0, 0, 1, 1, 1, 1,GridBagConstraints.NONE); frame.setJMenuBar(menuBar); frame.getContentPane().add(pnlChatGUI); frame.setVisible(true); } public void actionPerformed(ActionEvent e) { } public static void main(String[] args) { new ChatGUI(); } private void addComponent(Container container, Component c, int x, int y, int width, int height, double weightx, double weighty, int fillOption) { GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = fillOption ; //GridBagConstraints.NONE ; //GridBagConstraints.BOTH; gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = width; gbc.gridheight = height; gbc.weightx = weightx; gbc.weighty = weighty; container.add(c, gbc); } }