소스 검색

添加摄像头测试

wutt 5 년 전
부모
커밋
a8200522dd

+ 4 - 0
KeyMonitorApp/bin/.gitignore

@@ -12,3 +12,7 @@
 /WindowsKeybordListener$1.class
 /WindowsKeybordListener.class
 /jdbc.properties
+/Test$1$1.class
+/Test$1.class
+/Test$2$1.class
+/Test$2.class

BIN
KeyMonitorApp/bin/Code.class


BIN
KeyMonitorApp/bin/JdbcCodeDao.class


BIN
KeyMonitorApp/bin/PropertyUtil.class


BIN
KeyMonitorApp/bin/Test.class


BIN
KeyMonitorApp/bin/TestWebCam$1$1.class


BIN
KeyMonitorApp/bin/TestWebCam$1.class


BIN
KeyMonitorApp/bin/TestWebCam.class


+ 21 - 23
KeyMonitorApp/src/Code.java

@@ -1,23 +1,21 @@
-import java.util.Date;
-
-public class Code {
-	private String name;
-	private String indate;
-	public String getName() {
-		return name;
-	}
-	public void setName(String name) {
-		this.name = name;
-	}
-	public String getIndate() {
-		return indate;
-	}
-	public void setIndate(String indate) {
-		this.indate = indate;
-	}
-	@Override
-	public String toString() {
-		return "Code [name=" + name + ", indate=" + indate + "]";
-	}
-	
-}
+public class Code {
+	private String name;
+	private String indate;
+	public String getName() {
+		return name;
+	}
+	public void setName(String name) {
+		this.name = name;
+	}
+	public String getIndate() {
+		return indate;
+	}
+	public void setIndate(String indate) {
+		this.indate = indate;
+	}
+	@Override
+	public String toString() {
+		return "Code [name=" + name + ", indate=" + indate + "]";
+	}
+	
+}

+ 4 - 1
KeyMonitorApp/src/JdbcCodeDao.java

@@ -19,7 +19,10 @@ public class JdbcCodeDao implements CodeDao {
 	
 	public static void readJdbcProperties() {
 		Properties props = new Properties();
-		InputStream in = PropertyUtil.class.getResourceAsStream("/jdbc.properties");
+		// 第一种,通过类加载器进行获取properties文件流-->
+//		InputStream in = JdbcCodeDao.class.getClassLoader().getResourceAsStream("db.properties");
+      // 第二种,通过类进行获取properties文件流-->
+		InputStream in = JdbcCodeDao.class.getResourceAsStream("/jdbc.properties");
         try {
 			props.load(in);
 			driverClassName = props.getProperty("driver");

+ 0 - 59
KeyMonitorApp/src/PropertyUtil.java

@@ -1,59 +0,0 @@
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-public class PropertyUtil {
-    
-    private static Properties props;
-    static {
-        loadProps();
-    }
-
-    synchronized static private void loadProps(){
-        System.out.println("开始加载properties文件内容.......");
-        props = new Properties();
-        InputStream in = null;
-        try {
-            // 第一种,通过类加载器进行获取properties文件流-->
-//            in = PropertyUtil.class.getClassLoader().getResourceAsStream("db.properties");
-            // 第二种,通过类进行获取properties文件流-->
-            in = PropertyUtil.class.getResourceAsStream("/jdbc.properties");
-            props.load(in);
-        } catch (FileNotFoundException e) {
-            System.out.println("jdbc.properties文件未找到");
-        } catch (IOException e) {
-            System.out.println("出现IOException");
-        } finally {
-            try {
-                if(null != in) {
-                    in.close();
-                }
-            } catch (IOException e) {
-                System.out.println("jdbc.properties文件流关闭出现异常");
-            }
-        }
-        System.out.println("加载properties文件内容完成...........");
-        System.out.println("properties文件内容:" + props);
-    }
-
-    /**
-     * 根据key获取配置文件中的属性
-     */
-    public static String getProperty(String key){
-        if(null == props) {
-            loadProps();
-        }
-        return props.getProperty(key);
-    }
-
-    /**
-     * 根据key获取配置文件中的属性,当为null时返回指定的默认值
-     */
-    public static String getProperty(String key, String defaultValue) {
-        if(null == props) {
-            loadProps();
-        }
-        return props.getProperty(key, defaultValue);
-    }
-}

+ 73 - 12
KeyMonitorApp/src/Test.java

@@ -1,12 +1,73 @@
-
-public class Test {
-	private static JdbcCodeDao dao = new JdbcCodeDao();
-	public static void main(String[] args) {
-//		Code code = new Code();
-//		code.setName("aaaaa");
-//		dao.add(code);
-		Code findByName = dao.findByName("aaaaa");
-		System.out.println(findByName);
-	}
-
-}
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+
+public class Test {
+	private static final JButton button = new JButton("拍照");
+	private static JdbcCodeDao dao = new JdbcCodeDao();
+	public static void main(String[] args) {
+////		Code code = new Code();
+////		code.setName("aaaaa");
+////		dao.add(code);
+//		Code findByName = dao.findByName("aaaaa");
+//		System.out.println(findByName);
+//	}
+		JFrame window = new JFrame("摄像头");
+		window.setResizable(true);
+		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+		window.pack();
+		window.setVisible(true);
+
+
+
+//		window.add(panel, BorderLayout.CENTER);
+		window.add(button, BorderLayout.SOUTH);
+		window.setResizable(true);
+		window.pack();
+		window.setVisible(true);
+		button.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e){
+				//定时模拟触发
+//				button.doClick();
+				button.setEnabled(false);  //设置按钮不可点击
+
+
+				//实现拍照保存-------start
+//				String fileName = "D://" + System.currentTimeMillis();       //保存路径即图片名称(不用加后缀)
+//				WebcamUtils.capture(webcam, fileName, ImageUtils.FORMAT_PNG);
+				SwingUtilities.invokeLater(new Runnable() {
+
+					@Override
+					public void run(){
+						System.out.println("点击了");
+						JOptionPane.showMessageDialog(null, "拍照成功");
+						button.setEnabled(true);    //设置按钮可点击
+
+						return;
+					}
+				});
+				//实现拍照保存-------end
+
+			}
+		});
+	for(int i=0;i<10;i++) {
+		Thread thread = new Thread(new Runnable() {
+			
+			@Override
+			public void run() {
+				// TODO Auto-generated method stub
+				button.doClick();
+			}
+		});
+		thread.start();
+	}
+	
+	
+}
+
+}

