Click to See Complete Forum and Search --> : Please help me creating this little GUI Chatting application


andre3080
11-18-2007, 06:43 AM
Hi...

im really new to java and that stuff... my probelm is that i have to ceate a little chat application and ive no idea how to do this.

So i started to construct a window using bluej:
import javax.swing.*;

public class FirstGUI extends JFrame
{
public FirstGUI()
{
super("Chatfenster");
setSize(600,300);
setLocation(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}

public static void main(String[] args)
{
FirstGUI g = new FirstGUI();
}
}

The program i have to write should look like a chat window, with to text fields. One in the bottom where you can write something and when you push on a "send" button it should appear in the other text field.

I would be really happy if someone could explain how to do this... thanks

Khalid Ali
11-18-2007, 10:36 AM
I can explain the concept, but you will have to make an effort yourself to begin.
There are 2 main components for any chat program that allows multiple client to interact with each other.
1. A chant server,
2. X number of clients that will log into chat server.

What you want to do is create a server application that will wait and listen for a login request from a client.
Once the login request is completed then it will display the text sent by the client to whoever other logged on users.
On the client side you will need to write it so that first it will connect to server, and then send messages subsequently.

For the chat client main window, what you need to do is in the text field put some text, then when u hit send, you need to capture that event for that button, then get text from text field, and then send it to server as well as put it on to the main display window of the chat.....

andre3080
11-18-2007, 10:48 AM
Thanks Khakid...

but this doesnt have to be a real chat... so i dont need a server application...

The only thing that is needed is, that the text which is written in the bottom field should appear in the field above after pushing the "send" button.

This is just a homework i have to do

Khalid Ali
11-18-2007, 03:11 PM
good....that makes it very easy then.. do this,
after the the statement that you have in the beginning of class name and extend JFrame, add another statement so that it looks like this

public class FirstGUI extends JFrame implements ActionListener{

now when u will have the above statement, it will not compile, you will get an error. Try to understand that error and let me know if you understand what solution is required to avoid that error. It very obvious but lets take it 1 step at a time.