⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 camcontroller.java

📁 Its video trNSMITT FILE USING JMF
💻 JAVA
字号:
/*  CamController.java
 *
 *	Application which allows user to control a web cam remotely.
 *
 *  Copyright (C) 2002 by Frank McCown
 *  University of Arkansas at Little Rock
 *  July 2002
 *
 */

import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.PortableServer.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class CamController extends JFrame
{
	public JPanel videoViewer;
	
	public static String hostName = "";   // This computer's host name
	public static org.omg.CORBA.ORB orb;
	public static rowc.MediaStore mediaStore;
	public static rowc.Registration regObject;
	public static NamingContext nc;

	public static boolean connectedToServer = false;  // Keep track of whether binded to Server
	
	private final String PROPERTY_FILE = "project.conf";
	
		
	public CamController(String args[])
	{
		System.out.println("initializing...");
		
		initCorba(args);
		
		// Determine this computer's ip address
		try 
		{
			java.net.InetAddress ia = java.net.InetAddress.getLocalHost();
			hostName = ia.getHostName();
			System.out.println("InetAddress = "+ia);
		}
		catch (java.net.UnknownHostException ex)
		{
			ex.printStackTrace();
		}
		
		// Call constructor AFTER getting ORB up because of ORB-dependent methods in VideoViewer
		videoViewer = new VideoViewer();
		
		JPanel contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(new BorderLayout());
    this.setSize(new Dimension(580, 580));
    this.setTitle("Cam Controller");

    contentPane.add(videoViewer, BorderLayout.CENTER);
    
    show();
	}
	
	private void initCorba(String commandLineArgs[])
	{
		System.out.println("Initializing CORBA... ");
		
		try
		{
  	  // Initialize the ORB
			java.util.Properties props = System.getProperties();
			
			try
			{
				// Read properties from project property file that indicates location
				// of Name and Event Services.

				FileInputStream f = new FileInputStream(PROPERTY_FILE);
				props.load(f);
				f.close();
			}
			catch (FileNotFoundException e)
			{
				// Got this most likely because app is being ran in Java Web Start.
				// Need to load property file differently.
				
				ClassLoader cl = this.getClass().getClassLoader(); 
   			java.net.URL url = cl.getResource(PROPERTY_FILE);
				props.load(url.openStream());
			}
		
  		props.setProperty("org.omg.CORBA.ORBClass", "com.ooc.CORBA.ORB");
  		props.setProperty("org.omg.CORBA.ORBSingletonClass",
                "com.ooc.CORBA.ORBSingleton");

     	orb = org.omg.CORBA.ORB.init(commandLineArgs, props);
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return;
		}

		try
		{
			// Find MediaStore using Naming Service
			nc = NamingContextHelper.narrow(
					orb.resolve_initial_references("NameService"));
			
	    // Resolve names with the Naming Service
	    NameComponent[] ncArray = new NameComponent[1];
	    ncArray[0] = new NameComponent("MediaStore","");
	    mediaStore = rowc.MediaStoreHelper.narrow(nc.resolve(ncArray));
			
			ncArray[0] = new NameComponent("Registration","");
			regObject = rowc.RegistrationHelper.narrow(nc.resolve(ncArray));
						
	    POA rootPOA = 
					POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
      
			// Create policies for our persistent POA and activate

      org.omg.CORBA.Policy[] policies = { 
        rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT),
        rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID) 
      };
      
     	POA myPOA = rootPOA.create_POA("blahh", 
				     rootPOA.the_POAManager(), policies);

	    myPOA.the_POAManager().activate();
	    
			connectedToServer = true;
		}
		catch (org.omg.CORBA.TRANSIENT e)
    {
    	e.printStackTrace();
     	JOptionPane.showMessageDialog(null, 
     		"Unable to locate Naming Service.\nMake sure Naming Service is running.", 
     		"Cam Viewer Error", JOptionPane.ERROR_MESSAGE);
     	System.exit(0);
    }
		catch (Exception e)
		{
			e.printStackTrace();
			JOptionPane.showMessageDialog(null,
					"Error locating remote objects.\nMake sure the CORBA server is running.",
					"Cam Viewer Error", JOptionPane.ERROR_MESSAGE);
		}
		
	}
	
	
	public static void main(String args[])
	{				
    final CamController app = new CamController(args);
		app.addWindowListener(
			new WindowAdapter() 
			{
				public void windowClosing(WindowEvent e) 
				{
					System.out.println("About to stopCamViewer");
					try
					{
						VideoViewer.terminate();
						VideoViewer.stopCamViewer();
					}
					catch (Exception ex)
					{	
						ex.printStackTrace();
					}
					System.exit(0);
				}
			}
		);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -