Click here to Skip to main content
13,087,235 members (54,595 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Guys, i wan to run a java program that using JMF to show webcam video in a browser..i tried applet but the result is negative..the applet running but view nothing..can someone help me on this..i paste here the java code..not the applet code..
any can help me??

import java.awt.BorderLayout;
import java.util.Vector;
import javax.swing.JFrame;

public class WebcamClass {
CaptureDeviceInfo cam;
MediaLocator locator;
Player player;
FormatControl formatControl;
public static void main ( String args [] ){
    WebcamClass camera = new WebcamClass();   
public WebcamClass(){
                    // List out available Devices to Capture Video.
        CaptureDeviceManager manager = new CaptureDeviceManager();
        //System.out.println("List device : " + manager.toString());
        Vector<capturedeviceinfo> list = manager.getDeviceList (null);
        System.out.println("List device : " + list.toString());
        for(CaptureDeviceInfo temp : list){
            // Checking whether the current device supports VfW
            // VfW = Video for Windows
            System.out.println("Found : "+temp.getName().substring(4));
            // Selecting the very first device that supports VfW
            cam = temp;
            System.out.println("Selected : "+cam.getName().substring(4));
        System.out.println("Put it on work!...");
        // Getting the MediaLocator for Selected device.
        // MediaLocator describes the location of media content
        //locator = cam.getLocator();
        String source = "vfw://0";
        //source = "";
        locator = new MediaLocator(source);
        if(locator != null){
System.out.println("locate :" + locator.toString());
            // Create a Player for Media Located by MediaLocator
            player = Manager.createRealizedPlayer(locator);
            if(player != null){
                // Starting the player
                // Creating a Frame to display Video
                JFrame f = new JFrame();
                f.setTitle("Display Webcam");
                f.setLayout(new BorderLayout());
                // Adding the Visual Component to display Video captured by Player
                // from URL provided by MediaLocator
                f.add(player.getVisualComponent(), BorderLayout.CENTER);
    }catch(Exception e){
Posted 3-Oct-12 23:35pm
Updated 3-Oct-12 23:41pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I don't know what you ae trying there - but that's no applet.

Follow this:
Applet Tutorial[^]

To get a valid applet. Also needs the browser to accept the Java Applet.
If that support is disabled by default, you might never notice the applet is there.
matpyam 5-Oct-12 7:49am
but i give above is the example of java program..
i already create the applet file..but when i run the applet using BlueJ, there are no output..through bluej aso i run the coding above, there are output..when i change it into applet..just applet window prompt that pop out and there is nothing in it..blank..
but, when i try the simple applet..applet "Hello World", it succeed..i also don no what is wrong with my coding or my desktop..:(
TorstenH. 5-Oct-12 8:23am
When the other applet is running, but your applet does not do so - then it's your applet that is not valid. Do you have any logging? Is there some interaction or is nothing happening? Try log4j, that's a common logging solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100