package javaclientapplaction;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.*;
import java.io.*;
import javax.swing.*;
public class JavaClientClass extends JFrame
{
JFrame J=new JFrame("Client");
JButton JB=new JButton("Send");
JTextField JT=new JTextField(20);
JTextArea JTA=new JTextArea();
Socket S=null;
public void ClientFunction()
{
try
{
J.setLayout(null);
S=new Socket("localhost",3333);
JB.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
DataOutputStream D=new DataOutputStream(S.getOutputStream());
D.writeUTF(JT.getText());
}
catch(Exception E)
{
JOptionPane.showMessageDialog(J, E.getMessage());
}
}
});
J.add(JB);
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)
{
JavaClientClass J1=new JavaClientClass();
J1.ClientFunction();
}
}
you have to use two PC for that this is a client side programing you have to set ip fo running this program
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.*;
import java.io.*;
import javax.swing.*;
public class JavaClientClass extends JFrame
{
JFrame J=new JFrame("Client");
JButton JB=new JButton("Send");
JTextField JT=new JTextField(20);
JTextArea JTA=new JTextArea();
Socket S=null;
public void ClientFunction()
{
try
{
J.setLayout(null);
S=new Socket("localhost",3333);
JB.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
DataOutputStream D=new DataOutputStream(S.getOutputStream());
D.writeUTF(JT.getText());
}
catch(Exception E)
{
JOptionPane.showMessageDialog(J, E.getMessage());
}
}
});
J.add(JB);
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)
{
JavaClientClass J1=new JavaClientClass();
J1.ClientFunction();
}
}
you have to use two PC for that this is a client side programing you have to set ip fo running this program
No comments:
Post a Comment