Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: stuck on this program can any one help me

  1. #1
    Junior Member
    Join Date
    Mar 2009
    Thanked 0 Times in 0 Posts

    Default stuck on this program can any one help me

    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());
       // imgpanel = new ImagePanel();
        capture = new JButton("Capture");
        String str1 = "vfw:Logitech USB Video Camera:0";
        String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
        di = CaptureDeviceManager.getDevice(str2);
        ml = di.getLocator();
          player = Manager.createRealizedPlayer(ml);
          Component comp;
          if ((comp = player.getVisualComponent()) != null)
        //  add(imgpanel,BorderLayout.SOUTH);
        catch (Exception e) 
       public static void main(String[] args) 
        Frame f = new Frame("SwingCapture");
        CaptureImage cf = new CaptureImage();
        f.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
        f.setSize(new Dimension(320,550));
      public static void playerclose() 
      public void actionPerformed(ActionEvent e) 
        JComponent c = (JComponent) e.getSource();
        if (c == capture) 
          // Grab a frame
          FrameGrabbingControl fgc = (FrameGrabbingControl)
          buf = fgc.grabFrame();
          // Convert it to an image
          btoi = new BufferToImage((VideoFormat)buf.getFormat());
          img = btoi.createImage(buf);
          // show the image
          //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
            //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);
            // 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);
    class leftPane extends displayTwoImages {
       public Image myimg = null;
        public void leftPane(){ 
        public void setImage(Image img) {
          this.myimg = img;
        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){
            return true;
          //  spin();
        public void paint(Graphics g){
            g.drawImage(image1, 100, 100, this);
                g.drawString("MATCH", 200, 200);

  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    United Kingdom
    My Mood
    Thanked 294 Times in 227 Posts
    Blog Entries

    Default Re: stuck on this program can any one help me

    Hello clive and welcome to the forums.

    What is the URL of the website where you got this code? I'd like to see if there is any documentation.

    Have you tried to compile the code? What are you stuck on exactly?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Mar 2009
    Thanked 0 Times in 0 Posts

    Default Re: stuck on this program can any one help me

    hi it when i press the button i am trying to get another JPanel to load up with it being split with capturing the image of the webcam that on the left but can't get it to load the JPanel and the image on the left side of the JPane i have tried everything that i can think of but find my self not getting any where

    here is the place where i got the code from to help me out with a webcam hope it helps

    Java Media Framework - Capture webcam success! Now how to make it repeat itself??

Similar Threads

  1. Replies: 24
    Last Post: April 14th, 2009, 03:43 PM
  2. Problem while programming a simple game of Car moving on a road
    By rojroj in forum Java Theory & Questions
    Replies: 3
    Last Post: April 2nd, 2009, 10:24 AM