T7
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="WrongPackageStatement" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -2,7 +2,9 @@ package sbu.javafx;
|
|||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
|
||||||
public class Launcher{
|
public class Launcher {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO: Launch the JavaFX application by calling Application.launch(Main.class) }
|
Application.launch(MusicApp.class,args);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -5,19 +5,22 @@ import javafx.fxml.FXMLLoader;
|
|||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class MusicApp extends Application {
|
public class MusicApp extends Application {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws IOException
|
public void start(Stage stage) throws Exception {
|
||||||
{
|
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
|
FXMLLoader loader =
|
||||||
Scene scene = new Scene(fxmlLoader.load());
|
new FXMLLoader(getClass().getResource("App-view.fxml"));
|
||||||
|
|
||||||
|
Scene scene = new Scene(loader.load(),900,600);
|
||||||
|
|
||||||
stage.setTitle("Music Player");
|
stage.setTitle("Music Player");
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
//TODO: add icon to the stage
|
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public static void main(String[] args) {
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,31 +1,151 @@
|
|||||||
package sbu.javafx;
|
package sbu.javafx;
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.control.ListView;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class MusicController {
|
public class MusicController {
|
||||||
|
|
||||||
// TODO: Define your UI components using the @FXML annotation.
|
public static ArrayList<Song> playlist =
|
||||||
|
new ArrayList<>();
|
||||||
//TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing.
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void handlePlayAction() {
|
private ListView<Song> songsListView;
|
||||||
//Update labels, change button icons, etc.
|
|
||||||
|
@FXML
|
||||||
|
private Label nowPlayingLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField titleField;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField artistField;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField durationField;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize() {
|
||||||
|
|
||||||
|
songsListView.getItems().addAll(
|
||||||
|
|
||||||
|
new Song(
|
||||||
|
"Believer",
|
||||||
|
"Imagine Dragons",
|
||||||
|
"03:24"
|
||||||
|
),
|
||||||
|
|
||||||
|
new Song(
|
||||||
|
"Perfect",
|
||||||
|
"Ed Sheeran",
|
||||||
|
"04:23"
|
||||||
|
),
|
||||||
|
|
||||||
|
new Song(
|
||||||
|
"Yellow",
|
||||||
|
"Coldplay",
|
||||||
|
"04:29"
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Logic to add a specific song to the user's playlist.
|
@FXML
|
||||||
|
public void addSong() {
|
||||||
|
|
||||||
public void addToPlaylist(String songName) {
|
String title = titleField.getText();
|
||||||
//Add the song to a list or update a ListView.
|
String artist = artistField.getText();
|
||||||
|
String duration = durationField.getText();
|
||||||
|
|
||||||
|
if(title.isEmpty()
|
||||||
|
|| artist.isEmpty()
|
||||||
|
|| duration.isEmpty()) {
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
songsListView.getItems().add(
|
||||||
|
|
||||||
|
new Song(
|
||||||
|
title,
|
||||||
|
artist,
|
||||||
|
duration
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
titleField.clear();
|
||||||
|
artistField.clear();
|
||||||
|
durationField.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:This method should open a new window or change the current scene to display the "Playlist" page.
|
@FXML
|
||||||
|
public void playSong() {
|
||||||
|
|
||||||
public void openPlaylistWindow() {
|
Song selectedSong =
|
||||||
//Create a new stage and show the playlist UI.
|
songsListView
|
||||||
|
.getSelectionModel()
|
||||||
|
.getSelectedItem();
|
||||||
|
|
||||||
|
if(selectedSong == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nowPlayingLabel.setText(
|
||||||
|
"Now Playing: "
|
||||||
|
+ selectedSong.getTitle()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@FXML
|
||||||
|
public void addToPlaylist() {
|
||||||
|
|
||||||
|
Song selectedSong =
|
||||||
|
songsListView
|
||||||
|
.getSelectionModel()
|
||||||
|
.getSelectedItem();
|
||||||
|
|
||||||
|
if(selectedSong == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!playlist.contains(selectedSong)) {
|
||||||
|
playlist.add(selectedSong);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void viewPlaylist(ActionEvent event)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
|
FXMLLoader loader =
|
||||||
|
new FXMLLoader(
|
||||||
|
getClass()
|
||||||
|
.getResource(
|
||||||
|
"Playlist-view.fxml"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Scene playlistScene =
|
||||||
|
new Scene(
|
||||||
|
loader.load(),
|
||||||
|
700,
|
||||||
|
500
|
||||||
|
);
|
||||||
|
|
||||||
|
Stage stage =
|
||||||
|
(Stage)((Node)event.getSource())
|
||||||
|
.getScene()
|
||||||
|
.getWindow();
|
||||||
|
|
||||||
|
stage.setScene(playlistScene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package sbu.javafx;
|
||||||
|
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class PlaylistController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ListView<Song> playlistView;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize() {
|
||||||
|
|
||||||
|
playlistView
|
||||||
|
.getItems()
|
||||||
|
.addAll(
|
||||||
|
MusicController.playlist
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void goBack(ActionEvent event)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
|
FXMLLoader loader =
|
||||||
|
new FXMLLoader(
|
||||||
|
getClass()
|
||||||
|
.getResource(
|
||||||
|
"App-view.fxml"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Scene scene =
|
||||||
|
new Scene(
|
||||||
|
loader.load(),
|
||||||
|
900,
|
||||||
|
600
|
||||||
|
);
|
||||||
|
|
||||||
|
Stage stage =
|
||||||
|
(Stage)((Node)event.getSource())
|
||||||
|
.getScene()
|
||||||
|
.getWindow();
|
||||||
|
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package sbu.javafx;
|
||||||
|
|
||||||
|
public class Song {
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private String artist;
|
||||||
|
private String duration;
|
||||||
|
|
||||||
|
public Song(String title,
|
||||||
|
String artist,
|
||||||
|
String duration) {
|
||||||
|
|
||||||
|
this.title = title;
|
||||||
|
this.artist = artist;
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArtist() {
|
||||||
|
return artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return title + " | " + artist + " | " + duration;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,54 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.control.*?>
|
||||||
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10">
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
<!-- TODO: Add your code here! -->
|
<VBox xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
fx:controller="sbu.javafx.MusicController"
|
||||||
|
alignment="CENTER"
|
||||||
|
spacing="15">
|
||||||
|
|
||||||
</VBox>
|
<Label text="Music Player"
|
||||||
|
style="-fx-font-size:24px;
|
||||||
|
-fx-font-weight:bold;" />
|
||||||
|
|
||||||
|
<HBox spacing="10"
|
||||||
|
alignment="CENTER">
|
||||||
|
|
||||||
|
<TextField fx:id="titleField"
|
||||||
|
promptText="Song Title"/>
|
||||||
|
|
||||||
|
<TextField fx:id="artistField"
|
||||||
|
promptText="Artist"/>
|
||||||
|
|
||||||
|
<TextField fx:id="durationField"
|
||||||
|
promptText="Duration"/>
|
||||||
|
|
||||||
|
<Button text="Add Song"
|
||||||
|
onAction="#addSong"/>
|
||||||
|
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
<ListView fx:id="songsListView"
|
||||||
|
prefWidth="600"
|
||||||
|
prefHeight="250"/>
|
||||||
|
|
||||||
|
<HBox spacing="10"
|
||||||
|
alignment="CENTER">
|
||||||
|
|
||||||
|
<Button text="Play"
|
||||||
|
onAction="#playSong"/>
|
||||||
|
|
||||||
|
<Button text="Add To Playlist"
|
||||||
|
onAction="#addToPlaylist"/>
|
||||||
|
|
||||||
|
<Button text="View Playlist"
|
||||||
|
onAction="#viewPlaylist"/>
|
||||||
|
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
<Label fx:id="nowPlayingLabel"
|
||||||
|
text="Now Playing: None"/>
|
||||||
|
|
||||||
|
</VBox>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<VBox xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
fx:controller="sbu.javafx.PlaylistController"
|
||||||
|
alignment="CENTER"
|
||||||
|
spacing="15">
|
||||||
|
|
||||||
|
<Label text="My Playlist"
|
||||||
|
style="-fx-font-size:22px;
|
||||||
|
-fx-font-weight:bold;" />
|
||||||
|
|
||||||
|
<ListView fx:id="playlistView"
|
||||||
|
prefWidth="500"
|
||||||
|
prefHeight="300"/>
|
||||||
|
|
||||||
|
<Button text="Back"
|
||||||
|
onAction="#goBack"/>
|
||||||
|
|
||||||
|
</VBox>
|
||||||
Reference in New Issue
Block a user