modyfikacja rekordów - sprawna

This commit is contained in:
Agnieszka Janicka 2016-06-10 19:30:10 +02:00
parent a7d40927a3
commit 71cf6237aa
13 changed files with 581 additions and 286 deletions

Binary file not shown.

Binary file not shown.

View File

@ -30,8 +30,9 @@
<Group type="103" groupAlignment="0" attributes="0">
<Component id="Title" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lmusican" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="idValue" alignment="0" min="-2" pref="57" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="56" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="49" max="-2" attributes="0"/>
<Component id="mainlabel" min="-2" pref="289" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
@ -59,9 +60,17 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="mainlabel" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="mainlabel" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="idValue" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="7" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="Title" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="albumTitle" alignment="3" min="-2" max="-2" attributes="0"/>
@ -182,5 +191,10 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="SaveChangesActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="idValue">
<Properties>
<Property name="text" type="java.lang.String" value="."/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -17,7 +17,7 @@ import javax.swing.JOptionPane;
*/
public class AlbumFieldPattern extends javax.swing.JFrame {
public boolean add = false, delete = false, edit = false, search = false;
public boolean add = false, delete = false, edit = false, search = false, update = false;
private Database d = new Database();
/**
@ -28,7 +28,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public AlbumFieldPattern(boolean required) {
public AlbumFieldPattern(boolean required, Album... a) {
initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Validation verify;
@ -40,9 +40,25 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
albumTitle.setInputVerifier(verify);
musican.setInputVerifier(verify);
year.setInputVerifier(verify);
try {
if (a[0].getId() >= 0) {
fillField(a[0]);
update = true;
}
} catch (ArrayIndexOutOfBoundsException e) {
//when only one parameter is defined
}
}
public void search(Album a) {
public void fillField(Album a) {
idValue.setText(Integer.toString(a.getId()));
albumTitle.setText(a.getName());
musican.setText(a.getMusican());
year.setText(Integer.toString(a.getYear()));
Category.setSelectedItem(a.getCategory());
}
public void search(Album a, String... mode) {
try {
List<Album> albums = new LinkedList<>();
albums = d.selectAlbums(a);
@ -53,8 +69,14 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
"Muzyk/Zespół",
"Rok",
"Kategoria"};
ListResult table = new ListResult(data, columnNames);
ListResult table = new ListResult(data, columnNames, "album");
table.setVisible(true);
if (mode[0].equals("edit")) {
table.setEnabledButton("edit");
}
if (mode[0].equals("delete")) {
table.setEnabledButton("delete");
}
} catch (IndexOutOfBoundsException e) {
//nothing to do here
@ -80,6 +102,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
Category = new javax.swing.JComboBox<>();
mainlabel = new javax.swing.JLabel();
SaveChanges = new javax.swing.JButton();
idValue = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
@ -116,6 +139,8 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
}
});
idValue.setText(".");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
@ -126,8 +151,9 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Title)
.addComponent(lmusican))
.addGap(56, 56, 56)
.addComponent(lmusican)
.addComponent(idValue, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(49, 49, 49)
.addComponent(mainlabel, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lyear, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
@ -148,8 +174,13 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(mainlabel)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(mainlabel)
.addGap(18, 18, 18))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(idValue)
.addGap(7, 7, 7)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Title)
.addComponent(albumTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
@ -188,11 +219,22 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
}
} else if (this.edit) {
Album a = new Album(0, albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString());
this.search(a);
this.search(a, "edit");
} else if (this.delete) {
JOptionPane.showMessageDialog(null, "USUŃ");
Album a = new Album(0, albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString());
this.search(a, "delete");
} else if (this.search) {
Album a = new Album(0, albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString());
this.search(a);
} else if (this.update) {
Album a = new Album(Integer.parseInt(idValue.getText()), albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString());
try {
d.updateQ(a);
} catch (SQLException e) {
e.printStackTrace();
}
}
dispose();
}//GEN-LAST:event_SaveChangesActionPerformed
/**
@ -239,6 +281,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
private javax.swing.JButton SaveChanges;
private javax.swing.JLabel Title;
private javax.swing.JTextField albumTitle;
private javax.swing.JLabel idValue;
private javax.swing.JLabel lcategory;
private javax.swing.JLabel lmusican;
private javax.swing.JLabel lyear;

View File

@ -26,18 +26,6 @@
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="Title" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="authorname" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="35" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="authorName" min="-2" pref="220" max="-2" attributes="0"/>
<Component id="bookTitle" min="-2" pref="363" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="20" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" max="-2" attributes="0">
<Component id="lcategory" max="32767" attributes="0"/>
@ -59,20 +47,39 @@
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="Title" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="authorname" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="35" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="authorName" min="-2" pref="220" max="-2" attributes="0"/>
<Component id="bookTitle" min="-2" pref="363" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" attributes="0">
<Component id="idValue" min="-2" pref="57" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="mainlabel" min="-2" pref="289" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="0" pref="20" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="mainlabel" min="-2" pref="289" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="71" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="mainlabel" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="mainlabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="idValue" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="Title" alignment="3" min="-2" max="-2" attributes="0"/>
@ -290,5 +297,10 @@
<AuxValue name="JavaCodeGenerator_AddingCodePost" type="java.lang.String" value="jLabel1.setVisible(false);"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="idValue">
<Properties>
<Property name="text" type="java.lang.String" value="."/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -20,7 +20,8 @@ import javax.swing.JOptionPane;
*/
public class BookFieldPattern extends javax.swing.JFrame {
public boolean add = false, delete = false, edit = false, search = false;
public boolean add = false, delete = false, edit = false, search = false, update = false;
public Book b;
private Database d = new Database();
public BookFieldPattern() {
@ -32,7 +33,7 @@ public class BookFieldPattern extends javax.swing.JFrame {
}
public BookFieldPattern(boolean required) {
public BookFieldPattern(boolean required, Book... b) {
initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Validation verify;
@ -47,9 +48,28 @@ public class BookFieldPattern extends javax.swing.JFrame {
year.setInputVerifier(verify);
ISBN.setInputVerifier(verify);
publishing.setInputVerifier(verify);
try {
if (b[0].getId() >= 0) {
fillField(b[0]);
update = true;
}
} catch (ArrayIndexOutOfBoundsException e) {
//when only one parameter is defined
}
}
public void search(Book b) {
public void fillField(Book b) {
idValue.setText(Integer.toString(b.getId()));
bookTitle.setText(b.getName());
authorName.setText(b.getAuthorName());
authorSurname.setText(b.getAuthorSurname());
publishing.setText(b.getPublishing());
year.setText(Integer.toString(b.getYear()));
ISBN.setText(b.getISBN());
Category.setSelectedItem(b.getCategory());
}
public void search(Book b, String... mode) {
try {
List<Book> books = new LinkedList<>();
books = d.selectBooks(b);
@ -62,8 +82,14 @@ public class BookFieldPattern extends javax.swing.JFrame {
"ISBN",
"Wydawnictwo",
"Kategoria"};
ListResult table = new ListResult(data, columnNames);
ListResult table = new ListResult(data, columnNames, "book");
table.setVisible(true);
if (mode[0].equals("edit")) {
table.setEnabledButton("edit");
}
if (mode[0].equals("delete")) {
table.setEnabledButton("delete");
}
} catch (IndexOutOfBoundsException e) {
}
}
@ -94,6 +120,7 @@ public class BookFieldPattern extends javax.swing.JFrame {
mainlabel = new javax.swing.JLabel();
SaveChanges = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
idValue = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
@ -181,6 +208,8 @@ public class BookFieldPattern extends javax.swing.JFrame {
jLabel1.setDoubleBuffered(true);
jLabel1.setName(""); // NOI18N
idValue.setText(".");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
@ -188,15 +217,6 @@ public class BookFieldPattern extends javax.swing.JFrame {
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Title)
.addComponent(authorname))
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(authorName, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bookTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 20, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(lcategory, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
@ -214,17 +234,30 @@ public class BookFieldPattern extends javax.swing.JFrame {
.addComponent(SaveChanges, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(mainlabel, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(71, 71, 71))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Title)
.addComponent(authorname))
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(authorName, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bookTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(idValue, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mainlabel, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 20, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(mainlabel)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(mainlabel)
.addComponent(idValue))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Title)
@ -281,13 +314,22 @@ public class BookFieldPattern extends javax.swing.JFrame {
} catch (SQLException e) {
e.getMessage();
}
} else if (this.edit) {
Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
this.search(b);
Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
this.search(b, "edit");
} else if (this.delete) {
JOptionPane.showMessageDialog(null, "USUŃ");
Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
this.search(b, "delete");
} else if (this.search) {
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.update) {
Book b = new Book(Integer.parseInt(idValue.getText()), bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
try {
d.updateQ(b);
} catch (SQLException e) {
e.printStackTrace();
}
}
dispose();
@ -327,16 +369,24 @@ public class BookFieldPattern extends javax.swing.JFrame {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(BookFieldPattern.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(BookFieldPattern.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(BookFieldPattern.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(BookFieldPattern.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(BookFieldPattern.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(BookFieldPattern.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(BookFieldPattern.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(BookFieldPattern.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
@ -360,6 +410,7 @@ public class BookFieldPattern extends javax.swing.JFrame {
private javax.swing.JLabel authorname;
private javax.swing.JLabel authorsurname;
javax.swing.JTextField bookTitle;
private javax.swing.JLabel idValue;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel lISBN;
private javax.swing.JLabel lcategory;

View File

@ -126,7 +126,7 @@ public class Database {
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
e.printStackTrace();
throw new SQLException("Error dodawania albumu");
throw new SQLException("Error dodawania filmu");
}
}
@ -308,7 +308,7 @@ public class Database {
public List<Movie> selectMovies(Movie searchData) {
List<Movie> movies = new ArrayList<>();
String query = "";
String query = new String();
try {
List<String> wheres = new ArrayList<>();
if (searchData.getName().length() > 0) {
@ -324,6 +324,7 @@ public class Database {
wheres.add("category LIKE '" + searchData.getCategory() + "'");
}
if (!wheres.isEmpty()) {
System.out.println(wheres.size());
if (wheres.size() == 1) {
query = "SELECT * FROM movies WHERE " + wheres.get(0) + ";";
} else if (wheres.size() > 1) {
@ -336,18 +337,18 @@ public class Database {
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));
}
}
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));
}
}
@ -375,24 +376,84 @@ public class Database {
return 0;
}
public <T> void updateQ(T obj) throws SQLException {
if (obj instanceof Book) {
try {
Book b = (Book) obj;
PreparedStatement prepStmt = conn.prepareStatement(
"UPDATE books SET name = ?, author_name = ?, author_surname = ?, publishing = ?, year = ?, isbn = ?, category = ? WHERE id = ?;");
prepStmt.setString(1, b.getName());
prepStmt.setString(2, b.getAuthorName());
prepStmt.setString(3, b.getAuthorSurname());
prepStmt.setString(4, b.getPublishing());
prepStmt.setInt(5, b.getYear());
prepStmt.setString(6, b.getISBN());
prepStmt.setString(7, b.getCategory());
prepStmt.setInt(8, b.getId());
System.out.println(prepStmt.toString());
prepStmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Zaktualizowano książkę poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Błąd przy aktualiacji bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
e.printStackTrace();
throw new SQLException("Error aktualizacji ksiazki");
}
} else if (obj instanceof Album) {
try {
Album a = (Album) obj;
PreparedStatement prepStmt = conn.prepareStatement(
"UPDATE albums SET name = ?, musican = ?, year = ?, category = ? WHERE id = ?;");
prepStmt.setString(1, a.getName());
prepStmt.setString(2, a.getMusican());
prepStmt.setInt(3, a.getYear());
prepStmt.setString(4, a.getCategory());
prepStmt.setInt(5, a.getId());
System.out.println(prepStmt.toString());
prepStmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Zaktualizowano album poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Błąd przy aktualiacji bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
e.printStackTrace();
throw new SQLException("Error aktualizacji albumu");
}
} else if (obj instanceof Movie) {
try {
Movie m = (Movie) obj;
PreparedStatement prepStmt = conn.prepareStatement(
"UPDATE movies SET name = ?, director = ?, year = ?, category = ? WHERE id = ?;");
prepStmt.setString(1, m.getName());
prepStmt.setString(2, m.getDirector());
prepStmt.setInt(3, m.getYear());
prepStmt.setString(4, m.getCategory());
prepStmt.setInt(5, m.getId());
System.out.println(prepStmt.toString());
prepStmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Zaktualizowano film poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Błąd przy aktualiacji bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
e.printStackTrace();
throw new SQLException("Error aktualizacji filmu");
}
}
}
public Object[][] convertToTable(List<?> l) {
try {
Object first = l.get(0);
String type = first.getClass().getName();
int i = l.size();
if (type.equals("library.Book")) {
if (first instanceof Book) {
Object tab[][] = new Object[i][8];
for (int y = 0; y < i; y++) { //kolejne wiersze danych
tab = Book.insertRowToTable(tab, y, (Book) l.get(y));
}
return tab;
} else if (type.equals("library.Album")) {
} else if (first instanceof Album) {
Object tab[][] = new Object[i][5];
for (int y = 0; y < i; y++) { //kolejne wiersze danych
tab = Album.insertRowToTable(tab, y, (Album) l.get(y));
}
return tab;
} else if (type.equals("library.Movie")) {
} else if (first instanceof Movie) {
Object tab[][] = new Object[i][5];
for (int y = 0; y < i; y++) { //kolejne wiersze danych
tab = Movie.insertRowToTable(tab, y, (Movie) l.get(y));
@ -401,7 +462,7 @@ public class Database {
}
} catch (IndexOutOfBoundsException e) {
JOptionPane.showMessageDialog(null, "Brak danych.", "Error:", JOptionPane.INFORMATION_MESSAGE);
throw new IndexOutOfBoundsException("Poza zakresem");
throw new IndexOutOfBoundsException("dł.tablicy = 0");
}
return null;

View File

@ -33,13 +33,16 @@
<EmptySpace min="-2" pref="23" max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="1180" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="496" max="-2" attributes="0"/>
<Component id="OK" min="-2" pref="215" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="26" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="editButton" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="deleteButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="548" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@ -49,9 +52,12 @@
<Component id="mainlabel" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="13" max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="473" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="32" max="-2" attributes="0"/>
<Component id="OK" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="33" max="32767" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="editButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="deleteButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="47" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -75,12 +81,10 @@
<SubComponents>
<Component class="javax.swing.JTable" name="table">
<Properties>
<Property name="autoCreateColumnsFromModel" type="boolean" editor="org.netbeans.modules.form.RADConnectionPropertyEditor" postCode="table.setModel(new javax.swing.table.DefaultTableModel(&#xa; rows,&#xa; columnsNames&#xa;));">
<Property name="autoCreateColumnsFromModel" type="boolean" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="false" type="code"/>
</Property>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor" postCode="table.setRowSelectionInterval(0, 0);">
<Connection code="new javax.swing.table.DefaultTableModel(&#xa; rows,&#xa; columnsNames&#xa;)" type="code"/>
</Property>
<Property name="model" postCode="table.setRowSelectionInterval(0, 0);"/>
<Property name="rowHeight" type="int" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="25" type="code"/>
</Property>
@ -89,21 +93,29 @@
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_AddingCodePost" type="java.lang.String" value="DefaultTableModel tableModel = new DefaultTableModel(rows, columnsNames) {&#xa;&#xa; @Override&#xa; public boolean isCellEditable(int row, int column) {&#xa; //all cells false&#xa; return false;&#xa; }&#xa;};&#xa;table.setModel(tableModel);"/>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new javax.swing.JTable(rows, columnsNames)"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="OK">
<Component class="javax.swing.JButton" name="editButton">
<Properties>
<Property name="text" type="java.lang.String" value="Wybierz pozycj&#x119;..."/>
<Property name="text" type="java.lang.String" value="Edytuj"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="OKActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="editButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="deleteButton">
<Properties>
<Property name="text" type="java.lang.String" value="Usu&#x144;"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="deleteButtonActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_ListenersCodePost" type="java.lang.String" value="int row = table.getSelectedRow();&#xa;&#xa;if(row == -1)&#xa;{&#xa;OK.setVisible(false);&#xa;}&#xa;else&#xa;{&#xa; &#xa; // do whatever you need to do with the data from the row&#xa;}"/>
</AuxValues>
</Component>
</SubComponents>
</Form>

View File

@ -10,6 +10,7 @@ import java.util.List;
import javax.swing.JFrame;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.table.DefaultTableModel;
/**
*
@ -20,15 +21,16 @@ public class ListResult extends javax.swing.JFrame {
/**
* Creates new form NewJFrame
*/
private Object[][] rows;
private Object[] columnsNames;
public String dataType;
private final Object[][] rows;
private final Object[] columnsNames;
public ListResult(Object[][] rowData, Object[] colNam) {
public ListResult(Object[][] rowData, Object[] colNam, String dataT) {
rows = rowData;
columnsNames = colNam;
dataType = dataT;
initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
/**
@ -43,7 +45,8 @@ 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();
editButton = new javax.swing.JButton();
deleteButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
@ -52,36 +55,35 @@ public class ListResult extends javax.swing.JFrame {
mainlabel.setText("Tabela danych");
table.setAutoCreateColumnsFromModel(false);
table.setModel(new javax.swing.table.DefaultTableModel(
rows,
columnsNames
));
table.setModel(new javax.swing.table.DefaultTableModel(
rows,
columnsNames
));
table.setRowSelectionInterval(0, 0);
table.setRowHeight(25);
table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jScrollPane1.setViewportView(table);
DefaultTableModel tableModel = new DefaultTableModel(rows, columnsNames) {
OK.setText("Wybierz pozycję...");
OK.addActionListener(new java.awt.event.ActionListener() {
@Override
public boolean isCellEditable(int row, int column) {
//all cells false
return false;
}
};
table.setModel(tableModel);
editButton.setText("Edytuj");
editButton.setEnabled(false);
editButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
OKActionPerformed(evt);
editButtonActionPerformed(evt);
}
});
int row = table.getSelectedRow();
if(row == -1)
{
OK.setVisible(false);
}
else
{
// do whatever you need to do with the data from the row
}
deleteButton.setText("Usuń");
deleteButton.setEnabled(false);
deleteButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
@ -94,11 +96,14 @@ 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))
.addGroup(layout.createSequentialGroup()
.addGap(496, 496, 496)
.addComponent(OK, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1180, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(26, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(editButton)
.addGap(18, 18, 18)
.addComponent(deleteButton)
.addGap(548, 548, 548))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -107,17 +112,70 @@ public class ListResult extends javax.swing.JFrame {
.addComponent(mainlabel)
.addGap(13, 13, 13)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 473, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32)
.addComponent(OK)
.addContainerGap(33, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(editButton)
.addComponent(deleteButton))
.addContainerGap(47, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//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
public boolean isCellEditable(int row, int col) {
return false;
}
private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
int selectedRowIndex = table.getSelectedRow();
System.out.println(selectedRowIndex);
if (dataType.equals("book")) {
Book b = new Book(
(Integer) table.getValueAt(selectedRowIndex, 0),
(String) table.getValueAt(selectedRowIndex, 1),
(String) table.getValueAt(selectedRowIndex, 2),
(String) table.getValueAt(selectedRowIndex, 3),
Integer.toString((Integer) table.getValueAt(selectedRowIndex, 4)),
(String) table.getValueAt(selectedRowIndex, 5),
(String) table.getValueAt(selectedRowIndex, 6),
(String) table.getValueAt(selectedRowIndex, 7));
BookFieldPattern bookPattern = new BookFieldPattern(true, b);
bookPattern.setVisible(true);
} else if (dataType.equals("movie")) {
Movie m = new Movie(
(Integer) table.getValueAt(selectedRowIndex, 0),
(String) table.getValueAt(selectedRowIndex, 1),
(String) table.getValueAt(selectedRowIndex, 2),
Integer.toString((Integer) table.getValueAt(selectedRowIndex, 3)),
(String) table.getValueAt(selectedRowIndex, 4));
MovieFieldPattern moviePattern = new MovieFieldPattern(true, m);
moviePattern.setVisible(true);
} else if (dataType.equals("album")) {
Album a = new Album(
(Integer) table.getValueAt(selectedRowIndex, 0),
(String) table.getValueAt(selectedRowIndex, 1),
(String) table.getValueAt(selectedRowIndex, 2),
Integer.toString((Integer) table.getValueAt(selectedRowIndex, 3)),
(String) table.getValueAt(selectedRowIndex, 4));
AlbumFieldPattern albumPattern = new AlbumFieldPattern(true, a);
albumPattern.setVisible(true);
}
dispose();
}//GEN-LAST:event_editButtonActionPerformed
private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
int selectedRowIndex = table.getSelectedRow();
System.out.println(selectedRowIndex);
}//GEN-LAST:event_deleteButtonActionPerformed
public void setEnabledButton(String which) {
if (which.equals("edit")) {
editButton.setEnabled(true);
} else if (which.equals("delete")) {
deleteButton.setEnabled(true);
}
}
/**
* @param args the command line arguments
@ -165,7 +223,8 @@ public class ListResult extends javax.swing.JFrame {
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton OK;
private javax.swing.JButton deleteButton;
private javax.swing.JButton editButton;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel mainlabel;
private javax.swing.JTable table;

View File

@ -31,32 +31,31 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="programTitle" max="32767" attributes="0"/>
<Component id="programTitle" pref="817" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="359" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="359" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jToggleButton1" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
<Component id="searchButtonsPanel" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel2" min="-2" max="-2" attributes="0"/>
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<Component id="jToggleButton1" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jPanel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="searchButtonsPanel" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="141" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@ -64,17 +63,18 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="24" max="-2" attributes="0"/>
<Component id="programTitle" min="-2" pref="38" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="13" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="searchButtonsPanel" min="-2" pref="87" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel2" min="-2" max="-2" attributes="0"/>
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="jToggleButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="43" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -116,12 +116,12 @@
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="radioBSearch" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="61" max="32767" attributes="0"/>
<EmptySpace pref="133" max="32767" attributes="0"/>
<Component id="radioBAdd" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="radioBEdit" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="radioBDelete1" min="-2" max="-2" attributes="0"/>
<Component id="radioBDelete" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="78" max="-2" attributes="0"/>
</Group>
</Group>
@ -135,7 +135,7 @@
<Group type="103" groupAlignment="3" attributes="0">
<Component id="radioBAdd" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="radioBEdit" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="radioBDelete1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="radioBDelete" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="radioBSearch" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
@ -196,7 +196,7 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="radioBEditActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JRadioButton" name="radioBDelete1">
<Component class="javax.swing.JRadioButton" name="radioBDelete">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="mode"/>
@ -204,7 +204,7 @@
<Property name="text" type="java.lang.String" value="Usuwanie"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="radioBDelete1ActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="radioBDeleteActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JRadioButton" name="radioBSearch">

View File

@ -41,7 +41,7 @@ public class MainMenu extends javax.swing.JFrame {
bBook = new javax.swing.JButton();
radioBAdd = new javax.swing.JRadioButton();
radioBEdit = new javax.swing.JRadioButton();
radioBDelete1 = new javax.swing.JRadioButton();
radioBDelete = new javax.swing.JRadioButton();
radioBSearch = new javax.swing.JRadioButton();
jPanel1 = new javax.swing.JPanel();
allMovieShow = new javax.swing.JButton();
@ -108,11 +108,11 @@ public class MainMenu extends javax.swing.JFrame {
}
});
mode.add(radioBDelete1);
radioBDelete1.setText("Usuwanie");
radioBDelete1.addActionListener(new java.awt.event.ActionListener() {
mode.add(radioBDelete);
radioBDelete.setText("Usuwanie");
radioBDelete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
radioBDelete1ActionPerformed(evt);
radioBDeleteActionPerformed(evt);
}
});
@ -141,12 +141,12 @@ public class MainMenu extends javax.swing.JFrame {
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(searchButtonsPanelLayout.createSequentialGroup()
.addComponent(radioBSearch)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 61, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 133, Short.MAX_VALUE)
.addComponent(radioBAdd)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(radioBEdit)
.addGap(18, 18, 18)
.addComponent(radioBDelete1)
.addComponent(radioBDelete)
.addGap(78, 78, 78))))
);
searchButtonsPanelLayout.setVerticalGroup(
@ -156,7 +156,7 @@ public class MainMenu extends javax.swing.JFrame {
.addGroup(searchButtonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(radioBAdd)
.addComponent(radioBEdit)
.addComponent(radioBDelete1)
.addComponent(radioBDelete)
.addComponent(radioBSearch))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(searchButtonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
@ -327,40 +327,40 @@ public class MainMenu extends javax.swing.JFrame {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(programTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(programTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 817, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(359, 359, 359)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToggleButton1)
.addGroup(layout.createSequentialGroup()
.addGap(359, 359, 359)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addComponent(searchButtonsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jToggleButton1))))
.addGap(0, 0, Short.MAX_VALUE)))
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(searchButtonsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(141, 141, 141))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(programTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(13, 13, 13)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(searchButtonsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jToggleButton1)
.addContainerGap(43, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
@ -382,6 +382,11 @@ public class MainMenu extends javax.swing.JFrame {
b.setVisible(true);
b.delete = true;
}
if (radioBDelete.getModel().isSelected()) {
MovieFieldPattern b = new MovieFieldPattern();
b.setVisible(true);
b.delete = true;
}
}//GEN-LAST:event_bMovieActionPerformed
private void bAlbumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAlbumActionPerformed
@ -431,12 +436,17 @@ public class MainMenu extends javax.swing.JFrame {
b.setVisible(true);
b.search = true;
}
if (radioBDelete.getModel().isSelected()) {
BookFieldPattern b = new BookFieldPattern();
b.setVisible(true);
b.delete = true;
}
}//GEN-LAST:event_bBookActionPerformed
private void radioBDelete1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioBDelete1ActionPerformed
private void radioBDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioBDeleteActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_radioBDelete1ActionPerformed
}//GEN-LAST:event_radioBDeleteActionPerformed
private void allBooksShowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allBooksShowActionPerformed
try {
@ -451,7 +461,7 @@ public class MainMenu extends javax.swing.JFrame {
"ISBN",
"Wydawnictwo",
"Kategoria"};
ListResult table = new ListResult(data, columnNames);
ListResult table = new ListResult(data, columnNames, "book");
table.setVisible(true);
} catch (IndexOutOfBoundsException e) {
//nothing to do here
@ -469,7 +479,7 @@ public class MainMenu extends javax.swing.JFrame {
"Reżyser",
"Rok",
"Kategoria"};
ListResult table = new ListResult(data, columnNames);
ListResult table = new ListResult(data, columnNames, "movie");
table.setVisible(true);
} catch (IndexOutOfBoundsException e) {
//nothing to do here
@ -488,7 +498,7 @@ public class MainMenu extends javax.swing.JFrame {
"Muzyk/Zespół",
"Rok",
"Kategoria"};
ListResult table = new ListResult(data, columnNames);
ListResult table = new ListResult(data, columnNames, "album");
table.setVisible(true);
} catch (IndexOutOfBoundsException e) {
@ -568,7 +578,7 @@ public class MainMenu extends javax.swing.JFrame {
private javax.swing.JLabel numberOfMovies;
private javax.swing.JLabel programTitle;
private javax.swing.JRadioButton radioBAdd;
private javax.swing.JRadioButton radioBDelete1;
private javax.swing.JRadioButton radioBDelete;
private javax.swing.JRadioButton radioBEdit;
private javax.swing.JRadioButton radioBSearch;
private javax.swing.JButton refreshNumbersOfItems;

View File

@ -30,8 +30,9 @@
<Group type="103" groupAlignment="0" attributes="0">
<Component id="Title" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="directorrname" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="idValue" alignment="0" min="-2" pref="57" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="56" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="52" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="director" min="-2" pref="219" max="-2" attributes="0"/>
<Component id="movieTitle" min="-2" pref="362" max="-2" attributes="0"/>
@ -47,11 +48,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Component id="year" alignment="0" min="-2" pref="76" max="-2" attributes="0"/>
<Component id="Category" min="-2" pref="220" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="SaveChanges" min="-2" pref="220" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="cancel" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="SaveChanges" alignment="0" min="-2" pref="220" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
@ -63,7 +60,10 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="mainlabel" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="mainlabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="idValue" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="Title" alignment="3" min="-2" max="-2" attributes="0"/>
@ -85,11 +85,8 @@
<Component id="Category" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="33" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="SaveChanges" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cancel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="25" max="32767" attributes="0"/>
<Component id="SaveChanges" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="26" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -139,9 +136,6 @@
<Font name="Tahoma" size="14" style="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="yearActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lcategory">
<Properties>
@ -154,22 +148,55 @@
<Component class="javax.swing.JComboBox" name="Category">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="9">
<StringArray count="45">
<StringItem index="0" value=" "/>
<StringItem index="1" value="Krymina&#x142;"/>
<StringItem index="2" value="Thriller"/>
<StringItem index="3" value="Przygodowy"/>
<StringItem index="4" value="Animowany"/>
<StringItem index="5" value="Akcji"/>
<StringItem index="1" value="Akcji"/>
<StringItem index="2" value="Anime"/>
<StringItem index="3" value="Animowany"/>
<StringItem index="4" value="Ba&#x15b;&#x144;"/>
<StringItem index="5" value="Biograficzny"/>
<StringItem index="6" value="Dla dzieci"/>
<StringItem index="7" value="Komedia"/>
<StringItem index="8" value="Horror"/>
<StringItem index="7" value="Dla m&#x142;odzie&#x17c;y"/>
<StringItem index="8" value="Dokument"/>
<StringItem index="9" value="Dokumentalizowany"/>
<StringItem index="10" value="Dramat"/>
<StringItem index="11" value="Edukacyjny"/>
<StringItem index="12" value="Etiuda"/>
<StringItem index="13" value="Fabularyzowany dokument"/>
<StringItem index="14" value="Familijny"/>
<StringItem index="15" value="Fantastyka"/>
<StringItem index="16" value="Fantasy"/>
<StringItem index="17" value="Historyczny"/>
<StringItem index="18" value="Horror"/>
<StringItem index="19" value="Karate"/>
<StringItem index="20" value="Katastroficzny"/>
<StringItem index="21" value="Komedia"/>
<StringItem index="22" value="Komedia romantyczna"/>
<StringItem index="23" value="Komediodramat"/>
<StringItem index="24" value="Kostiumowy"/>
<StringItem index="25" value="Krymina&#x142;"/>
<StringItem index="26" value="Kung-fu"/>
<StringItem index="27" value="Melodramat"/>
<StringItem index="28" value="Musical"/>
<StringItem index="29" value="Obyczajowy"/>
<StringItem index="30" value="Parodia"/>
<StringItem index="31" value="Przygodowy"/>
<StringItem index="32" value="Przyrodniczy"/>
<StringItem index="33" value="Psychologiczny"/>
<StringItem index="34" value="Religijny"/>
<StringItem index="35" value="Romans"/>
<StringItem index="36" value="Satyra"/>
<StringItem index="37" value="Science fiction"/>
<StringItem index="38" value="Sensacja"/>
<StringItem index="39" value="Sportowy"/>
<StringItem index="40" value="Surrealistyczny"/>
<StringItem index="41" value="Sztuki walki"/>
<StringItem index="42" value="Thriller"/>
<StringItem index="43" value="Western"/>
<StringItem index="44" value="Wojenny"/>
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="CategoryActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
@ -194,13 +221,10 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="SaveChangesActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="cancel">
<Component class="javax.swing.JLabel" name="idValue">
<Properties>
<Property name="text" type="java.lang.String" value="Anuluj"/>
<Property name="text" type="java.lang.String" value="."/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@ -17,7 +17,7 @@ import javax.swing.JOptionPane;
*/
public class MovieFieldPattern extends javax.swing.JFrame {
public boolean add = false, delete = false, edit = false, search = false;
public boolean add = false, delete = false, edit = false, search = false, update = false;
private Database d = new Database();
/**
@ -28,7 +28,7 @@ public class MovieFieldPattern extends javax.swing.JFrame {
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public MovieFieldPattern(boolean required) {
public MovieFieldPattern(boolean required, Movie... m) {
initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Validation verify;
@ -40,6 +40,47 @@ public class MovieFieldPattern extends javax.swing.JFrame {
movieTitle.setInputVerifier(verify);
director.setInputVerifier(verify);
year.setInputVerifier(verify);
try {
if (m[0].getId() >= 0) {
fillField(m[0]);
update = true;
}
} catch (ArrayIndexOutOfBoundsException e) {
//when only one parameter is defined
}
}
public void fillField(Movie m) {
idValue.setText(Integer.toString(m.getId()));
movieTitle.setText(m.getName());
director.setText(m.getDirector());
year.setText(Integer.toString(m.getYear()));
Category.setSelectedItem(m.getCategory());
}
public void search(Movie m, String... mode) {
try {
List<Movie> movies = new LinkedList<>();
movies = d.selectMovies(m);
Object[][] data = d.convertToTable(movies);
String[] columnNames = {
"ID",
"Tytuł",
"Reżyser",
"Rok",
"Kategoria"};
ListResult table = new ListResult(data, columnNames, "movie");
table.setVisible(true);
if (mode[0].equals("edit")) {
table.setEnabledButton("edit");
}
if (mode[0].equals("delete")) {
table.setEnabledButton("delete");
}
} catch (IndexOutOfBoundsException e) {
//nothing to do here
}
}
/**
@ -61,7 +102,7 @@ public class MovieFieldPattern extends javax.swing.JFrame {
Category = new javax.swing.JComboBox<>();
mainlabel = new javax.swing.JLabel();
SaveChanges = new javax.swing.JButton();
cancel = new javax.swing.JButton();
idValue = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
@ -79,21 +120,11 @@ public class MovieFieldPattern 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);
}
});
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.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CategoryActionPerformed(evt);
}
});
Category.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { " ", "Akcji", "Anime", "Animowany", "Baśń", "Biograficzny", "Dla dzieci", "Dla młodzieży", "Dokument", "Dokumentalizowany", "Dramat", "Edukacyjny", "Etiuda", "Fabularyzowany dokument", "Familijny", "Fantastyka", "Fantasy", "Historyczny", "Horror", "Karate", "Katastroficzny", "Komedia", "Komedia romantyczna", "Komediodramat", "Kostiumowy", "Kryminał", "Kung-fu", "Melodramat", "Musical", "Obyczajowy", "Parodia", "Przygodowy", "Przyrodniczy", "Psychologiczny", "Religijny", "Romans", "Satyra", "Science fiction", "Sensacja", "Sportowy", "Surrealistyczny", "Sztuki walki", "Thriller", "Western", "Wojenny" }));
mainlabel.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
mainlabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
@ -107,12 +138,7 @@ public class MovieFieldPattern extends javax.swing.JFrame {
}
});
cancel.setText("Anuluj");
cancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelActionPerformed(evt);
}
});
idValue.setText(".");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
@ -124,8 +150,9 @@ public class MovieFieldPattern extends javax.swing.JFrame {
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Title)
.addComponent(directorrname))
.addGap(56, 56, 56)
.addComponent(directorrname)
.addComponent(idValue, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(52, 52, 52)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(director, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(movieTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 362, javax.swing.GroupLayout.PREFERRED_SIZE)
@ -138,17 +165,16 @@ public class MovieFieldPattern extends javax.swing.JFrame {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Category, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(SaveChanges, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(cancel)))))
.addComponent(SaveChanges, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(21, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(mainlabel)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(mainlabel)
.addComponent(idValue))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Title)
@ -166,10 +192,8 @@ public class MovieFieldPattern extends javax.swing.JFrame {
.addComponent(lcategory)
.addComponent(Category, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(33, 33, 33)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(SaveChanges)
.addComponent(cancel))
.addContainerGap(25, Short.MAX_VALUE))
.addComponent(SaveChanges)
.addContainerGap(26, Short.MAX_VALUE))
);
pack();
@ -179,10 +203,6 @@ public class MovieFieldPattern 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 {
@ -193,36 +213,25 @@ public class MovieFieldPattern extends javax.swing.JFrame {
e.getMessage();
}
} else if (this.edit) {
try {
List<Movie> 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
}
Movie m = new Movie(0, movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString());
this.search(m, "edit");
} else if (this.delete) {
JOptionPane.showMessageDialog(null, "USUŃ");
Movie m = new Movie(0, movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString());
this.search(m, "delete");
} else if (this.search) {
Movie m = new Movie(0, movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString());
this.search(m);
} else if (this.update) {
Movie m = new Movie(Integer.parseInt(idValue.getText()), movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString());
try {
d.updateQ(m);
} catch (SQLException e) {
e.printStackTrace();
}
}
dispose();
}//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
private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
this.dispose();
}//GEN-LAST:event_cancelActionPerformed
/**
* @param args the command line arguments
*/
@ -264,9 +273,9 @@ public class MovieFieldPattern extends javax.swing.JFrame {
private javax.swing.JComboBox<String> Category;
private javax.swing.JButton SaveChanges;
private javax.swing.JLabel Title;
private javax.swing.JButton cancel;
private javax.swing.JTextField director;
private javax.swing.JLabel directorrname;
private javax.swing.JLabel idValue;
private javax.swing.JLabel lcategory;
private javax.swing.JLabel lyear;
private javax.swing.JLabel mainlabel;