+ 79 - 78
KeyMonitorApp/src/TestWebCam.java

@@ -1,78 +1,79 @@
-import java.awt.BorderLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JOptionPane;
-import javax.swing.SwingUtilities;
-
-import com.github.sarxos.webcam.Webcam;
-import com.github.sarxos.webcam.WebcamPanel;
-import com.github.sarxos.webcam.WebcamResolution;
-import com.github.sarxos.webcam.WebcamUtils;
-import com.github.sarxos.webcam.util.ImageUtils;
-
-/**
- * 相机测试
- */
-public class TestWebCam {
- 
-	private static JFrame window;
- 
-	public static void main(String[] args) throws InterruptedException {
- 
-		Webcam webcam = Webcam.getDefault();
-		webcam.setViewSize(WebcamResolution.VGA.getSize());
- 
-		WebcamPanel panel = new WebcamPanel(webcam);
-		panel.setFPSDisplayed(true);
-		panel.setDisplayDebugInfo(true);
-		panel.setImageSizeDisplayed(true);
-		panel.setMirrored(true);
- 
-		JFrame window = new JFrame("Test webcam panel");
-		window.add(panel);
-		window.setResizable(true);
-		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		window.pack();
-		window.setVisible(true);
- 
- 
- 
-		final JButton button = new JButton("拍照");
-		window.add(panel, BorderLayout.CENTER);
-		window.add(button, BorderLayout.SOUTH);
-		window.setResizable(true);
-		window.pack();
-		window.setVisible(true);
-		button.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent e){
-				//定时模拟触发
-				button.doClick();
-				button.setEnabled(false);  //设置按钮不可点击
- 
- 
-				//实现拍照保存-------start
-				String fileName = "D://" + System.currentTimeMillis();       //保存路径即图片名称(不用加后缀)
-				WebcamUtils.capture(webcam, fileName, ImageUtils.FORMAT_PNG);
-				SwingUtilities.invokeLater(new Runnable() {
- 
-					@Override
-					public void run(){
-						JOptionPane.showMessageDialog(null, "拍照成功");
-						button.setEnabled(true);    //设置按钮可点击
- 
-						return;
-					}
-				});
-				//实现拍照保存-------end
- 
-			}
-		});
-	}
-}
- 
- 
- 
- 
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+
+import com.github.sarxos.webcam.Webcam;
+import com.github.sarxos.webcam.WebcamPanel;
+import com.github.sarxos.webcam.WebcamResolution;
+import com.github.sarxos.webcam.WebcamUtils;
+import com.github.sarxos.webcam.util.ImageUtils;
+
+/**
+ * 相机测试
+ */
+public class TestWebCam {
+ 
+	private static JFrame window;
+ 
+	public static void main(String[] args) throws InterruptedException {
+ 
+		Webcam webcam = Webcam.getDefault();
+		webcam.setViewSize(WebcamResolution.VGA.getSize());
+//		webcam.open();
+ 
+		WebcamPanel panel = new WebcamPanel(webcam);
+		panel.setFPSDisplayed(true);
+		panel.setDisplayDebugInfo(true);
+		panel.setImageSizeDisplayed(true);
+		panel.setMirrored(true);
+ 
+		JFrame window = new JFrame("Test webcam panel");
+		window.add(panel);
+		window.setResizable(true);
+		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+		window.pack();
+		window.setVisible(true);
+ 
+ 
+ 
+		final JButton button = new JButton("拍照");
+		window.add(panel, BorderLayout.CENTER);
+		window.add(button, BorderLayout.SOUTH);
+		window.setResizable(true);
+		window.pack();
+		window.setVisible(true);
+		button.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e){
+				//定时模拟触发
+				button.doClick();
+				button.setEnabled(false);  //设置按钮不可点击
+ 
+ 
+				//实现拍照保存-------start
+				String fileName = "D://" + System.currentTimeMillis();       //保存路径即图片名称(不用加后缀)
+				WebcamUtils.capture(webcam, fileName, ImageUtils.FORMAT_PNG);
+				SwingUtilities.invokeLater(new Runnable() {
+ 
+					@Override
+					public void run(){
+						JOptionPane.showMessageDialog(null, "拍照成功");
+						button.setEnabled(true);    //设置按钮可点击
+ 
+						return;
+					}
+				});
+				//实现拍照保存-------end
+ 
+			}
+		});
+	}
+}
+ 
+ 
+ 
+