JTextPaneの内容を変更しようとしています。問題はスコープの問題だと思います。このコードをコンパイルすることはできませんが、アイデアは得られます...マルチスレッドのため、これは難しいかもしれません。TYIA
C:\ucdhb2\gaia\inigui\inigui15\src\inigui13.java:259: error: local
variable theframe is accessed from within inner class; needs to be declared final
theframe.mainfield.getStyledDocumemt().insertString(1, "hellooo",
null);
^ C:\ucdhb2\gaia\inigui\inigui15\src\inigui13.java:259: error: cannot
find symbol
theframe.mainfield.getStyledDocumemt().insertString(1, "hellooo",
null);
^ symbol: method getStyledDocumemt() location: variable mainfield of type JTextField
2 errors
コード
class inigui13 extends applet {
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
JTextField mainfield;
public void init() {
inigui13 theframe = new inigui13();
theframe.setSize(700, 525);
theframe.setVisible(true);
try {
echoSocket = new Socket("192.168.2.3", 9900);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader( echoSocket.getInputStream() ) );
} catch (UnknownHostException e) {
System.err.println("Sstemexit");
System.exit(1);
} catch (IOException e) {
System.err.println("IOFailed");
System.exit(1);
}
Runnable readsock = new Runnable() {
public void run() {
boolean recvread = true;
while( recvread ) {
BufferedReader stdIn = new BufferedReader( new InputStreamReader(System.in));
try {
theframe.mainfield.getStyledDocumemt().insertString(1, "hellooo", null);
} catch( IOException e ){}
}
}
try {
out.close();
in.close();
echoSocket.close();
} catch( IOException e ){}
}
};
Thread readsockt = new Thread(readsock);
readsockt.start();
}
public inigui13 {
mainfield = new JTextPane;
this.add(mainfield);
}
};
}