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

📄 mainframe.java~10~

📁 一些基本的代码,还有一些事例.值得一看
💻 JAVA~10~
字号:
package jsounddemo1;import java.awt.*;import java.awt.event.*;import javax.swing.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class MainFrame extends JFrame {  private JPanel contentPane;  private JTextField jTextField1 = new JTextField();  private JLabel jLabel1 = new JLabel();  private JPanel jPanel1 = new JPanel();  private JButton jButton1 = new JButton();  private JButton jButton2 = new JButton();  private java.applet.AudioClip clip;  //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();    this.setSize(new Dimension(418, 118));    this.setTitle("JSoundDemo1");    jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));    jLabel1.setToolTipText("");    jLabel1.setText("Waiting.........");    jButton1.setFont(new java.awt.Font("Dialog", 0, 12));    jButton1.setText("Play");    jButton1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton1_actionPerformed(e);      }    });    jButton2.setFont(new java.awt.Font("Dialog", 0, 12));    jButton2.setText("Stop");    jButton2.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton2_actionPerformed(e);      }    });    jTextField1.setText("");    contentPane.add(jLabel1, BorderLayout.SOUTH);    contentPane.add(jPanel1, BorderLayout.CENTER);    jPanel1.add(jButton1, null);    jPanel1.add(jButton2, null);    contentPane.add(jTextField1, BorderLayout.NORTH);    clip=null;  }  //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);    }  }  void jButton1_actionPerformed(ActionEvent e) {    try{//      clip = java.applet.Applet.newAudioClip(new java.net.URL(this.jTextField1.getText()));      clip = java.applet.Applet.newAudioClip(ClassLoader.getSystemResource("sounds/spacemusic.wav"));      clip.play();      this.jLabel1.setText("Now Playing "+this.jTextField1.getText());    }catch(Exception err){      err.printStackTrace();    }  }  void jButton2_actionPerformed(ActionEvent e) {    try{      clip.stop();      this.jLabel1.setText("Waiting .......");    }catch(Exception err){      err.printStackTrace();    }  }}

⌨️ 快捷键说明

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