View Javadoc
1 package krico.camserv; 2 import java.applet.Applet; 3 import java.net.URL; 4 import java.awt.*; 5 import java.awt.event.*; 6 /*** 7 * This is an applet for camserv webcam server 8 * 9 * The applet can be called with the following HTML 10 *<pre> 11 *<html> 12 *<body> 13 *<applet code="krico.camserv.WebCam.class" width="330" height="300" archive="WebCam.jar"> 14 *<param name="camservURL" value="http://localhost:9192"> 15 *<param name="imageWidth" value="320"> 16 *<param name="imageHeight" value="240"> 17 *<param name="br" value="0"> 18 *<param name="bg" value="0"> 19 *<param name="bb" value="0"> 20 *<param name="fr" value="255"> 21 *<param name="fg" value="255"> 22 *<param name="fb" value="255"> 23 *<param name="sleep" value="100"> 24 *<param name="showButtons" value="false"> 25 *</applet> 26 *</body> 27 *</html> 28 *</pre> 29 * @author <a href="mailto:krico@users.sourceforge.net">Christian Asmussen</a> 30 */ 31 public class WebCam extends Applet implements ActionListener{ 32 int imW = 320; 33 int imH = 240; 34 URL camserv; 35 boolean ok = true; 36 Thread timer; 37 long sleep = 100; 38 WebPanel panel; 39 boolean showbuttons = true; 40 public void start(){ 41 if(panel.getGo()) return; 42 timer = new Thread(panel); 43 panel.setGo(true); 44 timer.start(); 45 } 46 public void stop(){ 47 if(!panel.getGo()) return; 48 panel.setGo(false); 49 } 50 public void actionPerformed(ActionEvent ae){ 51 String action = ae.getActionCommand(); 52 System.out.println("Action is: " + action); 53 if("START".equals(action)){ 54 if(panel.getGo()) return; 55 timer = new Thread(panel); 56 panel.setGo(true); 57 timer.start(); 58 return; 59 } 60 if("STOP".equals(action)){ 61 if(!panel.getGo()) return; 62 panel.setGo(false); 63 return; 64 } 65 } 66 public void destroy(){ 67 panel.setGo(false); 68 } 69 public void init(){ 70 String serv = getParameter("camservURL"); 71 72 try{ 73 camserv = new URL(serv); 74 }catch(Exception e){ 75 ok = false; 76 } 77 Color bg; 78 try{ 79 imW = new Integer(getParameter("imageWidth")).intValue(); 80 imH = new Integer(getParameter("imageHeight")).intValue(); 81 }catch(Exception e){ 82 System.err.println("Could not get \"imageWidth\" or \"imageHeight\" parameters"); 83 } 84 try{ 85 sleep = new Long(getParameter("sleep")).longValue(); 86 }catch(Exception e){ 87 System.err.println("Could not get sleep time"); 88 } 89 String showButtonsString = getParameter("showButtons"); 90 try{ 91 showbuttons = new Boolean(showButtonsString).booleanValue(); 92 }catch(Exception e){}; 93 try{ 94 int r = new Integer(getParameter("br")).intValue(); 95 int g = new Integer(getParameter("bg")).intValue(); 96 int b = new Integer(getParameter("bb")).intValue(); 97 bg = new Color(r,g,b); 98 if(bg != null) 99 setBackground(bg); 100 }catch(Exception e){ 101 System.err.println("Could not get Background color, using default: " + getBackground()); 102 } 103 try{ 104 int r = new Integer(getParameter("fr")).intValue(); 105 int g = new Integer(getParameter("fg")).intValue(); 106 int b = new Integer(getParameter("fb")).intValue(); 107 bg = new Color(r,g,b); 108 if(bg != null) 109 setForeground(bg); 110 }catch(Exception e){ 111 System.err.println("Could not get Foreground color, using default: " + getBackground()); 112 } 113 if(!ok) System.err.println("Could not get url for camserv \"" + serv + "\""); 114 buildUI(); 115 } 116 void buildUI(){ 117 GridBagLayout gridbag = new GridBagLayout(); 118 GridBagConstraints c = new GridBagConstraints(); 119 setLayout(gridbag); 120 121 panel = new WebPanel(this,camserv,imW,imH,sleep); 122 c.fill = GridBagConstraints.BOTH; 123 124 c.weightx = 1.0; 125 if(showbuttons){ 126 Button b1 = new Button("Start"); 127 b1.setActionCommand("START"); 128 b1.addActionListener(this); 129 gridbag.setConstraints(b1,c); 130 add(b1); 131 c.gridwidth = GridBagConstraints.REMAINDER; 132 Button b2 = new Button("Stop"); 133 b2.setActionCommand("STOP"); 134 b2.addActionListener(this); 135 gridbag.setConstraints(b2,c); 136 add(b2); 137 } 138 gridbag.setConstraints(panel,c); 139 add(panel); 140 } 141 /*** 142 * The applet can be called with the following HTML 143 *<pre> 144 *<html> 145 *<body> 146 *<applet code="krico.camserv.WebCam.class" width="330" height="300" archive="WebCam.jar"> 147 *<param name="camservURL" value="http://localhost:9192"> 148 *<param name="imageWidth" value="320"> 149 *<param name="imageHeight" value="240"> 150 *<param name="br" value="0"> 151 *<param name="bg" value="0"> 152 *<param name="bb" value="0"> 153 *<param name="fr" value="255"> 154 *<param name="fg" value="255"> 155 *<param name="fb" value="255"> 156 *<param name="sleep" value="100"> 157 *</applet> 158 *</body> 159 *</html> 160 *</pre> 161 */ 162 public String [][]getParameterInfo(){ 163 return new String[][]{ 164 {"camservURL","URL","This should be the url for the camserv server, it should be the same domain as the html page"}, 165 {"imageWidth","integer","The width of the image produced by the camserv"}, 166 {"imageHeight","integer","The height of the image produced by the camserv"}, 167 {"br" , "0-255", "The background R of RGB"}, 168 {"bg", "0-255","The background G of RGB"}, 169 {"bb", "0-255","The background B of RGB"}, 170 {"fr" , "0-255", "The foreground R of RGB"}, 171 {"fg", "0-255","The foreground G of RGB"}, 172 {"fb", "0-255","The foreground B of RGB"}, 173 {"sleep", "long","The time between image updates"} 174 }; 175 } 176 public String getAppletInfo(){ 177 return "WebCam Applet by Krico"; 178 } 179 180 } 181 182 183 184 185 186 187 188 189 190

This page automatically generated by Maven