Click here to Skip to main content
12,761,018 members (30,538 online)

Running java program in a browser?

matpyam asked:

Open original thread
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){
Tags: Java


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 26 Mar 2009
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