diff --git a/biblioteka.db b/biblioteka.db index 5ea8ff9..08e4013 100644 Binary files a/biblioteka.db and b/biblioteka.db differ diff --git a/src/library/Album.java b/src/library/Album.java index ef4056a..3a66c59 100644 --- a/src/library/Album.java +++ b/src/library/Album.java @@ -20,9 +20,15 @@ public class Album extends Item { } public Database d = new Database(); - Album(int id, String n, String m, int y, String c) { + Album(int id, String n, String m, String y, String c) { + try{ + this.setYear(Integer.parseInt(y)); + } + catch(NumberFormatException e){ + this.setYear(0); + } + this.setId(id); this.setName(n); - this.setYear(y); this.setCategory(c); this.setMusican(m); } diff --git a/src/library/AlbumFieldPattern.form b/src/library/AlbumFieldPattern.form index ea28a7a..a39815d 100644 --- a/src/library/AlbumFieldPattern.form +++ b/src/library/AlbumFieldPattern.form @@ -132,10 +132,8 @@ + - - - @@ -148,20 +146,18 @@ - - - - - - - - + + + + + + + + + - - - diff --git a/src/library/AlbumFieldPattern.java b/src/library/AlbumFieldPattern.java index c8401f6..91203e2 100644 --- a/src/library/AlbumFieldPattern.java +++ b/src/library/AlbumFieldPattern.java @@ -6,6 +6,8 @@ package library; import java.sql.SQLException; +import java.util.LinkedList; +import java.util.List; import javax.swing.JFrame; import javax.swing.JOptionPane; @@ -15,6 +17,9 @@ import javax.swing.JOptionPane; */ public class AlbumFieldPattern extends javax.swing.JFrame { + public boolean add = false, delete = false, edit = false, search = false; + private Database d = new Database(); + /** * Creates new form bookFieldPattern */ @@ -36,7 +41,25 @@ public class AlbumFieldPattern extends javax.swing.JFrame { musican.setInputVerifier(verify); year.setInputVerifier(verify); } - public boolean add = false, delete = false, edit = false, search = false; + + public void search(Album a) { + try { + List albums = new LinkedList<>(); + albums = d.selectAlbums(a); + Object[][] data = d.convertToTable(albums); + String[] columnNames = { + "ID", + "Tytuł", + "Muzyk/Zespół", + "Rok", + "Kategoria"}; + ListResult table = new ListResult(data, columnNames); + table.setVisible(true); + } catch (IndexOutOfBoundsException e) { + + //nothing to do here + } + } /** * This method is called from within the constructor to initialize the form. @@ -74,21 +97,12 @@ public class AlbumFieldPattern extends javax.swing.JFrame { lyear.setText("Rok:"); year.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N - year.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - yearActionPerformed(evt); - } - }); + year.setName("year"); // NOI18N lcategory.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N lcategory.setText("Gatunek:"); - Category.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Jazz", "Rap", "Rock", "Muzyka Klasyczna", "Reggae", "Pop", "Elektroniczna" })); - Category.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - CategoryActionPerformed(evt); - } - }); + Category.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { " ", "Jazz", "Rap", "Rock", "Muzyka Klasyczna", "Reggae", "Pop", "Elektroniczna" })); mainlabel.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N mainlabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); @@ -163,31 +177,24 @@ public class AlbumFieldPattern extends javax.swing.JFrame { this.SaveChanges.setText(s); } - private void CategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CategoryActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_CategoryActionPerformed - private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed if (this.add) { try { - Album a = new Album(0, albumTitle.getText(), musican.getText(), Integer.parseInt(year.getText()), Category.getSelectedItem().toString()); + Album a = new Album(0, albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString()); a.insertToDB(); this.dispose(); } catch (SQLException e) { e.getMessage(); } } else if (this.edit) { - JOptionPane.showMessageDialog(null, "EDYTUJ"); + Album a = new Album(0, albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString()); + this.search(a); } else if (this.delete) { JOptionPane.showMessageDialog(null, "USUŃ"); } }//GEN-LAST:event_SaveChangesActionPerformed - private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_yearActionPerformed - /** * @param args the command line arguments */ diff --git a/src/library/BookFieldPattern.java b/src/library/BookFieldPattern.java index 67a8293..a003997 100644 --- a/src/library/BookFieldPattern.java +++ b/src/library/BookFieldPattern.java @@ -49,6 +49,25 @@ public class BookFieldPattern extends javax.swing.JFrame { publishing.setInputVerifier(verify); } + public void search(Book b) { + try { + List books = new LinkedList<>(); + books = d.selectBooks(b); + Object[][] data = d.convertToTable(books); + String[] columnNames = {"ID", + "Tytuł", + "Imię Autora", + "Nazwisko Autora", + "Rok", + "ISBN", + "Wydawnictwo", + "Kategoria"}; + ListResult table = new ListResult(data, columnNames); + table.setVisible(true); + } catch (IndexOutOfBoundsException e) { + } + } + /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always @@ -264,27 +283,8 @@ public class BookFieldPattern extends javax.swing.JFrame { } } else if (this.edit) { - try { - Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString()); - List books = new LinkedList<>(); - //books = d.selectBooks(b); - d.selectBooks(b); - /*Object[][] data = d.convertToTable(books); - String[] columnNames = {"ID", - "Tytuł", - "Imię Autora", - "Nazwisko Autora", - "Rok", - "ISBN", - "Wydawnictwo", - "Kategoria"}; - ListResult table = new ListResult(data, columnNames); - table.setVisible(true);*/ - } catch (IndexOutOfBoundsException e) { - //nothing to do here - } - // ListResult l = new ListResult(); - + Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString()); + this.search(b); } else if (this.delete) { JOptionPane.showMessageDialog(null, "USUŃ"); } else if (this.search) { diff --git a/src/library/Database.java b/src/library/Database.java index 4ccc700..d49b74a 100644 --- a/src/library/Database.java +++ b/src/library/Database.java @@ -154,83 +154,80 @@ public class Database { return books; } - //public List selectBooks(Book searchData) { - public void selectBooks(Book searchData) { + public List selectBooks(Book searchData) { List books = new ArrayList<>(); - boolean EmptyAll = true; - //try { - List wheres = new ArrayList<>(); - if (searchData.getName().length() > 0) { - wheres.add("WHERE name LIKE '" + searchData.getName() + "'"); - System.out.println("WHERE name LIKE '" + searchData.getName() + "'"); - EmptyAll = false; - } - if (searchData.getAuthorName().length() > 0) { - wheres.add("WHERE author_name LIKE '" + searchData.getAuthorName() + "'"); - System.out.println("WHERE author_name LIKE '" + searchData.getAuthorName() + "'"); - EmptyAll = false; - } - if (searchData.getPublishing().length() > 0) { - wheres.add("WHERE publishing LIKE '" + searchData.getPublishing() + "'"); - System.out.println("WHERE publishing LIKE '" + searchData.getPublishing() + "'"); - EmptyAll = false; - } - if (searchData.getYear() > 0) { - wheres.add("WHERE year = " + searchData.getYear()); - System.out.println("WHERE year = " + searchData.getYear()); - EmptyAll = false; - } - if (searchData.getISBN().length() > 0) { - wheres.add("WHERE isbn LIKE " + searchData.getISBN()); - System.out.println("WHERE isbn LIKE '" + searchData.getISBN() + "'"); - EmptyAll = false; - } - if (searchData.getCategory().length() > 1) { - wheres.add("WHERE category LIKE '" + searchData.getCategory() + "'"); - System.out.println("WHERE category LIKE '" + searchData.getCategory() + "'"); - EmptyAll = false; - } - if (EmptyAll) { - System.out.println("PUSTO"); - } - - String query = "SELECT * FROM books"; - if (query.length() == 19) { - - } - /*ResultSet result = stat.executeQuery("SELECT * FROM books"); - int id, year; - String name, authorName, authorSurname, isbn, category, publishing; - while (result.next()) { - id = result.getInt("id"); - year = result.getInt("year"); - name = result.getString("name"); - authorName = result.getString("author_name"); - authorSurname = result.getString("author_surname"); - publishing = result.getString("publishing"); - isbn = result.getString("isbn"); - category = result.getString("category"); - books.add(new Book(id, name, authorName, authorSurname, year, isbn, publishing, category)); + String query = ""; + try { + List wheres = new ArrayList<>(); + if (searchData.getName().length() > 0) { + wheres.add("name LIKE '" + searchData.getName() + "'"); + } + if (searchData.getAuthorName().length() > 0) { + wheres.add("author_name LIKE '" + searchData.getAuthorName() + "'"); + } + if (searchData.getAuthorSurname().length() > 0) { + wheres.add("author_surname LIKE '" + searchData.getAuthorSurname() + "'"); + } + if (searchData.getPublishing().length() > 0) { + wheres.add("publishing LIKE '" + searchData.getPublishing() + "'"); + } + if (searchData.getYear() > 0) { + wheres.add("year = " + searchData.getYear()); + } + if (searchData.getISBN().length() > 0) { + wheres.add("isbn LIKE '" + searchData.getISBN() + "'"); + } + if (searchData.getCategory().length() > 1) { + wheres.add("category LIKE '" + searchData.getCategory() + "'"); + } + if (!wheres.isEmpty()) { + if (wheres.size() == 1) { + query = "SELECT * FROM books WHERE " + wheres.get(0) + ";"; + } else if (wheres.size() > 1) { + for (int i = 0; i < wheres.size(); i++) { + if (i == 0) { + query = "SELECT * FROM books WHERE " + wheres.get(0); + } else if (i > 0 && i < wheres.size() - 1) { + query += " AND " + wheres.get(i); + } else if (i == wheres.size() - 1) { + query += " AND " + wheres.get(i) + ";"; + } + } + } + System.out.println(query); + ResultSet result = stat.executeQuery(query); + int id; + String name, authorName, authorSurname, isbn, category, publishing, year; + while (result.next()) { + id = result.getInt("id"); + year = result.getString("year"); + name = result.getString("name"); + authorName = result.getString("author_name"); + authorSurname = result.getString("author_surname"); + publishing = result.getString("publishing"); + isbn = result.getString("isbn"); + category = result.getString("category"); + books.add(new Book(id, name, authorName, authorSurname, year, isbn, publishing, category)); + } } } catch (SQLException e) { JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE); } - return books;*/ + return books; } public List selectAlbums() { List albums = new ArrayList(); try { ResultSet result = stat.executeQuery("SELECT * FROM albums"); - int id, year; - String name, musican, category; + int id; + String name, musican, category, year; while (result.next()) { id = result.getInt("id"); - year = result.getInt("year"); + year = result.getString("year"); name = result.getString("name"); musican = result.getString("musican"); category = result.getString("category"); - albums.add(new Album(id, name, musican, year, category)); } } catch (SQLException e) { @@ -239,20 +236,69 @@ public class Database { return albums; } + public List selectAlbums(Album searchData) { + List albums = new ArrayList<>(); + String query = ""; + try { + List wheres = new ArrayList<>(); + if (searchData.getName().length() > 0) { + wheres.add("name LIKE '" + searchData.getName() + "'"); + } + if (searchData.getMusican().length() > 0) { + wheres.add("musican LIKE '" + searchData.getMusican() + "'"); + } + if (searchData.getYear() > 0) { + wheres.add("year = " + searchData.getYear()); + } + if (searchData.getCategory().length() > 1) { + wheres.add("category LIKE '" + searchData.getCategory() + "'"); + } + if (!wheres.isEmpty()) { + if (wheres.size() == 1) { + query = "SELECT * FROM albums WHERE " + wheres.get(0) + ";"; + } else if (wheres.size() > 1) { + for (int i = 0; i < wheres.size(); i++) { + if (i == 0) { + query = "SELECT * FROM albums WHERE " + wheres.get(0); + } else if (i > 0 && i < wheres.size() - 1) { + query += " AND " + wheres.get(i); + } else if (i == wheres.size() - 1) { + query += " AND " + wheres.get(i) + ";"; + } + } + } + System.out.println(query); + ResultSet result = stat.executeQuery(query); + int id; + String name, musican, category, year; + while (result.next()) { + id = result.getInt("id"); + year = result.getString("year"); + name = result.getString("name"); + musican = result.getString("musican"); + category = result.getString("category"); + albums.add(new Album(id, name, musican, year, category)); + } + } + } catch (SQLException e) { + JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE); + } + return albums; + } + public List selectMovies() { List movies = new ArrayList(); try { ResultSet result = stat.executeQuery("SELECT * FROM movies"); - int id, year; - String name, category, director; + int id; + String name, category, director, year; while (result.next()) { id = result.getInt("id"); - year = result.getInt("year"); + year = result.getString("year"); name = result.getString("name"); director = result.getString("director"); category = result.getString("category"); movies.add(new Movie(id, name, director, year, category)); - } } catch (SQLException e) { JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE); @@ -260,6 +306,57 @@ public class Database { return movies; } + public List selectMovies(Movie searchData) { + List movies = new ArrayList<>(); + String query = ""; + try { + List wheres = new ArrayList<>(); + if (searchData.getName().length() > 0) { + wheres.add("name LIKE '" + searchData.getName() + "'"); + } + if (searchData.getDirector().length() > 0) { + wheres.add("director LIKE '" + searchData.getDirector() + "'"); + } + if (searchData.getYear() > 0) { + wheres.add("year = " + searchData.getYear()); + } + if (searchData.getCategory().length() > 1) { + wheres.add("category LIKE '" + searchData.getCategory() + "'"); + } + if (!wheres.isEmpty()) { + if (wheres.size() == 1) { + query = "SELECT * FROM movies WHERE " + wheres.get(0) + ";"; + } else if (wheres.size() > 1) { + for (int i = 0; i < wheres.size(); i++) { + if (i == 0) { + query = "SELECT * FROM movies WHERE " + wheres.get(0); + } else if (i > 0 && i < wheres.size() - 1) { + query += " AND " + wheres.get(i); + } else if (i == wheres.size() - 1) { + query += " AND " + wheres.get(i) + ";"; + } + } + System.out.println(query); + ResultSet result = stat.executeQuery(query); + int id; + String name, category, director, year; + while (result.next()) { + id = result.getInt("id"); + year = result.getString("year"); + name = result.getString("name"); + director = result.getString("director"); + category = result.getString("category"); + movies.add(new Movie(id, name, director, year, category)); + } + } + } + + } catch (SQLException e) { + JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE); + } + return movies; + } + public int countAll(String tableName) { try { int count = 0; @@ -303,7 +400,7 @@ public class Database { return tab; } } catch (IndexOutOfBoundsException e) { - JOptionPane.showMessageDialog(null, "Baza danych pusta", "Error:", JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog(null, "Brak danych.", "Error:", JOptionPane.INFORMATION_MESSAGE); throw new IndexOutOfBoundsException("Poza zakresem"); } diff --git a/src/library/ListResult.form b/src/library/ListResult.form index 0bd187f..8a1fcb1 100644 --- a/src/library/ListResult.form +++ b/src/library/ListResult.form @@ -33,6 +33,10 @@ + + + + @@ -44,8 +48,10 @@ - - + + + + @@ -88,5 +94,16 @@ + + + + + + + + + + + diff --git a/src/library/ListResult.java b/src/library/ListResult.java index eda967a..28ed1dd 100644 --- a/src/library/ListResult.java +++ b/src/library/ListResult.java @@ -8,6 +8,8 @@ package library; import java.util.LinkedList; import java.util.List; import javax.swing.JFrame; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; /** * @@ -41,6 +43,7 @@ public class ListResult extends javax.swing.JFrame { mainlabel = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); table = new javax.swing.JTable(rows, columnsNames); + OK = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); @@ -62,6 +65,24 @@ public class ListResult extends javax.swing.JFrame { table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); jScrollPane1.setViewportView(table); + OK.setText("Wybierz pozycję..."); + OK.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + OKActionPerformed(evt); + } + }); + int row = table.getSelectedRow(); + + if(row == -1) + { + OK.setVisible(false); + } + else + { + + // do whatever you need to do with the data from the row + } + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -73,7 +94,10 @@ public class ListResult extends javax.swing.JFrame { .addComponent(mainlabel, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(23, 23, 23) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1180, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1180, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addGap(496, 496, 496) + .addComponent(OK, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(26, Short.MAX_VALUE)) ); layout.setVerticalGroup( @@ -82,13 +106,19 @@ public class ListResult extends javax.swing.JFrame { .addContainerGap() .addComponent(mainlabel) .addGap(13, 13, 13) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 533, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(30, Short.MAX_VALUE)) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 473, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(32, 32, 32) + .addComponent(OK) + .addContainerGap(33, Short.MAX_VALUE)) ); pack(); }// //GEN-END:initComponents + private void OKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OKActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_OKActionPerformed + /** * @param args the command line arguments */ @@ -103,20 +133,28 @@ public class ListResult extends javax.swing.JFrame { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; + } } } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(ListResult.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(ListResult.class + .getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(ListResult.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(ListResult.class + .getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(ListResult.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(ListResult.class + .getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(ListResult.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(ListResult.class + .getName()).log(java.util.logging.Level.SEVERE, null, ex); } // // - + /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { @@ -127,6 +165,7 @@ public class ListResult extends javax.swing.JFrame { } // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton OK; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel mainlabel; private javax.swing.JTable table; diff --git a/src/library/Movie.java b/src/library/Movie.java index c276a11..c5d6711 100644 --- a/src/library/Movie.java +++ b/src/library/Movie.java @@ -26,11 +26,16 @@ public class Movie extends Item { //nothing to do there } - Movie(int id, String n, String d, int y, String c) { + Movie(int id, String n, String d, String y, String c) { + try{ + this.setYear(Integer.parseInt(y)); + } + catch(NumberFormatException e){ + this.setYear(0); + } this.setId(id); this.setName(n); this.director = d; - this.setYear(y); this.setCategory(c); } diff --git a/src/library/MovieFieldPattern.form b/src/library/MovieFieldPattern.form index 6573f6e..7712900 100644 --- a/src/library/MovieFieldPattern.form +++ b/src/library/MovieFieldPattern.form @@ -154,15 +154,16 @@ - - - - - - - - - + + + + + + + + + + diff --git a/src/library/MovieFieldPattern.java b/src/library/MovieFieldPattern.java index 21b528d..0bbadda 100644 --- a/src/library/MovieFieldPattern.java +++ b/src/library/MovieFieldPattern.java @@ -6,6 +6,8 @@ package library; import java.sql.SQLException; +import java.util.LinkedList; +import java.util.List; import javax.swing.JFrame; import javax.swing.JOptionPane; @@ -15,6 +17,9 @@ import javax.swing.JOptionPane; */ public class MovieFieldPattern extends javax.swing.JFrame { + public boolean add = false, delete = false, edit = false, search = false; + private Database d = new Database(); + /** * Creates new form bookFieldPattern */ @@ -36,7 +41,6 @@ public class MovieFieldPattern extends javax.swing.JFrame { director.setInputVerifier(verify); year.setInputVerifier(verify); } - public boolean add = false, delete = false, edit = false, search = false; /** * This method is called from within the constructor to initialize the form. @@ -84,7 +88,7 @@ public class MovieFieldPattern extends javax.swing.JFrame { lcategory.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N lcategory.setText("Kategoria:"); - Category.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Kryminał", "Thriller", "Przygodowy", "Animowany", "Akcji", "Dla dzieci", "Komedia", "Horror" })); + Category.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { " ", "Kryminał", "Thriller", "Przygodowy", "Animowany", "Akcji", "Dla dzieci", "Komedia", "Horror" })); Category.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { CategoryActionPerformed(evt); @@ -182,14 +186,29 @@ public class MovieFieldPattern extends javax.swing.JFrame { private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed if (this.add) { try { - Movie m = new Movie(0, movieTitle.getText(), director.getText(), Integer.parseInt(year.getText()), Category.getSelectedItem().toString()); + Movie m = new Movie(0, movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString()); m.insertToDB(); this.dispose(); } catch (SQLException e) { e.getMessage(); } } else if (this.edit) { - JOptionPane.showMessageDialog(null, "EDYTUJ"); + try { + List movies = new LinkedList<>(); + Movie m = new Movie(0, movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString()); + movies = d.selectMovies(m); + Object[][] data = d.convertToTable(movies); + String[] columnNames = { + "ID", + "Tytuł", + "Reżyser", + "Rok", + "Kategoria"}; + ListResult table = new ListResult(data, columnNames); + table.setVisible(true); + } catch (IndexOutOfBoundsException e) { + //nothing to do here + } } else if (this.delete) { JOptionPane.showMessageDialog(null, "USUŃ"); }