Hey there, everyone.
I'm currently enrolled in a Client/Server Programming class (i.e. Java 2) in college. For our first lab assignment, we're being asked to create a simple GUI to emulate a basic instant messaging chat client. This client won't have any actual functionality, just a simple window. This window, however has to look similar to a window developed by my professor for a Visual Basic class. Now, I KNOW that with my basic knowledge, I'll never be able to get my code to look exactly like the example, but I'd like to get as close as possible.
My real question is: what LayoutManager (or combination thereof) should I be using to get as close to this as possible? I've only put in the first couple components onto my lab project, but I'm curious if I'm doing this right... Or if I'm using the smartest approach. Thanks for any and all help!
EDIT: OH, before I forget, here's the sample code that I already have now. Pick it apart at your leisure! Any and all criticisms are welcome, both for my code, and the approach I've tried!
import java.awt.*;
import javax.swing.*;
public class Chat {
public static void main(String[] args) {
/*
* The main() method is what creates the Frame for use by the user. It set's a default size to 300x600,
* which is a pretty standard size for a chat client. It also adds a title to the Frame, which adds a
* cool element there!
*/
ChatClient GUI = new ChatClient();
GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GUI.setSize(300, 600);
GUI.setTitle("Lab 1: Chat");
GUI.setVisible(true);
GUI.start();
}
}
class ChatClient extends JFrame {
public void start() {
setLayout(new BorderLayout());
/*
* Divide the main Frame into three separate Panels. The North Panel holds the username, server, and port
* information, along with the associated Buttons.
*/
JPanel northPanelGroup = new JPanel(new GridLayout(3, 3, 1, 1));
JPanel centerPanelGroup = new JPanel(new GridLayout(1, 1, 1, 1));
JPanel southPanelGroup = new JPanel(new GridLayout(1, 3, 1, 1));
/*
* Obviously, add the Panel Groups into the main Frame
*/
add(BorderLayout.NORTH, northPanelGroup);
add(BorderLayout.CENTER, centerPanelGroup);
add(BorderLayout.SOUTH, southPanelGroup);
/*
* Begin adding the username, server, and port information into the North Panel
*/
JPanel usernamePanel = new JPanel();
usernamePanel.add(new JLabel("Username"));
usernamePanel.add(new JTextField(10));
northPanelGroup.add(usernamePanel);
JPanel serverPanel = new JPanel();
serverPanel.add(new JLabel("Server"));
serverPanel.add(new JTextField(10));
northPanelGroup.add(serverPanel);
JPanel portPanel = new JPanel();
portPanel.add(new JLabel("Port"));
portPanel.add(new JTextField(5));
northPanelGroup.add(portPanel);
}
}