This is my first java project. I created a Set list Generator for my church's youth group. It writes to a .dat file and reads from it. The flow is 3 songs. Fast, Medium/Slow, or slow. I have made a song class with the following properties: Artist, Title, Tempo, Category.
My goal is to click a button where a JOptionpane pops up and generates a 3 random song set list from our database like the following: Song 1: show song with fast category Song 2: show song with medium or slow category song 3: show song with slow category
I am stuck at this point and need some help on how to achieve that. I got as far as populating an array from the songs.dat file but i am unsure how to generate a song with specified category. This is the last step in my personal project.
public Menu() {
initComponents();
songs = new ArrayList<Song>();
populateArrayList();
String [] songsArray = new String[songs.size()];
for (int i = 0 ; i < songs.size() ; i++)
{
songsArray[i] = songs.get(i).getTitle();
songsArray[i] = songs.get(i).getCategory();
}
}
public void populateArrayList()
{
try
{
FileInputStream file = new FileInputStream("Songs.dat");
ObjectInputStream inputFile = new ObjectInputStream(file);
boolean endOfFile = false;
while (!endOfFile)
{
try
{
songs.add((Song) inputFile.readObject());
}
catch (EOFException e)
{
endOfFile = true;
}
catch (Exception f)
{
JOptionPane.showMessageDialog(null, f.getMessage());
}
}
inputFile.close();
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
Aucun commentaire:
Enregistrer un commentaire