Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package playmymusic;
  7.  
  8. import javafx.beans.property.IntegerProperty;
  9. import javafx.beans.property.SimpleIntegerProperty;
  10. import javafx.beans.property.SimpleStringProperty;
  11. import javafx.beans.property.StringProperty;
  12.  
  13. /**
  14. *
  15. * @author man
  16. */
  17. public class SongContent
  18. {
  19. private final StringProperty artist;
  20. private final StringProperty title;
  21. private final StringProperty genre;
  22. private static IntegerProperty id;
  23.  
  24. public SongContent(int id, String artist, String title, String genre)
  25. {
  26. this.artist = new SimpleStringProperty(artist);
  27. this.title = new SimpleStringProperty(title);
  28. this.genre = new SimpleStringProperty(genre);
  29. this.id = new SimpleIntegerProperty(id);
  30. }
  31.  
  32. public Integer getId()
  33. {
  34. return id.get();
  35. }
  36. public void setID(int paramId)
  37. {
  38. id.set(paramId);
  39. }
  40.  
  41. public String getArtist()
  42. {
  43. return artist.get();
  44. }
  45. public void setArtist(String paramArtist)
  46. {
  47. artist.set(paramArtist);
  48. }
  49.  
  50. public String getTitle()
  51. {
  52. return title.get();
  53. }
  54. public void setTitle(String paramTitle)
  55. {
  56. title.set(paramTitle);
  57. }
  58.  
  59. public String getGenre()
  60. {
  61. return genre.get();
  62. }
  63. public void setGenre(String paramGenre)
  64. {
  65. genre.set(paramGenre);
  66. }
  67.  
  68. public StringProperty artistProperty(){return artist;}
  69. public StringProperty titleProperty(){return title;}
  70. public StringProperty genreProperty(){return genre;}
  71. public static IntegerProperty idProperty() { return id;}
  72. }
  73.  
  74. /*
  75. * To change this license header, choose License Headers in Project Properties.
  76. * To change this template file, choose Tools | Templates
  77. * and open the template in the editor.
  78. */
  79. package playmymusic;
  80.  
  81. import java.io.IOException;
  82. import java.net.URL;
  83. import java.sql.Connection;
  84. import java.sql.DriverManager;
  85. import java.sql.PreparedStatement;
  86. import java.sql.ResultSet;
  87. import java.sql.SQLException;
  88. import java.util.ResourceBundle;
  89. import javafx.beans.property.IntegerProperty;
  90. import javafx.collections.FXCollections;
  91. import javafx.collections.ObservableList;
  92. import javafx.event.ActionEvent;
  93. import javafx.fxml.FXML;
  94. import javafx.fxml.FXMLLoader;
  95. import javafx.fxml.Initializable;
  96. import javafx.scene.Scene;
  97. import javafx.scene.control.TableColumn;
  98. import javafx.scene.control.TableView;
  99. import javafx.scene.control.TextField;
  100. import javafx.scene.control.cell.PropertyValueFactory;
  101. import javafx.scene.layout.Pane;
  102. import javafx.stage.Stage;
  103. import javax.swing.JOptionPane;
  104. import org.apache.derby.jdbc.ClientDriver;
  105. /**
  106. *
  107. * @author man
  108. */
  109. public class FXMLDocumentController implements Initializable {
  110. public LoginModel loginModel = new LoginModel();
  111.  
  112. @FXML
  113. private TextField txtUsername;
  114. @FXML
  115. private TextField txtPassword;
  116.  
  117. @FXML
  118. private TextField txtArtist;
  119. @FXML
  120. private TextField fxTitle;
  121. @FXML
  122. private TextField fxGenre;
  123.  
  124. @FXML
  125. private TableView<SongContent> tableView;
  126.  
  127. @FXML
  128. private TableColumn<SongContent, Integer> id;
  129.  
  130. @FXML
  131. private TableColumn<SongContent, String> artist;
  132. @FXML
  133. private TableColumn<SongContent, String> title;
  134. @FXML
  135. private TableColumn<SongContent, String> genre;
  136.  
  137. private ObservableList<SongContent> data;
  138.  
  139.  
  140. @FXML
  141. private void Login(ActionEvent event) throws SQLException {
  142. try {
  143. if(loginModel.isLogin(txtUsername.getText(), txtPassword.getText()))
  144. {
  145. Stage primaryStage = new Stage();
  146. FXMLLoader loader = new FXMLLoader();
  147. Pane root = loader.load(getClass().getResource("PopUpWindow.fxml").openStream());
  148.  
  149. Scene scene = new Scene(root, 785, 809);
  150. primaryStage.setScene(scene);
  151. primaryStage.show();
  152.  
  153. PlayMyMusic.primaryStage.close();
  154. }else
  155. {
  156. System.out.println("WOOPS");
  157. }
  158. } catch (IOException e) {
  159. // TODO Auto-generated catch block
  160. e.printStackTrace();
  161. }
  162. }
  163.  
  164.  
  165. @FXML
  166. private void songs(ActionEvent e) throws SQLException, ClassNotFoundException
  167. {
  168.  
  169. loginModel.insertSongs(txtArtist.getText(), fxTitle.getText(), fxGenre.getText());
  170. try
  171. {
  172. int i = 1;
  173. Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/PlayMyMusicDB;user=test;password=test");
  174. data = FXCollections.observableArrayList();
  175.  
  176. ResultSet rs = conn.createStatement().executeQuery("select * from Song");
  177. while(rs.next())
  178. {
  179. data.add(new SongContent(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4)));
  180. i++;
  181. }
  182. }catch(SQLException ex) {
  183. System.err.println("Error" + ex);
  184. }
  185. id.setCellValueFactory(new PropertyValueFactory<>("id"));
  186. artist.setCellValueFactory(new PropertyValueFactory<>("artist"));
  187. title.setCellValueFactory(new PropertyValueFactory<>("title"));
  188. genre.setCellValueFactory(new PropertyValueFactory<>("genre"));
  189.  
  190. tableView.setItems(null);
  191. tableView.setItems(data);
  192. txtArtist.clear();
  193. fxTitle.clear();
  194. fxGenre.clear();
  195.  
  196. }
  197.  
  198. @FXML
  199. public void deleteItems(ActionEvent e) throws SQLException, ClassNotFoundException
  200. {
  201. Connection c = DriverManager.getConnection("jdbc:derby://localhost:1527/PlayMyMusicDB;user=test;password=test");
  202. int action = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete this item?");
  203. if(action == 0)
  204. {
  205. try
  206. {
  207. IntegerProperty i = SongContent.idProperty();
  208.  
  209. ResultSet rs = c.createStatement().executeQuery("DELETE FROM Song where i = " + i);
  210.  
  211.  
  212. }catch(Exception e1)
  213. {
  214. e1.printStackTrace();
  215. }
  216. }
  217. }
  218.  
  219.  
  220. @Override
  221. public void initialize(URL url, ResourceBundle rb)
  222. {
  223.  
  224. }
  225. }
  226. `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement