1 Replies - 767 Views - Last Post: 30 September 2013 - 03:03 PM Rate Topic: -----

#1 Alex A   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 02-March 13

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:

	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);
		}
	} 



Is This A Good Question/Topic? 0
  • +

Replies To: Refresh JFrame during try/catch statement

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

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

This post has been edited by pbl: 30 September 2013 - 03:06 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1