I want my Java program to play a song while the program is running, What would be the sample code to have my java program play a tune with file name lets say, : 'hillsong.mp3' ? also if it is not too much to ask is my program well written? Or should I add separate some methods into seperate classes?
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");
}
}