现在的位置: 首页 > 综合 > 正文

视频监控(serverJFrame)

2013年10月08日 ⁄ 综合 ⁄ 共 5665字 ⁄ 字号 评论关闭
 

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.*;
import javax.swing.border.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import com.sun.image.codec.jpeg.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.media.util.BufferToImage;
import javax.media.control.FrameGrabbingControl;
import javax.imageio.stream.ImageOutputStream;

import org.apache.crimson.tree.XmlDocument;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

/**
 * @(#)Jmf.java
 *
 * JFC Sample application
 *
 * 
@author
 * 
@version 1.00 06/04/24
 
*/

public class v_ServerJFrame extends JFrame {

    Player player;
    CaptureDeviceInfo di;
    MediaLocator ml;
    
//static int picCount;
    JPanel v_panel = null;
    
static final int pic_Width = 176;    
    
static final int pic_Hight = 144;
    
long times = 0;
    
int px[] = new int[2];
    
    
int playerisOpen = 0;
    Component comp;
    
    timeSave bt 
= new timeSave(this);

    
// UDPServer udpSer = null;
    /**
     * The constructor.
     
*/

    
public v_ServerJFrame() {
        
        JPanel ButtonGroup 
= new JPanel();
    
        v_panel 
= new JPanel();
        v_panel.setBackground(Color.GRAY);
        v_panel.setLayout(
new FlowLayout());
        v_panel.setBorder(
new BevelBorder(BevelBorder.LOWERED));
        
        
        getContentPane().add(BorderLayout.CENTER, v_panel);
        getContentPane().add(BorderLayout.SOUTH, ButtonGroup);

        setResizable(
false);
        
        
        JButton StartButton 
= new JButton();
        
//JButton CaptureButton = new JButton();
        JButton StopButton = new JButton();
        
//JButton SaveButton = new JButton();
        JButton ExitButton = new JButton();

        
        StartButton.setText(
"启动");
        
//CaptureButton.setText("Capture");
        StopButton.setText("停止");
        
//SaveButton.setText("Save");        
        ExitButton.setText("退出");
        

        ButtonGroup.add(BorderLayout.WEST, StartButton);
       
// ButtonGroup.add(BorderLayout.WEST, CaptureButton);        
        ButtonGroup.add(BorderLayout.WEST, StopButton);
        
//ButtonGroup.add(BorderLayout.WEST, SaveButton);        
        ButtonGroup.add(BorderLayout.WEST, ExitButton);
        
        
//StartCapture();        
        
      
        
        StopButton.addActionListener
                (    
new ActionListener() {
            
public void actionPerformed(ActionEvent e) {
                
//System.out.println(comp.getWidth());
                
//System.out.println(comp.getHeight());              
                
//v_panel.repaint();          
                
//new UDPServer().start();
                /*for (int i=0;i<10;i++){
                    if (ps.ps[i] !=null)
                      ps.ps[i].EXIT_FLAG =1;
                }
*/

                
                CloseCapture();
            }

        }

        );
        StartButton.addActionListener
                (  
new ActionListener() {
            
public void actionPerformed(ActionEvent e) {            
                StartCapture();
                
            }

        }

        );
        
/*SaveButton.addActionListener
                (  new ActionListener() {
            public void actionPerformed(ActionEvent e) {
             
            }
        }
        );
*/

        ExitButton.addActionListener
                (  
new ActionListener() {
            
public void actionPerformed(ActionEvent e) {
                CloseCapture();
                v_ServerJFrame.
this.windowClosed();
            }

        }

        );
        
/*CaptureButton.addActionListener
                (  new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                CaptureAction();
            }
        }
        );
*/


        setTitle(
"v_ServerJFrame");
        setSize(
new Dimension(338310));
       
// setSize(new Dimension(128,128));
       
       
//StartCapture();

        
// Add window listener.
        this.addWindowListener
                (
                        
new WindowAdapter() {
            
public void windowClosing(WindowEvent e) {                
                v_ServerJFrame.
this.windowClosed();
            }

        }

        );
    }



    
/**
     * Shutdown procedure when run as an application.
     
*/

    
private void SavePicToFile(BufferedImage bi){
        System.out.println(
"JPGFile is saving..."); 
        FileOutputStream out 
= null;
        String ph;
        
if (new File(AcceptMsg.picSavepath).exists())
           ph 
= AcceptMsg.picSavepath + "/";
        
else
             ph 
= System.getProperty("user.dir"+ "/pic/" ;

        SimpleDateFormat dateformt
=new SimpleDateFormat("yyyyMMddHHmmss");
        Date now 
= new Date();
        String s 
= dateformt.format(now);
        ph 
+= "xwy" + s + ".jpg";
        
        
try
        
{
        out 
= new FileOutputStream(ph);
        }

        
catch (java.io.FileNotFoundException io)
        
{
          System.out.println(
"File Not Found");
        }
        
        JPEGImageEncoder encoder 
= JPEGCodec.createJPEGEncoder(out);
        JPEGEncodeParam param 
= encoder.getDefaultJPEGEncodeParam(bi);
        param.setQuality(1f, 
false);//不压缩图像
        encoder.setJPEGEncodeParam(param);
        System.out.println(
"JPGFile is saved!");
        
try
        
{
          encoder.encode(bi);
          out.close();
        }

        
catch (java.io.IOException io)
        
{
        System.out.println(
"IOException");
        }

        
    }

//  ----------------------------------------------------------------

抱歉!评论已关闭.