i've created a chat Applet as client. i want it to be used like this
-user login
-choose chat room
-and start applet.
what i've done now is chat applet. i want it to be used by multi user.
and display online users name or username.
but now it can only detect one user. if i run many applet concurrently using my pc, it can't detect other user's name.
how to do that?
actually i modified this code from one i get from the web page i found.
the original one is not connected to server. and it has the problem as i mentioned before.
this is the original code.
can anyone help me?
import java.lang.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class ChatApplet extends Applet implements ActionListener,Runnable
{
String user;
String msg;
public void init() {
super.init();
//{{INIT_CONTROLS
setLayout(new BorderLayout(0,0));
addNotify();
resize(518,347);
setBackground(new Color(12632256));
msgbox = new java.awt.TextArea("",2,0,TextArea.SCROLLBARS_NONE);
msgbox.setEditable(false);
msgbox.disable();
//msgbox.hide();
msgbox.reshape(0,0,380,216);
add(msgbox);
idbox = new java.awt.TextField();
idbox.reshape(84,288,284,24);
add(idbox);
button1 = new java.awt.Button("EnterRoom");
button1.reshape(384,288,72,21);
add(button1);
list = new java.awt.List();
//list.TOP_ALIGNMENT();
//list.disable();
list = new java.awt.List(5);
list.add("#Default User"+"\n");
list.reshape(384,24,128,196);
list.setFont(new Font("Helvetica", Font.BOLD, 12));
add(list);
label2 = new java.awt.Label("Members");
label2.reshape(396,0,100,19);
add(label2);
label1 = new java.awt.Label("UserName");
label1.reshape(0,288,72,27);
add(label1);
textbox = new java.awt.TextField();
textbox.reshape(84,240,431,44);
add(textbox);
label3 = new java.awt.Label("EnterText");
label3.reshape(0,252,72,25);
add(label3);
//}}
//uf = new UserFrame();
button1.addActionListener(this);
idbox.addActionListener(this);
textbox.addActionListener(this);
list.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==idbox)
{
user = idbox.getText()+"\n";
list.addItem(user.trim());
idbox.setText("");
msgbox.append(user +" HAS JOINED THE GROUP");
}
if(ae.getSource().equals(button1))
{
user = idbox.getText()+"\n";
list.addItem(user.trim());
idbox.setText("");
msgbox.append(user +" HAS JOINED THE GROUP");
}
if(ae.getSource().equals(textbox))
{
msg = textbox.getText();
msgbox.append(msg +"\n");
textbox.setText("");
}
if(ae.getSource().equals(list))
{
String l = list.getSelectedItem();
//uf.setTitle(l);
//Frame i[] = uf.getFrames();
//uf.setVisible(true);
}
}
public void start()
{
if(vt == null)
{
vt = new Thread(this,getClass().getName());
vt.start();
}
}
public void run()
{
try{
for(int i=0;i<10;i++)
{
msgbox.append("One stop Java source code - www.globalleafs.com"+"\n");
msgbox.setForeground(Color.red);
vt.sleep(30000);
vt.resume();
}
}catch(Exception e){e.printStackTrace();}
}
java.awt.TextArea msgbox;
java.awt.TextField idbox;
java.awt.Button button1;
java.awt.List list;
java.awt.Label label2;
java.awt.Label label1;
java.awt.TextField textbox;
java.awt.Label label3;
private Thread vt;
}
-user login
-choose chat room
-and start applet.
what i've done now is chat applet. i want it to be used by multi user.
and display online users name or username.
but now it can only detect one user. if i run many applet concurrently using my pc, it can't detect other user's name.
how to do that?
actually i modified this code from one i get from the web page i found.
the original one is not connected to server. and it has the problem as i mentioned before.
this is the original code.
can anyone help me?
import java.lang.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class ChatApplet extends Applet implements ActionListener,Runnable
{
String user;
String msg;
public void init() {
super.init();
//{{INIT_CONTROLS
setLayout(new BorderLayout(0,0));
addNotify();
resize(518,347);
setBackground(new Color(12632256));
msgbox = new java.awt.TextArea("",2,0,TextArea.SCROLLBARS_NONE);
msgbox.setEditable(false);
msgbox.disable();
//msgbox.hide();
msgbox.reshape(0,0,380,216);
add(msgbox);
idbox = new java.awt.TextField();
idbox.reshape(84,288,284,24);
add(idbox);
button1 = new java.awt.Button("EnterRoom");
button1.reshape(384,288,72,21);
add(button1);
list = new java.awt.List();
//list.TOP_ALIGNMENT();
//list.disable();
list = new java.awt.List(5);
list.add("#Default User"+"\n");
list.reshape(384,24,128,196);
list.setFont(new Font("Helvetica", Font.BOLD, 12));
add(list);
label2 = new java.awt.Label("Members");
label2.reshape(396,0,100,19);
add(label2);
label1 = new java.awt.Label("UserName");
label1.reshape(0,288,72,27);
add(label1);
textbox = new java.awt.TextField();
textbox.reshape(84,240,431,44);
add(textbox);
label3 = new java.awt.Label("EnterText");
label3.reshape(0,252,72,25);
add(label3);
//}}
//uf = new UserFrame();
button1.addActionListener(this);
idbox.addActionListener(this);
textbox.addActionListener(this);
list.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==idbox)
{
user = idbox.getText()+"\n";
list.addItem(user.trim());
idbox.setText("");
msgbox.append(user +" HAS JOINED THE GROUP");
}
if(ae.getSource().equals(button1))
{
user = idbox.getText()+"\n";
list.addItem(user.trim());
idbox.setText("");
msgbox.append(user +" HAS JOINED THE GROUP");
}
if(ae.getSource().equals(textbox))
{
msg = textbox.getText();
msgbox.append(msg +"\n");
textbox.setText("");
}
if(ae.getSource().equals(list))
{
String l = list.getSelectedItem();
//uf.setTitle(l);
//Frame i[] = uf.getFrames();
//uf.setVisible(true);
}
}
public void start()
{
if(vt == null)
{
vt = new Thread(this,getClass().getName());
vt.start();
}
}
public void run()
{
try{
for(int i=0;i<10;i++)
{
msgbox.append("One stop Java source code - www.globalleafs.com"+"\n");
msgbox.setForeground(Color.red);
vt.sleep(30000);
vt.resume();
}
}catch(Exception e){e.printStackTrace();}
}
java.awt.TextArea msgbox;
java.awt.TextField idbox;
java.awt.Button button1;
java.awt.List list;
java.awt.Label label2;
java.awt.Label label1;
java.awt.TextField textbox;
java.awt.Label label3;
private Thread vt;
}