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

孤者浪人 提交于 2019-12-13 04:03:43

问题


I actually want a JFrame in which there is a combobox.

There is a folder which has 3 sound files named:

  • sound1.wav
  • sound2.wav
  • sound3.wav

The combobox should display these 3 file titles and when I click one of them it plays that sound file.


回答1:


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?




回答2:


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?



来源:https://stackoverflow.com/questions/6516869/i-want-to-make-a-java-program-in-which-there-is-a-combobox-which-displays-the-ti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!