Description of the subject area
The subject area is a media player similar to iTunes. The main entities in this database are the user and the collection of compositions.
Each song belongs to only one artist and one album, but many users can add them. Each user can add an unlimited number of songs.
Each user must have a unique mail and password that can be repeated, thanks to this information, the user can log into his account. Also, the following fields are mandatory for users when registering: name, phone number, country of residence, subscription start date and subscription end date. After correct login or successful registration, the user is taken to the main page, where the user is presented with a selection of tracks from different artists, among which he can choose the ones he likes and add them to his playlist. The number of added tracks is not limited. Each user has his own personal account, in which he can view the added music, delete it, and there is also an option to view the user's personal data entered by him during registration.The user at any time can delete his account along with all its contents and his data from the system.
Building a logical model
Using the description of the subject area, we built a logical model
Note
-- «USERS» «TRACK LIST» «SUBSCRIPTION VALIDITY», .
.
.
Building a relational model
The logical model was converted to relational using Oracle SQL Developer Data Modeler
Conformity to normal forms
All tables of this model correspond to 1NF, because all attributes have only a single value for each record, which excludes multiplicity.
All tables are in second normal form, since every non-key attribute is irreducibly dependent on a primary key.
All tables are in third normal form, since each non-key attribute is nontransitively dependent on the primary key. There is no dependence of a non-key attribute on another non-key attribute.
All tables correspond to NFBC, because the determinants of all functional dependencies are potential keys.
Explanation of functional dependencies
Database and application creation
The database is created on the local phpMyAdmin server. The result of the program is shown below:
Available pages
/
Testing the program
Testing how the application reacts to expected input and testing button health
Let's check the correctness of the application's reaction to the expected input data + the operability of all fields, buttons and drop-down lists.
Checking the correctness of user registration
Verify that the Add Music to User Library button is working correctly
«FALSE ALARM by THE WEEKND»
«FALSE ALARM by THE WEEKND»
«FALSE ALARM by THE WEEKND» «TRACK LIST» 32
«MY MUSIC», 32
«FALSE ALARM by THE WEEKND»
«FALSE ALARM by THE WEEKND» «TRACK LIST» 32
«MY MUSIC», 32
Checking if the button to delete music from the user's library works correctly
«FALSE ALARM by THE WEEKND»
«FALSE ALARM by THE WEEKND»
«MY MUSIC», 32
32 «TRACK LIST»
«FALSE ALARM by THE WEEKND»
«MY MUSIC», 32
32 «TRACK LIST»
Checking if the button for sorting music by artist works correctly
«MUSE»
«KASABIAN»
«KASABIAN»
Checking the correct operation of the button for deleting a user account from the system
«ivanivanov@mail.ru»
«Delete user from system»
«USERS», 18
«Delete user from system»
«USERS», 18
Testing the Application Response to Erroneous Input
When entering incorrect data, the program notifies the user about it
Incorrect name entry error
Invalid email entry error
Incorrect phone number entered error
An error that occurs when trying to duplicate the credentials of an existing user
An error that occurs when trying to enter credentials of a non-existent user
Everything works for the expected data entry. For the absence of input and for incorrect input, the program issues a warning
Applications
Appendix 1 - code for creating tables
Code for creating tables in Oracle Data Modeler
-- Generated by Oracle SQL Developer Data Modeler 19.4.0.350.1424
-- at: 2020-06-01 16:18:08 MSK
-- site: Oracle Database 11g
-- type: Oracle Database 11g
CREATE TABLE albums (
id VARCHAR2(5) NOT NULL,
album_name VARCHAR2(20) NOT NULL,
release_year DATE NOT NULL,
genre VARCHAR2(20) NOT NULL
);
ALTER TABLE albums ADD CONSTRAINT albums_pk PRIMARY KEY ( id );
CREATE TABLE my_music (
user_id VARCHAR2(5) NOT NULL,
my_msc_id NUMBER NOT NULL
);
CREATE UNIQUE INDEX my_music__idx ON
my_music (
user_id
ASC );
ALTER TABLE my_music ADD CONSTRAINT my_msc_pk PRIMARY KEY ( my_msc_id );
CREATE TABLE performers (
id VARCHAR2(5) NOT NULL,
performer_name VARCHAR2(30) NOT NULL
);
ALTER TABLE performers ADD CONSTRAINT performers_pk PRIMARY KEY ( id );
CREATE TABLE subscription_validity (
"Start_Date/_Start_Time" DATE NOT NULL,
"End_Date/_End_Time" DATE NOT NULL,
user_id VARCHAR2(5) NOT NULL,
track_list_id VARCHAR2(5) NOT NULL
);
ALTER TABLE subscription_validity ADD CONSTRAINT subscription_validity_pk PRIMARY KEY ( user_id,
track_list_id );
CREATE TABLE songs (
id VARCHAR2(5) NOT NULL,
track_name VARCHAR2(50) NOT NULL,
genre VARCHAR2(20) NOT NULL,
duration TIMESTAMP NOT NULL,
albums_id VARCHAR2(5) NOT NULL,
performers_id VARCHAR2(5) NOT NULL,
my_music_my_msc_id NUMBER NOT NULL
);
ALTER TABLE track_list ADD CONSTRAINT track_list_pk PRIMARY KEY ( id );
CREATE TABLE "USER" (
id VARCHAR2(5) NOT NULL,
password VARCHAR2(20) NOT NULL,
name VARCHAR2(30) NOT NULL,
email VARCHAR2(30) NOT NULL,
phone_number VARCHAR2(12) NOT NULL,
country VARCHAR2(20) NOT NULL,
balance NUMBER(7, 2),
my_music_my_msc_id NUMBER NOT NULL
);
CREATE UNIQUE INDEX user__idx ON
"USER" (
my_music_my_msc_id
ASC );
ALTER TABLE "USER" ADD CONSTRAINT user_pk PRIMARY KEY ( id );
ALTER TABLE my_music
ADD CONSTRAINT my_music_user_fk FOREIGN KEY ( user_id )
REFERENCES "USER" ( id );
ALTER TABLE subscription_validity
ADD CONSTRAINT subs_val_track_list_fk FOREIGN KEY ( track_list_id )
REFERENCES track_list ( id );
ALTER TABLE subscription_validity
ADD CONSTRAINT subs_val_user_fk FOREIGN KEY ( user_id )
REFERENCES "USER" ( id );
ALTER TABLE track_list
ADD CONSTRAINT track_list_albums_fk FOREIGN KEY ( albums_id )
REFERENCES albums ( id );
ALTER TABLE track_list
ADD CONSTRAINT track_list_my_music_fk FOREIGN KEY ( my_music_my_msc_id )
REFERENCES my_music ( my_msc_id );
ALTER TABLE track_list
ADD CONSTRAINT track_list_performers_fk FOREIGN KEY ( performers_id )
REFERENCES performers ( id );
ALTER TABLE "USER"
ADD CONSTRAINT user_my_music_fk FOREIGN KEY ( my_music_my_msc_id )
REFERENCES my_music ( my_msc_id );
CREATE SEQUENCE my_msc_my_msc_id_seq START WITH 1 NOCACHE ORDER;
CREATE OR REPLACE TRIGGER my_msc_my_msc_id_trg BEFORE
INSERT ON my_music
FOR EACH ROW
WHEN ( new.my_msc_id IS NULL )
BEGIN
:new.my_msc_id := my_msc_my_msc_id_seq.nextval;
END;
/
-- Oracle SQL Developer Data Modeler Summary Report:
--
-- CREATE TABLE 6
-- CREATE INDEX 2
-- ALTER TABLE 13
-- CREATE VIEW 0
-- ALTER VIEW 0
-- CREATE PACKAGE 0
-- CREATE PACKAGE BODY 0
-- CREATE PROCEDURE 0
-- CREATE FUNCTION 0
-- CREATE TRIGGER 1
-- ALTER TRIGGER 0
-- CREATE COLLECTION TYPE 0
-- CREATE STRUCTURED TYPE 0
-- CREATE STRUCTURED TYPE BODY 0
-- CREATE CLUSTER 0
-- CREATE CONTEXT 0
-- CREATE DATABASE 0
-- CREATE DIMENSION 0
-- CREATE DIRECTORY 0
-- CREATE DISK GROUP 0
-- CREATE ROLE 0
-- CREATE ROLLBACK SEGMENT 0
-- CREATE SEQUENCE 1
-- CREATE MATERIALIZED VIEW 0
-- CREATE MATERIALIZED VIEW LOG 0
-- CREATE SYNONYM 0
-- CREATE TABLESPACE 0
-- CREATE USER 0
--
-- DROP TABLESPACE 0
-- DROP DATABASE 0
--
-- REDACTION POLICY 0
--
-- ORDS DROP SCHEMA 0
-- ORDS ENABLE SCHEMA 0
-- ORDS ENABLE OBJECT 0
--
-- ERRORS 0
-- WARNINGS 0
Appendix 2 - program code
DataBase class
package sample.database;
import javafx.event.ActionEvent;
import sample.model.Performers;
import sample.model.TrackList;
import sample.model.User;
import java.sql.*;
import java.util.ArrayList;
public class DataBase {
public static void main(String[] args) {
DataBase dataBase = new DataBase();
for (TrackList t:dataBase.allMusic()
) {
System.out.println(t.toString());
}
}
//
public boolean loginIn(String email, String password) {
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
Statement stmt = conn.createStatement();
// ( )
ResultSet rset = stmt.executeQuery("SELECT * FROM users u INNER JOIN subscription_validity s ON u.id_users=s.id_users where email = '" + email + "'&& password ='" + password + "'");
if (rset.next()) {
User.setId(rset.getInt(1));
User.setName(rset.getString(3));
User.setEmail(rset.getString(4));
User.setPhone(rset.getString(5));
User.setCountry(rset.getString(6));
User.setStartDate(rset.getString(8));
User.setEndDate(rset.getString(9));
return true;
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public boolean emailCheck(String email) {
try {
// db
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
// Statement
Statement stmt = conn.createStatement();
//
ResultSet rset = stmt.executeQuery("select * from users where email = '" + email + "'");
return !rset.next();
} catch (SQLException e) {
e.printStackTrace();
}
return true;
}
public void registration(String name, String email, String phone, String password, String country, String startDate, String endDate) {
try {
// db
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
// Statement
Statement stmt = conn.createStatement();
// users
stmt.executeUpdate("insert into users (email,password,name,phone_num,contry) value ('" + email + "','" + password + "','" + name + "','" + phone + "','" + country + "')");
// subscription_validity
stmt.executeUpdate("insert into subscription_validity (Start_Date_Start_Time, End_Date_End_Time,id_users) value ('" + startDate + "','" + endDate + "', (select max(id_users) from users) )");
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
//
public ArrayList<TrackList> allMusic() {
ArrayList<TrackList> arrayList = new ArrayList<>();
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
Statement stmt = conn.createStatement();
//
ResultSet rset = stmt.executeQuery("SELECT * FROM track_list t INNER JOIN performers p ON p.id_performers=t.id_performers INNER JOIN albums a ON a.id_albums=t.id_albums");
while (rset.next()) {
arrayList.add(new TrackList(rset.getInt(1), rset.getString(2), rset.getString(10), rset.getString(8), rset.getString(3), rset.getString(4)));
}
rset.close();
stmt.close();
conn.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return arrayList;
}
//
public ArrayList<TrackList> myMusic(int id) {
ArrayList<TrackList> arrayList = new ArrayList<>();
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
Statement stmt = conn.createStatement();
//
ResultSet rset = stmt.executeQuery("SELECT m.id_track_list, t.track_name, " +
"a.album_name, p.performer_name, t.genre, t.duration FROM my_music m INNER JOIN " +
"track_list t ON t.id_track_list=m.id_track_list INNER JOIN performers p ON " +
"p.id_performers=t.id_performers INNER JOIN albums a ON a.id_albums=t.id_albums WHERE m.id_users=" + id);
while (rset.next()) {
arrayList.add(new TrackList(rset.getInt(1), rset.getString(2), rset.getString(3), rset.getString(4), rset.getString(5), rset.getString(6)));
}
rset.close();
stmt.close();
conn.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return arrayList;
}
public void addMyMusic(int idUser, int idTrackList) {
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("SELECT * FROM my_music WHERE " +
"id_users = " + idUser + " && id_track_list = " + idTrackList);
// id user,
//
if (!rset.next())
stmt.executeUpdate("INSERT INTO my_music (id_users, id_track_list) VALUE ("+ idUser +", "+ idTrackList +")");
rset.close();
stmt.close();
conn.close();
//
} catch (SQLException e){
e.printStackTrace();
}
}
public void deleteMyMusic(int idUser, int idTrackList) {
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
Statement stmt = conn.createStatement();
stmt.executeUpdate("DELETE FROM my_music WHERE id_users =" + idUser + "&& id_track_list =" + idTrackList);
stmt.close();
conn.close();
} catch (SQLException e){
e.printStackTrace();
}
}
//
public ArrayList<Performers> performers(){
ArrayList<Performers> arrayList = new ArrayList();
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("SELECT * FROM performers");
while(rset.next()){
arrayList.add(new Performers(rset.getInt(1),rset.getString(2)));
}
rset.close();
stmt.close();
conn.close();
} catch (SQLException e){
e.printStackTrace();
}
return arrayList;
}
//
public ArrayList<TrackList> performerMusic(int id) {
ArrayList<TrackList> arrayList = new ArrayList<>();
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
Statement stmt = conn.createStatement();
//
ResultSet rset = stmt.executeQuery("SELECT * FROM track_list t INNER JOIN performers p ON p.id_performers=t.id_performers INNER JOIN albums a ON a.id_albums=t.id_albums WHERE p.id_performers = " + id);
while (rset.next()) {
arrayList.add(new TrackList(rset.getInt(1), rset.getString(2), rset.getString(10), rset.getString(8), rset.getString(3), rset.getString(4)));
}
rset.close();
stmt.close();
conn.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return arrayList;
}
//
public void deleteUser(int idUser) {
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
Statement stmt = conn.createStatement();
stmt.executeUpdate("DELETE FROM users WHERE id_users =" + idUser);
stmt.close();
conn.close();
} catch (SQLException e){
e.printStackTrace();
}
}
}
Main class
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/login.fxml"));
Stage newStage = new Stage();
newStage.setScene(new Scene(root));
newStage.initModality(Modality.NONE);
newStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Music class
package sample;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListView;
import javafx.stage.Modality;
import javafx.stage.Stage;
import sample.database.DataBase;
import sample.model.Performers;
import sample.model.TrackList;
import sample.model.User;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
public class Music implements Initializable {
@FXML
public ListView<TrackList> allMusic;
@FXML
public ComboBox comboBox;
@FXML
public Button myMusic;
DataBase dataBase = new DataBase();
ArrayList<TrackList> arrayList;
TrackList trackList = null;
public void addMyMusic(ActionEvent actionEvent) {
// " "
if(trackList != null)
dataBase.addMyMusic(User.getId(),trackList.getId());
}
@Override
public void initialize(URL location, ResourceBundle resources) {
arrayList = dataBase.allMusic();
ObservableList<TrackList> observableList = FXCollections.observableList(arrayList);
allMusic.setItems(observableList);
allMusic.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TrackList>(){
@Override
public void changed(ObservableValue<? extends TrackList> observable, TrackList oldValue, TrackList newValue) {
trackList = newValue;
}
});
for (Performers p:dataBase.performers()
) {
comboBox.getItems().add(p);
}
comboBox.getItems().add(new Performers(0,"All"));
comboBox.setValue(new Performers(0,"All"));
comboBox.valueProperty().addListener(new ChangeListener<Performers>() {
@Override
public void changed(ObservableValue<? extends Performers> observable, Performers oldValue, Performers newValue) {
if(newValue.getId() == 0) {
arrayList = dataBase.allMusic();
ObservableList<TrackList> observableList = FXCollections.observableList(arrayList);
allMusic.setItems(observableList);
} else{
arrayList = dataBase.performerMusic(newValue.getId());
ObservableList<TrackList> observableList = FXCollections.observableList(arrayList);
allMusic.setItems(observableList);
}
}
});
}
public void myMusic(ActionEvent actionEvent) {
Stage stage = (Stage) myMusic.getScene().getWindow();
stage.close();
try {
Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/mymusic.fxml"));
Stage newStage = new Stage();
newStage.setScene(new Scene(root));
newStage.initModality(Modality.NONE);
newStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}
MyMusic class
package sample;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.stage.Modality;
import javafx.stage.Stage;
import sample.database.DataBase;
import sample.model.TrackList;
import sample.model.User;
import javax.jws.soap.SOAPBinding;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
public class MyMusic implements Initializable {
@FXML
public ListView allMusic;
@FXML
public Button back;
@FXML
public Button userData;
DataBase dataBase = new DataBase();
ArrayList<TrackList> arrayList;
TrackList trackList = null;
public void deleteMyMusic(ActionEvent actionEvent) {
if(trackList != null)
dataBase.deleteMyMusic(User.getId(),trackList.getId());
arrayList = dataBase.myMusic(User.getId());
ObservableList<TrackList> observableList = FXCollections.observableList(arrayList);
allMusic.setItems(observableList);
}
@Override
public void initialize(URL location, ResourceBundle resources) {
arrayList = dataBase.myMusic(User.getId());
ObservableList<TrackList> observableList = FXCollections.observableList(arrayList);
allMusic.setItems(observableList);
allMusic.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TrackList>(){
@Override
public void changed(ObservableValue<? extends TrackList> observable, TrackList oldValue, TrackList newValue) {
trackList = newValue;
}
});
}
public void userData(ActionEvent actionEvent) {
Stage stage = (Stage) userData.getScene().getWindow();
stage.close();
try {
Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/userdata.fxml"));
Stage newStage = new Stage();
newStage.setScene(new Scene(root));
newStage.initModality(Modality.NONE);
newStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
public void back(ActionEvent actionEvent) {
Stage stage = (Stage) back.getScene().getWindow();
stage.close();
try {
Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/music.fxml"));
Stage newStage = new Stage();
newStage.setScene(new Scene(root));
newStage.initModality(Modality.NONE);
newStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Registration class
package sample;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import sample.database.DataBase;
public class Registration {
@FXML
public Label error;
@FXML
public Button reg;
@FXML
public TextField phone;
@FXML
public PasswordField password;
@FXML
public PasswordField repeatPassword;
@FXML
public TextField name;
@FXML
public TextField email;
@FXML
public TextField endDate;
@FXML
public TextField startDate;
@FXML
public TextField country;
public void registration(ActionEvent actionEvent) {
DataBase dataBase = new DataBase();
// String name,String email,String phone, String password, String country, String startDate, String endDate
if(name.getText().matches("[a-zA-Zђ-Ї°-Џ]{3,}")){
if(email.getText().matches("[A-Za-z0-9]{3,}[@][A-Za-z0-9]{3,}[.][A-Za-z0-9]{2,}")){
if(phone.getText().matches("[+][7][0-9]{10}") || phone.getText().matches("[8][0-9]{10}")){
if(dataBase.emailCheck(email.getText())){
if(password.getText().equals(repeatPassword.getText())){
dataBase.registration(name.getText(),email.getText(),
phone.getText(),password.getText(),country.getText(), startDate.getText(), endDate.getText());
Stage stage = (Stage)reg.getScene().getWindow();
stage.close();
}else{
error.setText(" ");
}
}else{
error.setText(" ");
}
}else{
error.setText(" +7********** 8**********");
}
}else{
error.setText(" emeail ***@***.**");
}
}else{
error.setText(" ");
}
}
}
Userdata class
package sample;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.Modality;
import javafx.stage.Stage;
import sample.database.DataBase;
import sample.model.User;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
public class Userdata implements Initializable {
@FXML
public Label name;
@FXML
public Label email;
@FXML
public Label phone;
@FXML
public Label contry;
@FXML
public Label startDate;
@FXML
public Label endDate;
@FXML
public Button back;
@FXML
public Button delete;
@Override
public void initialize(URL location, ResourceBundle resources) {
name.setText(User.getName());
email.setText(User.getEmail());
phone.setText(User.getPhone());
contry.setText(User.getCountry());
startDate.setText(User.getStartDate());
endDate.setText(User.getEndDate());
}
public void back(ActionEvent actionEvent) {
Stage stage = (Stage) back.getScene().getWindow();
stage.close();
try {
Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/mymusic.fxml"));
Stage newStage = new Stage();
newStage.setScene(new Scene(root));
newStage.initModality(Modality.NONE);
newStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
public void delete(ActionEvent actionEvent) {
DataBase dataBase = new DataBase();
dataBase.deleteUser(User.getId());
Stage stage = (Stage) delete.getScene().getWindow();
stage.close();
try {
Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/login.fxml"));
Stage newStage = new Stage();
newStage.setScene(new Scene(root));
newStage.initModality(Modality.NONE);
newStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Performers class
package sample.model;
public class Performers {
private int id;
private String name;
public Performers(int id, String name) {
this.id = id;
this.name = name;
}
@Override
public String toString() {
return name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
TrackList class
package sample.model;
public class TrackList {
private int id;
private String trackName;
private String albumName;
private String performerName;
private String genre;
private String duration;
public TrackList(int id, String trackName, String albumName, String performerName, String genre, String duration) {
this.id = id;
this.trackName = trackName;
this.albumName = albumName;
this.performerName = performerName;
this.genre = genre;
this.duration = duration;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTrackName() {
return trackName;
}
public void setTrackName(String trackName) {
this.trackName = trackName;
}
public String getAlbumName() {
return albumName;
}
public void setAlbumName(String albumName) {
this.albumName = albumName;
}
public String getPerformerName() {
return performerName;
}
public void setPerformerName(String performerName) {
this.performerName = performerName;
}
public String getGenre() {
return genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
@Override
public String toString() {
return
trackName +
" by " + performerName +
" from album - " + albumName +
" (" + genre + ") " +
", " + duration;
}
}
User class
package sample.model;
public class User {
private static int id;
private static String name;
private static String email;
private static String phone;
private static String country;
private static String startDate;
private static String endDate;
public static int getId() {
return id;
}
public static void setId(int id) {
User.id = id;
}
public static String getName() {
return name;
}
public static void setName(String name) {
User.name = name;
}
public static String getEmail() {
return email;
}
public static void setEmail(String email) {
User.email = email;
}
public static String getPhone() {
return phone;
}
public static void setPhone(String phone) {
User.phone = phone;
}
public static String getCountry() {
return country;
}
public static void setCountry(String country) {
User.country = country;
}
public static String getStartDate() {
return startDate;
}
public static void setStartDate(String startDate) {
User.startDate = startDate;
}
public static String getEndDate() {
return endDate;
}
public static void setEndDate(String endDate) {
User.endDate = endDate;
}
}
Login class
package sample;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Modality;
import javafx.stage.Stage;
import sample.database.DataBase;
import java.io.IOException;
public class Login {
@FXML
public Button loginIn;
@FXML
public Button registration;
@FXML
public TextField email;
@FXML
public PasswordField password;
@FXML
public Label error;
public void loginIn(ActionEvent actionEvent) {
DataBase dataBase = new DataBase();
if(email.getText() != null ){
if(password.getText() != null){
if(dataBase.loginIn(email.getText(), password.getText())){
Stage stage = (Stage) loginIn.getScene().getWindow();
stage.close();
try {
Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/music.fxml"));
Stage newStage = new Stage();
newStage.setScene(new Scene(root));
newStage.initModality(Modality.NONE);
newStage.show();
} catch (IOException e) {
e.printStackTrace();
}
} else {
error.setText("This Login or Password does not exist");
}
} else {
error.setText("Please, enter your Password: ");
}
} else {
error.setText("Please, enter your Login: ");
}
}
public void registration(ActionEvent actionEvent) {
try {
Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/registration.fxml"));
Stage newStage = new Stage();
newStage.setScene(new Scene(root));
newStage.initModality(Modality.NONE);
newStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}