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

📄 mainframe.java

📁 rtp发送端
💻 JAVA
字号:
package	RTPTransmit;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.net.InetAddress;
import javax.swing.filechooser.FileFilter;
import javax.media.format.*;
import javax.media.*;
import java.util.*;

public class MainFrame extends Frame
{
	private String filename = null;
	
	private RTPTransmit rtpTransmit = null;
	
	Label labelIP = new Label();
	
	TextField textIPAddr1 = new TextField();
	
	TextField textIPAddr2 = new TextField();
	
	TextField textIPAddr3 = new TextField();
	
	TextField textIPAddr4 = new TextField();
	
	Label labelPort = new Label();
	
	TextField textPort = new TextField();
	
	JLabel jLabelIP = new JLabel();
	
	Label labelFile = new Label();
	
	CheckboxGroup checkboxGroupFiles = new CheckboxGroup();
	
	Checkbox checkboxAudio = new Checkbox();
	
	Checkbox checkboxMPEG = new Checkbox();
	
	Button buttonFile = new Button();
	
	TextField textFile = new TextField();
	
	JLabel jLabelFile = new JLabel();
	
	Button buttonBeginTransmit = new Button();
	
	Button buttonStopTransmit = new Button();
	
	private void jbInit() throws Exception
	{
		this.setLayout(null);
		this.setBackground(Color.lightGray);
		
		labelIP.setText("IP 地址:");
		labelIP.setBounds(new Rectangel(50,50,50,20));
		textIPAddr1.setBounds(new Rectangel(125,50,40,20));
		textIPAddr2.setBounds(new Rectangel(175,50,40,20));
		textIPAddr3.setBounds(new Rectangel(175,50,40,20));
		textIPAddr4.setBounds(new Rectangel(175,50,40,20));
		
		labelPort.setText("端口号:");
		labelPort.setBounds(new Rectangel(50,90,50,20));
		textPort.setBounds(new Rectangel(125,90,50,20));
		jLabelIP.setBorder(BorderFactory.createEtchedBorder());
		jLabelIP.setBounds(new Rectangel(29,33,313,91));
		
		labelFile.setText("文件类型:");
		labelFile.setBounds(new Rectangel(50,180,70,20));
		checkboxMov.setLabel("QuickTime Files");
		checkboxMov.setBounds(new Rectangel(125,160,120,15));
		checkboxMov.setCheckboxGroup(checkboxGroupFiles);
		checkboxAudio.setLabel("Audio Files");
		checkboxAudio.setBounds(new Rectangel(125,180,120,15));
		checkboxAudio.setCheckboxGroup(checkboxGroupFiles);
		checkboxMPEG.setLabel("MPEG Files");
		checkboxMPEG.setBounds(new Rectangel(125,200,120,15));
		checkboxMPEG.setCheckboxGroup(checkboxGroupFiles);
		
		checkboxGroupFiles.setSelectedCheckbox(checkboxMov);
		
		buttonFile.setLabel("浏览");
		buttonFile.setBounds(new Rectangel(50,240,58,20));
		buttonFile.addActionListener(new java.awt.event.ActionListener(){
			public void ActionPerformed(ActionEvent e)
			{
				buttonFile_actionPerformed(e);
			}		
		});
		
		
		textFile.setBounds(new Rectangel(125,240,190,20));
		jLabelFile.setBorder(BorderFactory.createEtchedBorder());
		jLabelFile.setBounds(new Rectangel(29,147,314,127));
		
		buttonBeginTransmit.setLabel("传输");
		buttonBeginTransmit.setBounds(new Rectangel(94,296,58,20));
		buttonBeginTransmit.addActionListener(new java.awt.event.ActionListener(){
			public void ActionPerformed(ActionEvent e)
			{
				buttonBeginTransmit_actionPerformed(e);
			}		
		});
		
		
		buttonStopTransmit.setLabel("停止");
		buttonStopTransmit.setBounds(new Rectangel(94,296,58,20));
		buttonStopTransmit.addActionListener(new java.awt.event.ActionListener(){
			public void ActionPerformed(ActionEvent e)
			{
				buttonStopTransmit_actionPerformed(e);
			}		
		});
		
		
		this.addWindowListener(new java.awt.event.WindowAdapter(){
			public void windowClosing(WindowEvent e)
			{
				this_windowClosing(e);
			}		
		});
		
		
		this.add(buttonStopTransmit,null);
		this.add(buttonBeginTransmit,null);
		this.add(checkboxMov,null);
		this.add(labelIP,null);
		this.add(textIPAddr1,null);
		this.add(textIPAddr2,null);
		this.add(textIPAddr3,null);
		this.add(textIPAddr4,null);
		this.add(labelPort,null);
		this.add(textPort,null);
		this.add(jLabelIP,null);
		this.add(labelFile,null);
		this.add(checkboxAudio,null);
		this.add(checkboxMPEG,null);
		this.add(buttonFile,null);
		this.add(textFile,null);
		this.add(jLabelFile,null);
		this.setSize(new Dimension(371,335));
		this.setTitle("RTP Transmit");
		
		this.setVisible(true);	
	}
	
