hi stuck on this webcam program that i found on the internet that i was using to join another class up that splits and put a captured image on the left side from the web cam and then display a ramdom number of images can anyone help me out so i can progress further here is the code
/* * CaptureImage.java * * Created on 25-Feb-2009, 19:58:34 * * To change this template, choose Tools | Templates * and open the template in the editor. */ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.awt.image.*; import com.sun.image.codec.jpeg.*; import javax.media.*; import javax.media.format.*; import javax.media.util.*; import javax.media.control.*; import javax.media.protocol.*; /** * * @author clive */ public class CaptureImage extends JFrame implements ActionListener { public static Player player = null; public CaptureDeviceInfo di = null; public MediaLocator ml = null; public JButton capture = null; public Buffer buf = null; public Image img = null; public VideoFormat vf = null; public BufferToImage btoi = null; //public ImagePanel leftPane = null; public CaptureImage() { setLayout(new BorderLayout()); setSize(320,550); // imgpanel = new ImagePanel(); capture = new JButton("Capture"); capture.addActionListener(this); String str1 = "vfw:Logitech USB Video Camera:0"; String str2 = "vfw:Microsoft WDM Image Capture (Win32):0"; di = CaptureDeviceManager.getDevice(str2); ml = di.getLocator(); try { player = Manager.createRealizedPlayer(ml); player.start(); Component comp; if ((comp = player.getVisualComponent()) != null) { add(comp,BorderLayout.NORTH); } add(capture,BorderLayout.CENTER); // add(imgpanel,BorderLayout.SOUTH); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { Frame f = new Frame("SwingCapture"); CaptureImage cf = new CaptureImage(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { playerclose(); System.exit(0);}}); f.add("Center",cf); f.pack(); f.setSize(new Dimension(320,550)); f.setVisible(true); } public static void playerclose() { player.close(); player.deallocate(); } public void actionPerformed(ActionEvent e) { JComponent c = (JComponent) e.getSource(); if (c == capture) { // Grab a frame FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl"); buf = fgc.grabFrame(); // Convert it to an image btoi = new BufferToImage((VideoFormat)buf.getFormat()); img = btoi.createImage(buf); // show the image leftPane.setImage(img); //new leftPane(); new displayTwoImages(); //JFrame a = new leftPane(); } } }// cam work here but will not interact with the class as showing up a JPanel and displaying the capture image
class displayTwoImages extends CaptureImage { private JPanel p; public displayTwoImages(){ Container c = getContentPane(); //set colour of background c.setBackground(Color.black); //set Layout Manager //c.setBackground(new BorderLayout()); // instantiate Panel object p = new JPanel(); JPanel leftPane = new JPanel(); // add components to it JPanel rightPane = new JPanel(); // add components to it JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane, rightPane); setContentPane(split); // add Panel to container c.add("South", p); } public static void main(String []args){ JFrame f = new displayTwoImages(); JFrame a = new leftPane(); // JFrame f = new displayTwoImages(); f.setSize(400, 100); f.show(); } } class leftPane extends displayTwoImages { public Image myimg = null; public void leftPane(){ setLayout(null); } public void setImage(Image img) { this.myimg = img; repaint(); } public void paint(Graphics g) { if (myimg != null) { g.drawImage(myimg, 0, 0, this); } } // this class is suppost to show in the JPanel on the right split side and do random images class rightPane extends displayTwoImages { public Image image1; public int random1; boolean match = false; public void rightPane(){ Image[] imageSet = new Image[6]; // code work better than the getImage(getCodeBase imageSet[0] = Toolkit.getDefaultToolkit().getImage("bugs-bunny-gangsta-psd16705.png"); //imageSet[1] = getImage(getCodeBase(),""); //imageSet[2] = getImage(getCodeBase(),""); //imageSet[3] = getImage(getCodeBase(),""); // here having problem with //imageSet[4] = getImage(getCodeBase(),""); //imageSet[5] = getImage(getCodeBase(),""); for(int i = 0; i < 6; i++){ // for each image to change ramdom number of time through the database of images random1 = (int)(Math.random()*6); image1 = imageSet[random1]; } } public boolean action(Event evt, Object arg){ repaint(); return true; // spin(); } public void paint(Graphics g){ g.drawImage(image1, 100, 100, this); if(match){ g.drawString("MATCH", 200, 200); } } }