public static void main(String[] args) { try { // The image is loaded either from this // default filename or the first command- // line argument. // The second command-line argument specifies // what string will be displayed. The third // specifies at what point in the string the // background color will change. String filename = "Raphael.jpg"; String message = "Java2D"; int split = 4; if (args.length > 0) filename = args[0]; if (args.length > 1) message = args[1]; if (args.length > 2) split = Integer.parseInt(args[2]); ApplicationFrame f = new ApplicationFrame("ShowOff v1.0"); f.setLayout(new BorderLayout()); ShowOff showOff = new ShowOff(filename, message, split); f.add(showOff, BorderLayout.CENTER); f.setSize(f.getPreferredSize()); f.center(); f.setResizable(false); f.setVisible(true); } catch (Exception e) { System.out.println(e); System.exit(0); } }
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == 67) // C { if (captureWindow) { this.openCaptureWindow(); } else { this.captureImage(); } } else if (e.getKeyCode() == 27) // Escape { System.out.println("Escape pressed, exiting"); System.exit(0); } else if (e.getKeyCode() == 84) // t { // Testing purpose for (int i = 0; i < images.size(); i++) { System.out.println("image " + i + ", used? " + images_used.contains((Integer) i)); } } else if (e.getKeyCode() == 89) // y { // Testing purpose System.out.println("getRandomImageNum() = " + getRandomImageNum()); } else if (e.getKeyCode() == 73) // i { // Testing purpose System.out.println("LAST ADDED"); for (int i = 0; i < images_lastadded.size(); i++) { System.out.println( i + " - image " + images_lastadded.get(i) + ", used? " + images_used.contains((Integer) images_lastadded.get(i))); } } else if (e.getKeyCode() == 85) // u { // Testing purpose for (int i = 0; i < imagepanels.length; i++) { for (int j = 0; j < imagepanels[i].imagenum_now.length; j++) { for (int j2 = 0; j2 < imagepanels[i].imagenum_now[j].length; j2++) { String print1; if (imagepanels[i].imagenum_now[j][j2] < 10) print1 = " " + imagepanels[i].imagenum_now[j][j2]; else if (imagepanels[i].imagenum_now[j][j2] < 100) print1 = " " + imagepanels[i].imagenum_now[j][j2]; else print1 = "" + imagepanels[i].imagenum_now[j][j2]; String print2; if (imagepanels[i].imagenum_next[j][j2] < 10) print2 = " " + imagepanels[i].imagenum_next[j][j2]; else if (imagepanels[i].imagenum_next[j][j2] < 100) print2 = " " + imagepanels[i].imagenum_next[j][j2]; else print2 = "" + imagepanels[i].imagenum_next[j][j2]; System.out.println( "imagepanels[" + i + "]." + "imagenum_now[" + j + "][" + j2 + "] = " + print1 + ", next = " + print2); } } } } else { displayInfo(e, "KEY TYPED: "); } }
public WebcamCaptureAndFadePanel(String saveDir, String layout) { System.out.println("Using " + saveDir + " as directory for the images."); saveDirectory = saveDir; getImages(); images_used = new ArrayList<Integer>(); images_lastadded = new ArrayList<Integer>(); images_nevershown = new ArrayList<Integer>(); Vector devices = (Vector) CaptureDeviceManager.getDeviceList(null).clone(); Enumeration enumeration = devices.elements(); System.out.println("- Available cameras -"); ArrayList<String> names = new ArrayList<String>(); while (enumeration.hasMoreElements()) { CaptureDeviceInfo cdi = (CaptureDeviceInfo) enumeration.nextElement(); String name = cdi.getName(); if (name.startsWith("vfw:")) { names.add(name); System.out.println(name); } } // String str1 = "vfw:Logitech USB Video Camera:0"; // String str2 = "vfw:Microsoft WDM Image Capture (Win32):0"; if (names.size() == 0) { JOptionPane.showMessageDialog( null, "Ingen kamera funnet. " + "Du må koble til et kamera for å kjøre programmet.", "Feil", JOptionPane.ERROR_MESSAGE); System.exit(0); } else if (names.size() > 1) { JOptionPane.showMessageDialog( null, "Fant mer enn 1 kamera. " + "Velger da:\n" + names.get(0), "Advarsel", JOptionPane.WARNING_MESSAGE); } String str2 = names.get(0); di = CaptureDeviceManager.getDevice(str2); ml = di.getLocator(); try { player = Manager.createRealizedPlayer(ml); formatControl = (FormatControl) player.getControl("javax.media.control.FormatControl"); /* Format[] formats = formatControl.getSupportedFormats(); for (int i=0; i<formats.length; i++) System.out.println(formats[i].toString()); */ player.start(); } catch (javax.media.NoPlayerException e) { JOptionPane.showMessageDialog( null, "Klarer ikke å starte" + " programmet pga. feil med kamera. Sjekk at det er koblet til.", "IOException", JOptionPane.ERROR_MESSAGE); System.exit(0); } catch (Exception e) { e.printStackTrace(); System.exit(0); } /* * Layout * * Add * - comp * - imagepanels */ if (layout.equals("1024v2")) { layout1024v2(); } else if (layout.equals("1280")) { layout1280(); } else { layout1024(); } // Capture Window if (captureWindow) { cw = new JFrame("Capture from webcam"); cw.setAlwaysOnTop(true); cw.setSize(sizeCaptureWindow_x, sizeCaptureWindow_y); cw.addKeyListener(new captureWindowKeyListner()); cw.setUndecorated(true); // Add webcam if ((comp = player.getVisualComponent()) != null) { cw.add(comp); } // Add panel to window and set location of window cw.setLocation(cwLocation_x, cwLocation_y); } // Text window cwText = new rotatedText(""); /* * Timer for update */ Timer thread = new Timer(); thread.schedule(new frameUpdateTask(), 0, (1000 / fps)); }
@Override public void keyPressed(KeyEvent arg0) { if (arg0.getKeyCode() == 67) // C { // Are we allowed to capture a new image? if (framenr - lastcapture_framenr > number_of_frames_betweencaptures) { captureImage(); cw.setVisible(false); if (timer != null) timer.cancel(); cwText.setText(""); // Empty text lastcapture_framenr = framenr; cwTimer.cancel(); if (number_of_second_showcapturetext > 0) { cwText.setText("Bildet ble lagret ..."); TimerTask task = new TimerTask() { @Override public void run() { EventQueue.invokeLater( new Runnable() { public void run() { cwText.setText(""); // Empty text } }); } }; timer = new Timer(); timer.schedule(task, (int) (number_of_second_showcapturetext * 1000)); } } else { // Console debug: // System.out.println("At framenr " + framenr + ", " + (framenr-lastcapture_framenr) + // "frames has passed, should be " +number_of_frames_betweencaptures); // System.out.println("You must wait an other "+ // // (int)Math.ceil(((double)number_of_frames_betweencaptures-(double)(framenr-lastcapture_framenr))/fps) + // " seconds"); TimerTask task = new TimerTask() { boolean finished = false; @Override public void run() { EventQueue.invokeLater( new Runnable() { public void run() { if (!finished) { if ((int) Math.ceil( ((double) number_of_frames_betweencaptures - (double) (framenr - lastcapture_framenr)) / fps) > 0) { cwText.setText( "Du må vente " + (int) Math.ceil( ((double) number_of_frames_betweencaptures - (double) (framenr - lastcapture_framenr)) / fps) + " sekunder før nytt bilde"); } else { finished = true; cwText.setText("Du kan nå ta nytt bilde"); } } } }); } }; timer = new Timer(); timer.schedule(task, 0, (1000 / fps)); // Update for every frame } } else if (arg0.getKeyCode() == 27) // Escape { System.out.println("Escape pressed, exiting"); System.exit(0); } }