i have a main java code called home.java which is an interface.
when i press button BTNSTART , i want d progm WebCam.java to exxecute.
but it's giving me an error saying :

ERROR: home.java:146: cannot find symbol symbol (constructor WebCam())

the code home.java :

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Random;
import java.util.*;
import java.text.*;

 
 class home extends JFrame implements ActionListener, Runnable
 {
	JButton btndetect,btntest,btnstart,btnexit;
	ImageIcon ic,ic1,bc;
        JLabel lbltitle;
      Thread t;
	
 public home()
 {
 	setSize(800,570);
	setTitle(" CAMERA SETUP ");

	
	
	ic1=new ImageIcon("ready3.jpg");
		
	lbltitle= new JLabel(ic1);	

	btndetect=new JButton(" Detect web cam ",ic);
	btntest=new JButton(" Test cam ");
	btnstart=new JButton("start servellance");
        btnexit=new JButton("Exit");


	Container cp=getContentPane();
	cp.setLayout(null); 

	//cp.setBackground(Color.white);
	Insets ins=getInsets();

	btndetect.setBounds(40,100,150,50);
	btntest.setBounds(40,200,150,50);
	btnexit.setBounds(40,300,150,50);
                 btnstart.setBounds(40,400,150,50);

	lbltitle.setBounds(0,0,850,570);
	//lbltitle.setBounds(220,20,130,104);
	
	btndetect.addActionListener(this);
	btntest.addActionListener(this);
	btnstart.addActionListener(this);
	btnexit.addActionListener(this);
		


	cp.add(btndetect);
	cp.add(btntest);
	cp.add(btnstart);
	cp.add(btnexit);
        cp.add(lbltitle);		

	//cp.setBackground(Color.blue);
     
	
  }



public void run()
{

  try
      {
               		 
          while(t.isAlive())
           {		
	Thread.sleep(1000);
	
	File f = new File("check/test.jpg");
	 if(f.exists())                  
	{
                    

	   String fname = f.getAbsolutePath();

                   FileInputStream instream = new FileInputStream(fname);

	int insize = instream.available();

	byte inBuf[] = new byte[insize];

                 int bytesread = instream.read(inBuf,0,insize);
	instream.close();
		                     	
		
 
                  }                    

            }
       }
         catch(Exception e)
         {
             System.out.println(e);
        }


}

public void actionPerformed(ActionEvent ae)
  {
				
	if(ae.getSource() == btndetect)
	{

		detect sc=new detect();
		sc.show();
		setVisible(false);
	}
 	
	else 
	if(ae.getSource() == btntest)
	{

		

	 try
        {
            JWebCam myWebCam = new JWebCam ( "Web Cam Capture" );
            myWebCam.setVisible ( true );
 
            if ( !myWebCam.initialise() )
            {
                System.out.println ("Web Cam not detected / initialised");
            }
        }
        catch ( Exception ex )
        {
            ex.printStackTrace();
        }

	}
                    else if(ae.getSource() == btnstart)
                   {

		       
		WebCam sc=new WebCam();
		sc.show();
		setVisible(false);
                   }
	else
	{
		System.exit(0);
	}
	
  }


  public static void main(String args[])
  {
 	home h=new home();
	h.show();
  }
}

& the code WebCam.java is as follows :

import java.io.*;
import java.awt.*;
import javax.media.*;
import javax.media.control.*;
import javax.media.format.*;
import javax.media.protocol.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*; //enc & dec jpegs

