Project

General

Profile

Revision 517

Added by Greg Tress about 16 years ago

minor visual and network tweaks

View differences:

trunk/code/projects/colonet/client/Colonet.java
423 423
	}
424 424
	
425 425
	public void connect () {
426
	    lblConnectionStatus.setText("Status: Connecting...");
426 427
	    webcamLoader = new WebcamLoader(this);
427 428
		dataUpdater = new DataUpdater();
428
		paintThread = new Thread(this, "paintThread");
429 429
		csi = new ColonetServerInterface(this);
430 430
		csi.connect(txtHost.getText(), txtPort.getText());
431
		if (!csi.isReady())
431
		if (!csi.isReady()) {
432
		    lblConnectionStatus.setText("Status: Offline");
432 433
			return;
433
		btnConnect.setEnabled(false);
434
	    }
435
		btnConnect.setText("Disconnect");
434 436
		lblConnectionStatus.setText("Status: Connected");
435
		//paintThread.start();
436 437
		dataUpdater.start();
437 438
		webcamLoader.start();
438 439
	}
439 440
	
440 441
	public void disconnect () {
441
	    btnConnect.setEnabled(true);
442
	    lblConnectionStatus.setText("Status: Disconnecting...");
443
	    dataUpdater.interrupt();
444
	    csi.disconnect();
445
	    csi = null;
446
	    btnConnect.setText("Connect");
442 447
	    lblConnectionStatus.setText("Status: Disconnected");
443
	    try { paintThread.interrupt(); } catch (Exception e) { }
444
		
445 448
	}
446 449
	
447 450
	/**
......
699 702
		
700 703
		    // General Actions
701 704
		    if (source == btnConnect) {
702
			    connect();
705
		        if (csi == null)
706
			        connect();
707
			    else
708
			        disconnect();
703 709
		    } else if (source == btnGetXBeeIDs) {
704 710
			    csi.sendXBeeIDRequest();
705 711
		    } else if (source == btnAssignID) {
......
798 804
	*
799 805
	*/
800 806
	class DataUpdater extends Thread {
801
		final int DATAUPDATER_DELAY = 800;
807
		final int DATAUPDATER_DELAY = 400;
802 808
		
803 809
		public DataUpdater () {
804 810
			super("Colonet DataUpdater");
......
861 867
		BufferedImage buffer;
862 868
	
863 869
		public WebcamPanel () {
864
			super(false);
870
			super(true);
865 871
		}
866 872
		
867 873
		public synchronized void setImage (BufferedImage newimg) {
......
946 952
			
947 953
			//Display buffered content
948 954
			g.drawImage(buffer, 0, 0, this);
949
			txtMatrix.append("p");
950 955
		}
951 956
	
952 957
	}
trunk/code/projects/colonet/client/ColonetServerInterface.java
225 225
	}
226 226
	
227 227
	public void disconnect () {
228
	    
228
	    try {
229
	        reader.close();
230
	        out.close();
231
	    } catch (IOException e) {
232
	    }
229 233
	}
230 234
	
231 235
	/*
232
	*	sendString - only this method should actually write data to the output stream
236
	* Send a general String to the OutputStream.
233 237
	*/
234 238
	private void sendString (String s) {
235 239
		//make sure we can send
......
272 276
		String packet = "";
273 277
		packet += ColonetServerInterface.SEND_TO_ROBOT;
274 278
		if (robotNumber != null)
275
			packet += " " + 7;  //robotNumber;
279
			packet += " " + robotNumber;
276 280
		packet += " " + ColonetServerInterface.COLONET_COMMAND;
277 281
		packet += " " + s;  //add  the command code here
278 282
		packet += "\n";

Also available in: Unified diff