📄 mainframe.java~2~
字号:
package jsounddemo2;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.media.*;import javax.media.control.*;import javax.media.datasink.*;import javax.media.format.*;import javax.media.protocol.*;import java.util.*;public class MainFrame extends JFrame implements ActionListener, DataSinkListener { private JPanel contentPane; private BorderLayout borderLayout1 = new BorderLayout(); StateHelper sh; Processor processor; DataSink filewriter = null; private JButton btStart = new JButton("Start"); private JButton btStop = new JButton("Stop"); //Construct the frame public MainFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(borderLayout1); this.setSize(new Dimension(400, 300)); this.setTitle("JSoundDemo2"); this.btStart.addActionListener(this); this.btStop.addActionListener(this); contentPane.add(this.btStart,BorderLayout.WEST); contentPane.add(this.btStop,BorderLayout.EAST); CaptureDeviceInfo cdi = null; AudioFormat af = new AudioFormat(AudioFormat.LINEAR,8000,16,1); Vector deviceList = CaptureDeviceManager.getDeviceList(af); if ( deviceList.size()>0){ cdi = (CaptureDeviceInfo)deviceList.firstElement(); }else{ terminate("Could not find 44,100Hz 16-bit audio device"); } processor = Manager.createProcessor(cdi.getLocator()); sh = new StateHelper(processor); if (!sh.configure(10000)) terminate("Could not configure processor"); FileTypeDescriptor ftd; ftd = new FileTypeDescriptor(FileTypeDescriptor.BASIC_AUDIO); processor.setContentDescriptor(ftd); if (!sh.realize(10000)) terminate("Could not realize processor"); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } public void actionPerformed(ActionEvent e) { /**@todo Implement this java.awt.event.ActionListener method*/ //throw new java.lang.UnsupportedOperationException("Method actionPerformed() not yet implemented."); String cmd = e.getActionCommand(); ((Component)e.getSource()).setEnabled(false); if (cmd.equals("Start")){ DataSource source = processor.getDataOutput(); MediaLocator dest = new MediaLocator("file:/c:/au.au"); try{ filewriter = Manager.createDataSink(source,dest); fil } } } public void dataSinkUpdate(DataSinkEvent parm1) { /**@todo Implement this javax.media.datasink.DataSinkListener method*/ throw new java.lang.UnsupportedOperationException("Method dataSinkUpdate() not yet implemented."); } public void terminate(String str){ System.out.println(str); System.exit(-1); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -