Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextArea; import javafx.scene.layout.VBox; import javafx.stage.Stage; import java.io . * ; import java.util. * ; public class
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.io;
import java.util.;
public class SongListManager extends Application
private static final String FILENAME "songs.txt;
private Song songs; Array to store songs
private TextArea displayArea; TextArea to display song list
@Override
public void startStage primaryStage
Initialize songs array and read data from file
songs readSongsFromFileFILENAME;
Initialize GUI components
displayArea new TextArea;
displayArea.setEditablefalse;
displaySongs;
Button addButton new ButtonAdd Song";
addButton.setOnActione addSong;
Button deleteButton new ButtonDelete Song";
deleteButton.setOnActione deleteSong;
Button ascendingSortButton new ButtonSort Ascending";
ascendingSortButton.setOnActione sortAscending;
Button descendingSortButton new ButtonSort Descending";
descendingSortButton.setOnActione sortDescending;
Button randomizeButton new ButtonRandomize List";
randomizeButton.setOnActione randomizeList;
VBox root new VBox;
root.getChildrenaddAlldisplayArea addButton, deleteButton, ascendingSortButton,
descendingSortButton, randomizeButton;
Scene scene new Sceneroot;
primaryStage.setScenescene;
primaryStage.setTitleSong List Manager";
primaryStage.show;
Method to read songs from file
private Song readSongsFromFileString filename
List songList new ArrayList;
try Scanner scanner new Scannernew Filefilename
while scannerhasNextLine
String line scanner.nextLine;
String parts line.split;
String title partstrim;
String artist partstrim;
String genre partstrim;
int duration Integer.parseIntpartstrim;
songList.addnew Songtitle artist, genre, duration;
catch FileNotFoundException e
System.err.printlnFile not found: filename;
return songList.toArraynew Song;
Method to display songs in the TextArea
private void displaySongs
displayArea.clear;
for Song song : songs
displayArea.appendTextsong
;
Method to add a new song
private void addSong
You can implement the logic to add a new song here
Method to delete an existing song
private void deleteSong
You can implement the logic to delete a song here
Method to sort songs in ascending order
private void sortAscending
You can implement the logic to sort songs in ascending order here
Method to sort songs in descending order
private void sortDescending
You can implement the logic to sort songs in descending order here
Method to randomize the song list
private void randomizeList
You can implement the logic to randomize the song list here
public static void mainString args
launchargs;
Add the logic to the methods above. Method to add a new song, Method to delete an existing song, Method to sort songs in ascending order, Method to sort songs in descending order, and Method to randomize the song list please.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started