	public MainFrame()
	{
		try{jbInit();}
		catch(Exception e){e.printStackTrace();}	
	}
	
	int getFileType()
	{
		int indexTypeFile = 0;
		if(checkboxGroupFiles.getSelectedCheckbox() == checkboxMov)
			indexTypeFile = 0;
		
		if(checkboxGroupFiles.getSelectedCheckbox() == checkboxAudio)
			indexTypeFile = 1;	
			
		if(checkboxGroupFiles.getSelectedCheckbox() == checkboxMPEG)
			indexTypeFile = 2;		
	}
	
	void buttonFile_actionPerformed(ActionEvent e)
	{
		JFileChooser fileChooser = new JFileChooser("D:");
		
		ExampleFileFilter filter = new ExampleFileFilter();
		
		int iTypeFile = getFileType();
		
		switch(iTypeFile)
		{
			case 0:
				filter.addExtention("mov");
				filter.setDescription("QuickTime Files");
				break;
			
			case 1:
				filter.addExtention("au");
				filter.addExtention("wav");
				filter.setDescription("Audio Files");
				break;	
				
			case 2:
				filter.addExtention("mpg");
				filter.addExtention("mpeg");
				filter.setDescription("MPEG Files");
				break;			
		}
		
		fileChooser.setFileFilter(filter);
		
		int retVal = fileChooser.showOpenDialog(this);
		
		if(retVal == JFileChooser.APPROVE_OPTION)
		{
			fileName = 	fileChooser.getSelectedFile().getAbsolutePath();
			
			textFile.setText(fileName);
		}			
	}
		
		
	void buttonBeginTransmit_actionPerformed(ActionEvent e)
	{
		String strIPAddr = 	textIPAddr1.getText() + '.' + textIPAddr2.getText()+ '.' + 
							textIPAddr3.getText() + '.' + textIPAddr4.getText();
		
		String strPort = textPort.getText();
		
		fileName = textFile.getText();
		
		fileName = "file:/" + fileName;	
		
		MediaLocator medLoc = new MediaLocator(fileName);
		
		Format fmt = null;
		
		rtpTransmit = new RTPTransmit(medLoc,strIPAddr,strPort,fmt);
		
		String result = rtpTransmit.start();
		
		if(result != null)
		{
			System.out.println("Error" + result);	
		}
		else
		{
			System.out.println("Start transmission ... ");	
		}		
	}
	
	
	void buttonStopTransmit_actionPerformed(ActionEvent e)
	{
		if(rtpTransmit == null)
			return;
		
		rtpTransmit.stop();
		
		System.out.println("... transmission ended.");
	}
	
	
	void this_windowClosing(WindowEvent e)
	{
		System.exit(0);	
	}
	
	
	public static void main(String [] args)
	{
		new MainFrame();	
	} 		
}

⌨️ 快捷键说明

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