I am tying to use Gridbag layout, but I cannot seem to get it working. here is the plan. and here is the code:
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.net.*;
import java.nio.*;
public class Chatroom implements ActionListener {
public Chatroom (){
JFrame frame = new JFrame ("Warrior Productions Chat");
JPanel pane = new JPanel ();
pane.setLayout(new GridBagLayout ());
GridBagConstraints c = new GridBagConstraints();
//JPanel chatArea = new JPanel ();
//JPanel messageArea = new JPanel();
//JPanel onArea = new JPanel();
JTextField textArea = new JTextField (60); // enter message
c.gridx = 10;
c.gridy = 55;
c.gridwidth = 60; c.gridheight = 5;
pane.add(textArea,c);
//JPanel sendButtonArea = new JPanel ();
JButton send = new JButton ("Send Message");send.setActionCommand ("send");send.addActionListener(this);
c.gridx = 75;
c.gridy = 55;
c.gridwidth = 15; c.gridheight = 5;
pane.add (send,c);
JTextArea users = new JTextArea (""); // SET THE USERS AKA TEXTAREA 2 c.gridx = 75;
c.gridy = 15;
c.gridwidth = 15;
c.gridheight = 35;
pane.add(users,c);
JTextArea messages = new JTextArea (35,60); // see messages TEXTAREA 1 c.gridx = 10; c.gridy = 15; c.gridwidth = 60; c.gridheight = 35;
pane.add (messages, c);
//chatArea.add(messages);onArea.add(users);messageArea.add(textArea); sendButtonArea.add(send);
//pane.add (chatArea); pane.add (onArea); pane.add(messageArea);pane.add (sendButtonArea);
frame.add(pane);
frame.setSize (700,400);
frame.setResizable(false);
frame.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Chatroom cr = new Chatroom ();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if ("send".equals(e.getActionCommand())){
// send message to other person
}
}
}
What am I doing wrong. BTW the increments on both axis in the plan are 10 each time.
Thanks for any help.