public class WebCam extends Frame implements ControllerListener
{
	Processor p;
	Object waitObj = new Object();
	boolean stateOK = true;
	DataSourceHandler handler;
	imgPanel currPanel;int imgWidth;int imgHeight;int WxH;
	DirectColorModel dcm = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF);
	MemoryImageSource sourceImage;Image outputImage;
	String sep = System.getProperty("file.separator");
	int[] outvid;
	private int[] pixelsR;
	private int[] pixelsG;
	private int[] pixelsB;
	short[] gradients;
	int cte0;
	int chg0;
	int chgtol = 25;	// tolerance for scene change
	int ctl;
	long ctfrt=15;	// minimum gap between scene change events
	long ctfr=ctfrt;	// so can fire from first


	public static void main(String[] args)
	{
		if(args.length == 0)
		{
			System.out.println("No media address.");
			new WebCam("vfw:Microsoft WDM Image Capture (Win32)");	
		}
		else
		{
			String path = args[0].trim();
			System.out.println(path);
			new WebCam(path);
		}
	}

	
	
	
	public WebCam(String path)
	{
		MediaLocator ml;String args = path;

		if((ml = new MediaLocator(args)) == null)
		{
			System.out.println("Cannot build media locator from: " + args);
		}

		if(!open(ml))
		{
			System.out.println("Failed to open media source");
		}
    }

	//create a processor for media lctr
	 
	
	private boolean open(MediaLocator ml)
	{
		System.out.println("Create processor for: " + ml);

		try
		{
			p = Manager.createProcessor(ml);
		}
		catch (Exception e)
		{
			System.out.println("Failed to create a processor from the given media source: " + e);
			return false;
		}

		p.addControllerListener(this);

		//configure processor
		p.configure();
		if(!waitForState(p.Configured))
		{
			System.out.println("Failed to configure the processor.");
			return false;
		}

	//raw output frm processor
		p.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW));

		TrackControl tc[] = p.getTrackControls();
		if(tc == null)
		{
			System.out.println("Failed to obtain track controls from the processor.");
			return false;
		}

		TrackControl videoTrack = null;
		for(int i = 0; i < tc.length; i++)
		{
			if(tc[i].getFormat() instanceof VideoFormat)
			{
				tc[i].setFormat(new RGBFormat(null,-1,Format.intArray,-1.0F,32,0x00FF0000, 0x0000FF00, 0x000000FF));
				videoTrack = tc[i];
			}
			else
			tc[i].setEnabled(false);
		}
		if(videoTrack == null)
		{
			System.out.println("The input media does not contain a video track.");
			return false;
		}
		System.out.println("Video format: " + videoTrack.getFormat());

		p.realize();
		if(!waitForState(p.Realized))
		{
			System.out.println("Failed to realize the processor.");
			return false;
		}

		// Get the output DataSource from the processor and set it to the DataSourceHandler.
		DataSource ods = p.getDataOutput();
		handler = new DataSourceHandler();
		try
		{
			handler.setSource(ods);	// determines image size
		}
		catch(IncompatibleSourceException e)
		{
			System.out.println("Cannot handle the output DataSource from the processor: " + ods);
			return false;
		}

		setLayout(new FlowLayout(FlowLayout.LEFT));
		currPanel = new imgPanel(new Dimension(imgWidth,imgHeight));
		add(currPanel);
		pack();
	;
		setVisible(true);

		handler.start();

		
		p.prefetch();

		if(!waitForState(p.Prefetched))
		{
			System.out.println("Failed to prefetch the processor.");
			return false;
		}

	
		p.start();

		return true;
	}

	
	 //image size set
	
	private void imageProfile(VideoFormat vidFormat)
	{
		System.out.println("Push Format "+vidFormat);
		Dimension d = (vidFormat).getSize();
		System.out.println("Video frame size: "+ d.width+"x"+d.height);
		imgWidth=d.width;
		imgHeight=d.height;
		WxH=imgWidth*imgHeight;
	}

	
	//Called on each new frame buffer
	
	private void useFrameData(Buffer inBuffer)
	{
		try
		{
		
			if(inBuffer.getData()!=null)	
			{
				if(outvid==null)outvid = new int[imgWidth*imgHeight];
				System.arraycopy((int[])inBuffer.getData(), 0, outvid, 0, outvid.length);
				setImage(outvid);
				
				if(sceneChange(outvid)==false)return;

				
				String paddedname = "0000000000000"+inBuffer.getTimeStamp();	// or getSequenceNumber()
				String sizedname = paddedname.substring(paddedname.length()-20);

				saveJpeg(outputImage,"image_"+sizedname+".jpg");
			}
		}
		catch(Exception e){System.out.println(e);}
	}

	
	//Determine if a scene change
	
	public boolean sceneChange(int[] outpix)
	{
		if(gradients==null)gradients = new short[imgWidth*imgHeight];

		if(pixelsR==null)pixelsR = new int[imgWidth*imgHeight];
		if(pixelsG==null)pixelsG = new int[imgWidth*imgHeight];
		if(pixelsB==null)pixelsB = new int[imgWidth*imgHeight];

		doubleGradients(outpix,gradients,imgWidth,imgHeight);

		return sceneChange(gradients,imgWidth,imgHeight);
	}

	///////////////////////////////////////////////////////////
	 //Calculates double gradients.
	 
	 
	void doubleGradients(int[] pixels, short[] gradients, int W, int H)
    {
		int Rindex=-1;int Cindex;
		int pix;
		int t1R;int t1G;int t1B;
		int txR;int txG;int txB;
		int tyR;int tyG;int tyB;
		int deriv_x;int deriv_y;int hypot;

		for(int j=0;j<H;j++)
		{
			for(int i=0;i<W;i++)
			{
				Rindex++;

				pix = pixels[Rindex];
				t1R = ((pix >> 16) & 0xff);
				t1G = ((pix >> 8) & 0xff);
				t1B = (pix & 0xff);

				pixelsR[Rindex] = t1R;pixelsG[Rindex] = t1G;pixelsB[Rindex] = t1B;
				// Rindex+1 etc not available here

				if(j<2 || i<2)continue;	// to calculate j-1 and i-1 below
				Cindex = Rindex-W-1;	// so all array values below are available

				txR = pixelsR[Cindex+1]-pixelsR[Cindex-1];
				txG = pixelsG[Cindex+1]-pixelsG[Cindex-1];
				txB = pixelsB[Cindex+1]-pixelsB[Cindex-1];

				tyR = pixelsR[Cindex+W]-pixelsR[Cindex-W];
				tyG = pixelsG[Cindex+W]-pixelsG[Cindex-W];
				tyB = pixelsB[Cindex+W]-pixelsB[Cindex-W];

				deriv_x = (Math.abs(txR)+Math.abs(txG)+Math.abs(txB))/3;
				deriv_y = (Math.abs(tyR)+Math.abs(tyG)+Math.abs(tyB))/3;

				//hypot = hypotenuse(deriv_x,deriv_y);
				hypot = deriv_x;if(deriv_y>deriv_x)hypot=deriv_y;

				gradients[Cindex] = (short)(hypot * 20);
			}
		}
		Thread.yield();
	}

	//scene change try
	public boolean sceneChange(short[] gradients, int w, int h)
	{
		

		int cte=0;
		int rindex=-1;
		int tD = 75;int tDtol=20*tD*255/100;	//tolrnce

		for(int j=0;j<h;j++)
		{
			for(int i=0;i<w;i++)
			{
				rindex++;
				if(gradients[rindex]>tDtol)cte++;
			}
		}

		// lower so ratios consistent up or down and so blank screen is max
		ctl=cte;if(cte0<ctl)ctl=cte0;if(ctl<1)ctl=1;

		int chg=100*(cte-cte0)/ctl;
		if(chg<0)chg=-chg;

		ctfr++;	// count frames since last event

		//if(chg>4)System.out.println(ctfr+" "+cte+"    "+chg);

		// tolerance exceeded, and peak or trough, and after min frame count between events
		if(chg0>chgtol && chg<=chg0 && ctfr>ctfrt)
		{
			// reset ...
			cte0=cte;	// updated
			chg0=0;
			ctfr=0;

			return true;	// scene change event
		}

		if(chg>chg0)	// yes, includes if swings to opposite sign
		{
			// cte0 unchanged
		}
		else
		{
			cte0=cte;	// updated
		}

		chg0=chg;

		return false;
	}

	//////////////////////////////////////////////////////////////////////
	
	public void tidyClose()
	{
		handler.close();
		p.close();
		//dispose();	// frame
		System.out.println("Sources closed");
	}

	
	//draw imgae into the fraem
	
	private void setImage(int[] outpix)
	{
		if(sourceImage==null)sourceImage = new MemoryImageSource(imgWidth, imgHeight, dcm, outpix, 0, imgWidth);
		outputImage = createImage(sourceImage);
		currPanel.setImage(outputImage);
	}

	
	
	private boolean waitForState(int state)
	{
		synchronized(waitObj)
		{
			try
			{
				while(p.getState() < state && stateOK)
				waitObj.wait();
			}
			catch (Exception e)
			{
			}
		}
		return stateOK;
	}

	
	//controller Listener.

	public void controllerUpdate(ControllerEvent event)
	{
		if(event instanceof ConfigureCompleteEvent ||	event instanceof RealizeCompleteEvent || event instanceof PrefetchCompleteEvent)
		{
			synchronized(waitObj)
			{
				stateOK = true;
				waitObj.notifyAll();
			}
		}
		else
		if(event instanceof ResourceUnavailableEvent)
		{
			synchronized(waitObj)
			{
				stateOK = false;
				waitObj.notifyAll();
			}
		}
		else
		if(event instanceof EndOfMediaEvent || event instanceof StopAtTimeEvent)
		{
			tidyClose();
		}
	}

	
	 //Prints frame info
	
	private void printDataInfo(Buffer buffer)
    {
		System.out.println(" Time stamp: " + buffer.getTimeStamp());
		System.out.println(" Time: " + (buffer.getTimeStamp()/10000000)/100f+"secs");
		System.out.println(" Sequence #: " + buffer.getSequenceNumber());
		System.out.println(" Data length: " + buffer.getLength());
		System.out.println(" Key Frame: " + (buffer.getFlags()==Buffer.FLAG_KEY_FRAME)+" "+buffer.getFlags());
    }

	
	//Jpeg buffer...for writing into fiel
	
	public void saveJpeg(Image img, String filename)
	{
		BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
		Graphics g = bi.getGraphics();
		g.drawImage(img, 0, 0, this);

		BufferedOutputStream fw=null;
		try
		{
			fw = new BufferedOutputStream(new FileOutputStream("images"+sep+filename));
		}
		catch(IOException e ){System.out.println("saveJpeg "+e);}

		JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fw);
		JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
		param.setQuality(0.6f,false);
		encoder.setJPEGEncodeParam(param);

		try
		{
			encoder.encode(bi);
			fw.close();

			System.out.println(" *** Created file "+filename);
		}
		catch (java.io.IOException io)
		{
			System.out.println("IOException");
		}
	}

	
	class DataSourceHandler implements BufferTransferHandler
	{
		DataSource source;
		PullBufferStream pullStrms[] = null;
		PushBufferStream pushStrms[] = null;
		Buffer readBuffer;

	
		private void setSource(DataSource source) throws IncompatibleSourceException
		{
			
			if(source instanceof PushBufferDataSource)
			{
				pushStrms = ((PushBufferDataSource) source).getStreams();

				
				pushStrms[0].setTransferHandler(this);

				// imag size
				imageProfile((VideoFormat)pushStrms[0].getFormat());
			}
			else
			if(source instanceof PullBufferDataSource)
			{
				System.out.println("PullBufferDataSource!");

				
			}

			this.source = source;
			readBuffer = new Buffer();
		}

		
		public void transferData(PushBufferStream stream)
		{
			try
			{
				stream.read(readBuffer);
			}
			catch(Exception e)
			{
				System.out.println(e);
				return;
			}

			
			Buffer inBuffer = (Buffer)(readBuffer.clone());
			inBuffer.setFlags(readBuffer.getFlags() | Buffer.FLAG_NO_SYNC);

			
			if(readBuffer.isEOM())
			{
				System.out.println("End of stream");
				return;
			}

		
			useFrameData(inBuffer);
		}

		public void start()
		{
			try{source.start();}catch(Exception e){System.out.println(e);}
		}

		public void stop()
		{
			try{source.stop();}catch(Exception e){System.out.println(e);}
		}

		public void close(){stop();}

		public Object[] getControls()
		{
			return new Object[0];
		}

		public Object getControl(String name)
		{
			return null;
		}
	}


	class imgPanel extends Panel
	{
		Dimension size;
		public Image myimg = null;

		public imgPanel(Dimension size)
		{
			super();
			this.size = size;
		}

		public Dimension getPreferredSize()
		{
			return size;
		}

		public void update(Graphics g)
		{
			paint(g);
		}

		public void paint(Graphics g)
		{
			if (myimg != null)
			{
				g.drawImage(myimg, 0, 0, this);
			}
		}

		public void setImage(Image img)
		{
			if(img!=null)
			{
				this.myimg = img;
				update(getGraphics());
			}
		}
	}

}

someone please help me integrate it..

got th soln...had to pass arguments..no need to reply...thnx..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.