我想让我的Java程序播放一首歌?

时间:2016-09-20 03:14:37

标签: java

我希望我的Java程序在程序运行时播放歌曲,让我的java程序播放带有文件名的曲调的示例代码可以说: 'hillsong.mp3'?如果不是太多问我的程序编写得好吗?或者我应该将单独的一些方法添加到单独的类中吗?

import java.awt.*;
import sun.audio.*;
import javax.swing.*;

public class AudioandImage extends JFrame {
    public ImageIcon image1;
    public JLabel label1;
    public ImageIcon image2;
    public JLabel label2;
    public JLabel text;

    AudioandImage() {
        setLayout (new BorderLayout());
        image1 = new ImageIcon(getClass().getResource("losangeles.jpg"));

        label1 = new JLabel(image1);
        add(label1,BorderLayout.PAGE_START);

        image2 = new ImageIcon(getClass().getResource("elsalvador.jpg"));

        label2 = new JLabel(image2);
        add(label2,BorderLayout.CENTER);

         text = new JLabel("<html><ul>My name is : Erik  Landaverde "
                    + "<li/>Some facts about myself: </li> "
                    + "<li/>I was born and raised in South Central Los Angeles</li>"
                    + "<li/>Have a Salvadorean background</li>"
                    + "<li/>My favorite sport is soccer</li>"
                    + "<li/>Lastly... I am a programmer!</li></ul></html>", SwingConstants.CENTER);

         add(text,BorderLayout.PAGE_END);

        }

    public static void main(String[] args) {

        AudioandImage gui = new AudioandImage();
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setVisible(true);
        gui.pack();
        gui.setTitle("A Little About Myself");

        }

}

0 个答案:

没有答案