F
Flamingo
I write a very simple program for chat, but there is something wrong I
don't know how to diagnose.
don't know how to diagnose.
Code:
:
/* javaClient deals with the graphical interface of the client*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class javaClient extends JFrame implements ActionListener
{
JButton sendButton; //send button
JTextField inputField; //input field
JTextArea outputArea; //output area
public javaClient()
{
inputField = new JTextField("enter here....");
outputArea = new JTextArea("server returns"); //the textfield show
the reply
sendButton = new JButton("send");
JPanel panel = new JPanel(); //create a new panel
panel.setLayout(new BorderLayout()); //the style of the panel
is BorderLayout
panel.add(inputField, BorderLayout.NORTH);
panel.add(outputArea, BorderLayout.CENTER);
setContentPane(panel);
}
public static void main(String[] args)
{
javaClient frame = new javaClient();
frame.pack();
frame.setVisible(true);
clientAgent ca = new clientAgent("127.0.0.1", 4700);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==sendButton)
{
ca.sendRequest(inputField.getText());
outputArea.append("\n"+ca.getResponse());
}
}
}
/* clientAgent in charge of the communication with the server*/
import java.io.*;
import java.net.*;
public class clientAgent
{
PrintStream ops; //output stream points to server
DataInputStream ips; //input stream from server
String cltRequest; //request by client
String svrRequest; //request by server
public clientAgent(String serverName, int port)
{
try
{
Socket clientSocket = new Socket(serverName,port);
ops = new PrintStream(clientSocket.getOutputStream());
//get the output stream from client socket
ips = new DataInputStream(clientSocket.getInputStream());
//get the input stream from the client socket
}
catch(Exception e)
{
System.out.println("can not connect to the server");
}
}
public void sendRequest(String request)
{
ops.println(request);
}
public String getResponse()
{
String str = new String();
try
{
str = ips.readLine();
}catch(IOException e){ }
return str;
}
}
When I compile the class of clientAgent, the information is below:
Note: Recompile with -Xlint:deprecation for details.
Process completed.
when I compile the class of javaClient, there are some error reported:
can not find symbol variable ca locate: line 34
can not find symbol variable ca locate: line 35
I don't know how to modify my code. Anybody can tell me why?
THanks a lot!