Compare commits
2
Commits
fa5f8ab267
...
3e7b236ec9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e7b236ec9 | ||
|
|
75e8bfb3f1 |
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>
|
||||
@@ -4,5 +4,6 @@ import javafx.application.Application;
|
||||
|
||||
public class Launcher {
|
||||
public static void main(String[] args) {
|
||||
// TODO: Launch the JavaFX application by calling Application.launch(Main.class) }
|
||||
Application.launch(MusicApp.class);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package sbu.javafx;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -16,7 +17,7 @@ public class MusicApp extends Application {
|
||||
Scene scene = new Scene(fxmlLoader.load());
|
||||
stage.setTitle("Music Player");
|
||||
stage.setScene(scene);
|
||||
//TODO: add icon to the stage
|
||||
stage.getIcons().add(new Image(MusicApp.class.getResourceAsStream("music.png")));
|
||||
stage.show();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +1,77 @@
|
||||
package sbu.javafx;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
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.input.MouseEvent;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MusicController {
|
||||
|
||||
// TODO: Define your UI components using the @FXML annotation.
|
||||
@FXML
|
||||
private Label nowPlayingLabel;
|
||||
|
||||
//TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing.
|
||||
public static ArrayList<String> playlist = new ArrayList<>();
|
||||
|
||||
@FXML
|
||||
public void handlePlayAction() {
|
||||
//Update labels, change button icons, etc.
|
||||
private void playSong1() {
|
||||
handlePlayAction("Song of Dawn");
|
||||
}
|
||||
|
||||
//TODO: Logic to add a specific song to the user's playlist.
|
||||
@FXML
|
||||
private void playSong2() {
|
||||
handlePlayAction("Midnight Drive");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void playSong3() {
|
||||
handlePlayAction("Echoes of You");
|
||||
}
|
||||
|
||||
public void handlePlayAction(String songName) {
|
||||
nowPlayingLabel.setText("Now Playing: " + songName);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addSong1() {
|
||||
addToPlaylist("Song of Dawn - Alice Johnson");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addSong2() {
|
||||
addToPlaylist("Midnight Drive - The Night Owls");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addSong3() {
|
||||
addToPlaylist("Echoes of You - Luna Sky");
|
||||
}
|
||||
|
||||
public void addToPlaylist(String songName) {
|
||||
//Add the song to a list or update a ListView.
|
||||
if (!playlist.contains(songName)) {
|
||||
playlist.add(songName);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:This method should open a new window or change the current scene to display the "Playlist" page.
|
||||
|
||||
public void openPlaylistWindow() {
|
||||
//Create a new stage and show the playlist UI.
|
||||
@FXML
|
||||
private void handleOpenPlaylist(ActionEvent event) {
|
||||
openPlaylistWindow(event);
|
||||
}
|
||||
|
||||
|
||||
public void openPlaylistWindow(ActionEvent event) {
|
||||
try {
|
||||
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("playlist-view.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load(), 400, 400);
|
||||
stage.setScene(scene);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
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<String> playlistListView;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
playlistListView.getItems().addAll(MusicController.playlist);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleBackButton(ActionEvent event) {
|
||||
try {
|
||||
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
|
||||
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("App-view.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load());
|
||||
stage.setScene(scene);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10">
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
|
||||
<!-- TODO: Add your code here! -->
|
||||
<VBox xmlns="http://javafx.com/fxml" xmlns:fx="http://javafx.com/fxml" alignment="CENTER" spacing="10" fx:controller="sbu.javafx.MusicController">
|
||||
<padding>
|
||||
<Insets top="20" right="20" left="20" bottom="20"/>
|
||||
</padding>
|
||||
|
||||
<Label text="Music Player" />
|
||||
|
||||
<VBox spacing="10">
|
||||
|
||||
<HBox spacing="20" alignment="CENTER">
|
||||
<Label text="Song Title" prefWidth="120" />
|
||||
<Label text="Artist Name" prefWidth="120" />
|
||||
<Label text="Duration" prefWidth="80" />
|
||||
<Label text="Add to Playlist" prefWidth="120" />
|
||||
<Label text="Play" prefWidth="60" />
|
||||
</HBox>
|
||||
|
||||
<HBox spacing="20" alignment="CENTER">
|
||||
<Label text="Song of Dawn" prefWidth="120" />
|
||||
<Label text="Alice Johnson" prefWidth="120" />
|
||||
<Label text="03:45" prefWidth="80" />
|
||||
<Button text="Add to Playlist" prefWidth="120" onAction="#addSong1" />
|
||||
<Button text="Play" prefWidth="60" onAction="#playSong1" />
|
||||
</HBox>
|
||||
|
||||
<HBox spacing="20" alignment="CENTER">
|
||||
<Label text="Midnight Drive" prefWidth="120" />
|
||||
<Label text="The Night Owls" prefWidth="120" />
|
||||
<Label text="04:12" prefWidth="80" />
|
||||
<Button text="Add to Playlist" prefWidth="120" onAction="#addSong2" />
|
||||
<Button text="Play" prefWidth="60" onAction="#playSong2" />
|
||||
</HBox>
|
||||
|
||||
<HBox spacing="20" alignment="CENTER">
|
||||
<Label text="Echoes of You" prefWidth="120" />
|
||||
<Label text="Luna Sky" prefWidth="120" />
|
||||
<Label text="05:08" prefWidth="80" />
|
||||
<Button text="Add to Playlist" prefWidth="120" onAction="#addSong3" />
|
||||
<Button text="Play" prefWidth="60" onAction="#playSong3" />
|
||||
</HBox>
|
||||
</VBox>
|
||||
|
||||
<HBox spacing="20" alignment="CENTER">
|
||||
<Label fx:id="nowPlayingLabel" text="Now Playing: -" prefWidth="350" />
|
||||
<Button text="Open Playlist" onAction="#handleOpenPlaylist" />
|
||||
</HBox>
|
||||
</VBox>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<VBox spacing="15" alignment="TOP_CENTER" xmlns:fx="http://javafx.com/fxml" fx:controller="sbu.javafx.PlaylistController">
|
||||
<padding>
|
||||
<Insets top="20" right="20" bottom="20" left="20"/>
|
||||
</padding>
|
||||
|
||||
<Label text="Your Playlist" />
|
||||
|
||||
<ListView fx:id="playlistListView" prefHeight="250" />
|
||||
|
||||
<Button text="Back to Player" onAction="#handleBackButton" />
|
||||
</VBox>
|
||||
Reference in New Issue
Block a user