1 Commits
Author SHA1 Message Date
neda c5da2948c3 javafx 2026-07-19 06:21:59 +03:30
6 changed files with 174 additions and 28 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="23" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_26" project-jdk-name="26" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
+5 -2
View File
@@ -2,7 +2,10 @@ 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);
}
} }
+9 -8
View File
@@ -3,21 +3,22 @@ package sbu.javafx;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.image.Image;
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 = new FXMLLoader(getClass().getResource("App-view.fxml"));
Scene scene = new Scene(fxmlLoader.load());
Scene scene = new Scene(loader.load(), 700, 500);
stage.setTitle("Music Player"); stage.setTitle("Music Player");
stage.setScene(scene); stage.setScene(scene);
//TODO: add icon to the stage
stage.show(); stage.show();
} }
} }
+65 -10
View File
@@ -1,31 +1,86 @@
package sbu.javafx; package sbu.javafx;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.event.ActionEvent; 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.layout.VBox;
import javafx.stage.Stage;
public class MusicController { 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. private ObservableList<String> playlist =
FXCollections.observableArrayList();
@FXML @FXML
public void handlePlayAction() { public void playSong1() {
//Update labels, change button icons, etc. handlePlayAction("Shape of You");
} }
//TODO: Logic to add a specific song to the user's playlist. @FXML
public void playSong2() {
handlePlayAction("Believer");
}
@FXML
public void playSong3() {
handlePlayAction("Perfect");
}
public void handlePlayAction(String songName) {
nowPlayingLabel.setText("Now Playing: " + songName);
}
@FXML
public void addSong1() {
addToPlaylist("Shape of You");
}
@FXML
public void addSong2() {
addToPlaylist("Believer");
}
@FXML
public void addSong3() {
addToPlaylist("Perfect");
}
public void addToPlaylist(String songName) { 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. }
@FXML
public void openPlaylistWindow() { public void openPlaylistWindow() {
//Create a new stage and show the playlist UI.
Stage stage = new Stage();
VBox root = new VBox(10);
Label title = new Label("My Playlist");
ListView<String> listView = new ListView<>();
listView.setItems(playlist);
root.getChildren().addAll(title, listView);
Scene scene = new Scene(root, 300, 400);
stage.setTitle("Playlist");
stage.setScene(scene);
stage.show();
} }
} }
+83 -2
View File
@@ -1,8 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10">
<!-- TODO: Add your code here! --> <VBox xmlns="http://javafx.com/javafx/17"
xmlns:fx="http://javafx.com/fxml"
fx:controller="sbu.javafx.MusicController"
spacing="15"
alignment="TOP_CENTER">
<padding>
<Insets top="20" right="20" left="20" bottom="20"/>
</padding>
<Label text="Music Player"
style="-fx-font-size:22px; -fx-font-weight:bold;"/>
<Label fx:id="nowPlayingLabel"
text="Now Playing: None"
style="-fx-font-size:16px;"/>
<GridPane hgap="15" vgap="15">
<Label text="Shape of You"/>
<Label text="Ed Sheeran" GridPane.columnIndex="1"/>
<Label text="3:54" GridPane.columnIndex="2"/>
<Button text="Play"
onAction="#playSong1"
GridPane.columnIndex="3"/>
<Button text="Add to Playlist"
onAction="#addSong1"
GridPane.columnIndex="4"/>
<Label text="Believer"
GridPane.rowIndex="1"/>
<Label text="Imagine Dragons"
GridPane.columnIndex="1"
GridPane.rowIndex="1"/>
<Label text="3:20"
GridPane.columnIndex="2"
GridPane.rowIndex="1"/>
<Button text="Play"
onAction="#playSong2"
GridPane.columnIndex="3"
GridPane.rowIndex="1"/>
<Button text="Add to Playlist"
onAction="#addSong2"
GridPane.columnIndex="4"
GridPane.rowIndex="1"/>
<Label text="Perfect"
GridPane.rowIndex="2"/>
<Label text="Ed Sheeran"
GridPane.columnIndex="1"
GridPane.rowIndex="2"/>
<Label text="4:23"
GridPane.columnIndex="2"
GridPane.rowIndex="2"/>
<Button text="Play"
onAction="#playSong3"
GridPane.columnIndex="3"
GridPane.rowIndex="2"/>
<Button text="Add to Playlist"
onAction="#addSong3"
GridPane.columnIndex="4"
GridPane.rowIndex="2"/>
</GridPane>
<Button text="View Playlist"
onAction="#openPlaylistWindow"/>
</VBox> </VBox>