fork download
  1.  
  2.  
  3. import java.awt.*;
  4. import java.net.*;
  5. import java.applet.*;
  6. import java.awt.event.*;
  7. import java.io.*;
  8.  
  9. public class Client extends Panel implements Runnable {
  10.  
  11. private TextField tf = new TextField();
  12. private TextArea ta = new TextArea();
  13.  
  14. private Socket socket;
  15.  
  16. private DataOutputStream dout;
  17. private DataInputStream iD;
  18.  
  19.  
  20. public Client( String host, int port) {
  21. setLayout(new BorderLayout());
  22. add("North", tf);
  23. add("Center", ta);
  24.  
  25. tf.addActionListener(new ActionListener() {
  26. public void actionPerformed(ActionEvent e) {
  27. processMessage(e.getActionCommand());
  28. }
  29. }
  30. );
  31.  
  32. try {
  33. socket = new Socket(host, port);
  34. System.out.println("Connected...");
  35.  
  36. iD = new DataInputStream(socket.getInputStream());
  37. dout = new DataOutputStream(socket.getOutputStream());
  38.  
  39. new Thread(this).start();
  40. } catch (IOException e) {
  41. System.out.println(e);
  42. }
  43.  
  44. }
  45. private void processMessage( String message ){
  46. try {
  47. dout.writeUTF(message);
  48. tf.setText("");
  49. } catch (IOException ie) {
  50. System.out.println(ie);
  51. }
  52. }
  53.  
  54.  
  55. public void run(){
  56. try{
  57. while(true){
  58. String message = iD.readUTF();
  59. ta.append(message+"\n");
  60. }
  61. }
  62. catch (IOException ie)
  63. {
  64. System.out.println( ie);
  65. }
  66.  
  67. }
  68.  
  69.  
  70.  
  71. }
  72.  
  73.  
  74.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:9: error: class Client is public, should be declared in a file named Client.java
public class Client extends Panel implements Runnable {
       ^
1 error
stdout
Standard output is empty