我有這三類:的Java:ObjectOutputStream的序列化與問題
命令:
package pack;
public abstract class Command impements java.io.Serializable
{
public abstract void execute();
}
客戶:
package pack;
// imports....
public class Client
{
Socket socket;
// Constructor...
public void sendCommand(Command c)
{
try
{
new ObjectOuputStream(socket.getOutputStream()).writeObject(c);
} catch (Exception e) {e.printStackTrace()};
}
}
MyKeyListener:
此Keylistener被添加到JFrame中的組件。
public class MyKeyListener implements KeyListener
{
private Client client;
public MyKeyListener(Client c)
{ client = c; }
public void keyTyped(....)......; // This method does nothing
public void keyPressed(KeyEvent e)
{
client.sendCommand(new Command() {
public void execute()
{
new Robot().keyPress(e.getKeyCode());
}
});
}
// The same for keyRelease()....
}
問題是:如果我運行代碼,他想發送命令。由於「MyKeyListener不可序列化」,流停止編寫 ???!但我從不嘗試發送MyKeyListener
我希望拼寫錯誤不在您的代碼中。 – Svante 2009-09-11 16:32:17