Friday, 20 May 2011

part 2 chatting softwear for the network on java server

package javaserverapplaction;
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class JavaServerClass
{
     JFrame J=new JFrame("Server");
    JButton JB=new JButton("Send");
    JTextField JT=new JTextField(20);
    JTextArea JTA=new JTextArea();
    String S2=new String();
     ServerSocket S=null;
      Socket S1=null;
    public void ServerFunction()
    {
      try
      {
          J.setLayout(null);
         //J.setLayout(null);
         S=new ServerSocket(3333);
         S1=S.accept();
       



       
        J.add(JB);
        JB.addActionListener(new ActionListener()
        {
                public void actionPerformed(ActionEvent e)
                {
                    try
                    {
                       while(true)
                       {
                          DataInputStream D=new DataInputStream(S1.getInputStream());
                          S2=D.readUTF();
                          JOptionPane.showMessageDialog(J,S2);
                       }
                    }
                    catch(Exception E)
                    {
                      JOptionPane.showMessageDialog(J, E.getMessage());
                    }
                }
        });
        JB.setBounds(10, 10, 100, 30);
        J.add(JT);
        JT.setBounds(150, 10, 100, 30);

        JTA.setBounds(10, 50,250, 250);
        J.add(JTA);
         J.setSize(300,400);
        J.setVisible(true);




      }
      catch(Exception E)
      {
       JOptionPane.showMessageDialog(J, E.getMessage());
      }
    }
    public static void main(String[] args)
    {
       JavaServerClass Ji=new JavaServerClass();
       Ji.ServerFunction();
    }

}
this is server side programing and this will go to another PC  and same you have to add ur ip address

No comments:

Post a Comment