public static void input1() {
try {
ServerSocket input1server = new ServerSocket(socket1);
Socket skt1 = input1server.accept();
BufferedReader input = new BufferedReader(new InputStreamReader(skt1.getInputStream()));
PrintStream output = new PrintStream(skt1.getOutputStream());
if(true){
line1.setText("[Input 1]Connection established on port: " + socket1);
line1.setForeground(Color.BLUE);
}
String text = input.readLine();
if(text != null){
line2.setText("Recieved message from client: [" +text+ "]");
output.print("Message successfully recieved");
int status = Integer.parseInt(text);
System.out.println(status);
}
skt1.close();
input1server.close();
System.out.println("Sever closing");
} catch (IOException e){
line1.setText("[Input 1]Connection failed on port: " + socket1);
line1.setForeground(Color.RED);
}
}
Refresh JFrame during try/catch statement
Page 1 of 11 Replies - 767 Views - Last Post: 30 September 2013 - 03:03 PM
#1
Refresh JFrame during try/catch statement
Posted 30 September 2013 - 02:54 PM
I am creating a server in my java program. During the creation of the server I have set some JLabels to say certain text. Although the JLabels only actually change after the client application has closed. Does anyone know how to make them update in real time. Here is my code:
Replies To: Refresh JFrame during try/catch statement
#2
Re: Refresh JFrame during try/catch statement
Posted 30 September 2013 - 03:03 PM
If you change a JComponent it will call its repaint() so the JFrame into which it is will be refresh as soon as the painting treah will be available again
And this will never be true
if(text != null){
readLine() does never return null... or may be if the Client disconnect
*edited: may be readLine may return null
And this will never be true
if(text != null){
readLine() does never return null... or may be if the Client disconnect
*edited: may be readLine may return null
This post has been edited by pbl: 30 September 2013 - 03:06 PM
Page 1 of 1

New Topic/Question
Reply


MultiQuote



|