something wrong with my chatting program!

F

Flamingo

I write a very simple program for chat, but there is something wrong I
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!
 
I

IchBin

Flamingo said:
I write a very simple program for chat, but there is something wrong I
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
{[/QUOTE]
private JButton sendButton;                           //send button
private JTextField inputField;                        //input field
private JTextArea outputArea;                       //output area
private clientAgent ca;[QUOTE]
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);[/QUOTE]

ca = new clientAgent("127.0.0.1", 4700);
[QUOTE]
}

	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"); 
System.out.println(e);

	     }[/QUOTE]



--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA              http://weconsultants.phpnet.us
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)
 
I

IchBin

Flamingo said:
I write a very simple program for chat, but there is something wrong I
don't know how to diagnose.

Code:
:[/QUOTE]

Make the following two changes:
[QUOTE]
/* 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[/QUOTE]

clientAgent ca = new clientAgent("127.0.0.1", 4700);
[QUOTE]
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);
	}

	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(e);

	     }
}
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!
[/QUOTE]


--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA              http://weconsultants.phpnet.us
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top