Project

General

Profile

Revision 471

Added by Greg Tress about 16 years ago

fixed image refresh

View differences:

trunk/code/projects/colonet/ColonetGUI/Colonet.java
1035 1035
	*/
1036 1036
	class WebcamLoader extends Thread 
1037 1037
	{
1038
		final int WEBCAMLOADER_DELAY = 400;
1038
		final int WEBCAMLOADER_DELAY = 300;
1039 1039
		final String IMAGE_PATH = "http://roboclub9.frc.ri.cmu.edu/colonet.jpg";
1040 1040
				
1041 1041
		URL imagePath;
1042 1042
		
1043 1043
		MediaTracker mt;
1044 1044
		BufferedImage image;
1045
		Random rand;
1045 1046
		
1046 1047
		public WebcamLoader (JApplet applet)
1047 1048
		{
1048 1049
			super("ColonetWebcamLoader");
1049 1050
			mt = new MediaTracker(applet);
1050 1051
			ImageIO.setUseCache(false);
1051
			try {
1052
				imagePath = new URL(IMAGE_PATH);
1053
			} catch (MalformedURLException e) {
1054
				System.out.println("Malformed URL: could not form URL from: [" + IMAGE_PATH + "]\n");
1055
			}
1056
			
1052
			rand = new Random();
1057 1053
		}
1058 1054
		
1059 1055
		public void run ()
......
1064 1060
					if (image != null) 
1065 1061
						image.flush();
1066 1062
					System.gc();
1063
					try {
1064
				        imagePath = new URL(IMAGE_PATH + "?rand=" + rand.nextInt(50000));
1065
			        } catch (MalformedURLException e) {
1066
				        System.out.println("Malformed URL: could not form URL from: [" + IMAGE_PATH + "]\n");
1067
			        }
1067 1068
					image = ImageIO.read(imagePath);
1068 1069
					// The MediaTracker waitForID pauses the thread until the image is loaded.
1069 1070
					// We don't want to display a half-downloaded image.

Also available in: Unified diff