我想在客户端和服务器之间来回发送一个类。想要从客户端运行 Panel 类。请问谁能告诉我该怎么办??
客户类别:
import java.net.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
public class Client
{
private static Socket socket = null;
public static void main (String args[]) throws IOException, ClassNotFoundException, EOFException
{
try {
socket = new Socket("localhost", 4444);
} catch (UnknownHostException e) {
System.err.println("Don't know about host: localhost");
System.exit(1);
}
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
socket.close();
}
}
当我想从客户端读取面板对象时,会出现一个错误,提示找不到主类。如何从客户端访问面板类???
服务器类:
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class Server {
public static void main(String[] args) throws IOException, ClassNotFoundException{
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(4444);
} catch (IOException e) {
System.err.println("Could not listen on port: 4444.");
System.exit(-1);
}
Socket socketOut = serverSocket.accept();
ObjectOutputStream oos = new ObjectOutputStream(socketOut.getOutputStream()) ;
socketOut.close();
serverSocket.close();
}
}
面板类
import javax.swing.*;
import java.awt.*;
public class Panel extends JPanel {
public Panel()
{
JTextField n = new JTextField(10);
n.setText("Hello");
JButton q = new JButton("Who are you?");
setSize(300,300);
add(n);
add(q);
setLayout (new FlowLayout());
}
}