i am building chat application in applet.
can i get some help like codesnippet or site for chat application
chat application in java
Page 1 of 14 Replies - 6333 Views - Last Post: 19 January 2011 - 02:51 AM
Replies To: chat application in java
#3
Re: chat application in java
Posted 18 January 2011 - 04:33 AM
import java.applet.Applet;
import java.awt.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.TextField;
import java.lang.*;
public class MyClient extends Applet implements ActionListener{
Socket localSocket;
PrintWriter out;
BufferedReader in;
Socket s;
Frame window=new Frame("2nd page");
TextField name=new TextField(15);
Label label=new Label("Please enter your name");
Button btn=new Button("Login");
TextArea room;
TextField txt;
Button send;
String name1;
DataOutputStream dout;
public void init(){
add(label);
add(name);
add(btn);
window.setLayout(new FlowLayout());
window.add(room=new TextArea("",9, 38, TextArea.SCROLLBARS_VERTICAL_ONLY));
window.add(new Label( "Message"));
window.add(txt=new TextField(27));
window.add(send=new Button("Send"));
txt.addActionListener(this);
send.addActionListener(this);
setLayout(new FlowLayout());
}
public boolean action(Event evt, Object whatAction)
{
if(evt.target instanceof Button)
{
String buttonLabel = (String) whatAction;
if(buttonLabel=="Login");
{
window.resize(300, 300);
window.show();
}
return true;
}
return false;
}
/* if(Button==name){
window.resize(300, 300);
window.show();
String str="";
str=name.getText();
name.setText("");
str=name1+": > "+str;*/
public void actionPerformed(ActionEvent e)
{
try
{
room.append(name.getText()+":");
room.append(txt.getText()+'\n');
Socket s=new Socket("localhost",1004);
txt.setText("");
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
System.out.println(s);
DataInputStream din=new DataInputStream(s.getInputStream());
System.out.println(s);
// localSocket = new Socket(this.getCodeBase().getHost(), 2000);
//Setup data stream in and out of socket and from KeyBoard
// in = new BufferedReader(new InputStreamReader(localSocket.getInputStream()));
//out= new PrintWriter(localSocket.getOutputStream());
//While we have a connection
// get textfield value
// String s = t1.getText();
//Read Texfield value
//flush the buffer if not full!
// read incoming string from socket
//System.out.println(in.readLine());
}
catch(UnknownHostException unc)
{
System.out.println("Connection why not connected");
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}}
class My implements Runnable{
DataInputStream din;
My(DataInputStream din)
{
this.din=din;
}
public void run()
{
String str1="";
while(true){
try{
str1=din.readUTF(); // receive the message
// add the message in list box
}catch(Exception e){}
}
}
}
}
]
[import java.io.*;
import java.net.*;
import java.util.*;
public class MyServer{
ServerSocket ss;
Socket s;
String txt1;
static DataInputStream din;
static DataInputStream dout;
MyServer()throws IOException{
ss=new ServerSocket(1004); // create server socket
while(true){
s=ss.accept(); //accept the client socket
System.out.println("Client is Connected");
}
}
/* class MyThread implements Runnable{
Socket s;
MyThread(Socket s2){
this.s=s;
}
*/
public void run(){
try{
din= new DataInputStream(s.getInputStream());
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
}
catch(Exception oe)
{}
}
class MyThread implements Runnable{
Socket s;
DataInputStream din;
DataOutputStream dout;
MyThread(Socket s){
this.s=s;
}
public void run(){
String str;
try{
din=new DataInputStream(s.getInputStream());
}catch(Exception e){}
{
try{
str=din.readUTF(); //read the message
}catch (IOException e){}
}
}
} }
This post has been edited by macosxnerd101: 18 January 2011 - 07:12 AM
Reason for edit:: Please use code tags
#4
Re: chat application in java
Posted 18 January 2011 - 07:15 AM
What specific problems or errors are you encountering? What is your question?
#5
Re: chat application in java
Posted 19 January 2011 - 02:51 AM
Hello Sir,
Thanks for the reply. Actually the problem is that i am not able to connect client with server. Can you guide me how to make chat-server application?
I have to give username and email-id as input, as soon i hit on Login, it should start as a Live Chat application. I am building this Live Chat Application in Applet.
Please help me. Also is there any good sites where i'vl get Live Chat-Server application.
kindly waiting for you reply.
Thanks for the reply. Actually the problem is that i am not able to connect client with server. Can you guide me how to make chat-server application?
I have to give username and email-id as input, as soon i hit on Login, it should start as a Live Chat application. I am building this Live Chat Application in Applet.
Please help me. Also is there any good sites where i'vl get Live Chat-Server application.
kindly waiting for you reply.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|