I want to make a java program in which there is a combobox which displays the titles of all the files available in a folder
I actually want a JFrame
in which there is a combobox.
There is a folder which has 3 sound files named:
sound1.wav
sound2开发者_JAVA技巧.wav
sound3.wav
The combobox should display these 3 file titles and when I click one of them it plays that sound file.
You could simply search the folder and populate the combobox with the values (Example: http://www.exampledepot.com/egs/java.io/GetFiles.html).
To play the soundfiles you may want to look here: How can I play sound in Java?
You can use .listFiles() to return the list of files in a particular folder
File someFolder = new File("pathname");
Object[] wavFiles = someFolder.listFiles(wavExtensionFilenameFilter);
JComboBox songComboBox = new JComboBox(wavFiles);
That should get you started on the UI at least, btw is this a homework question?
精彩评论