Wyszukiwarka WELL DONE
This commit is contained in:
parent
fa5c2eec24
commit
a7d40927a3
BIN
biblioteka.db
BIN
biblioteka.db
Binary file not shown.
@ -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);
|
||||
}
|
||||
|
@ -132,10 +132,8 @@
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="year" noResource="true"/>
|
||||
</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>
|
||||
@ -148,20 +146,18 @@
|
||||
<Component class="javax.swing.JComboBox" name="Category">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="7">
|
||||
<StringItem index="0" value="Jazz"/>
|
||||
<StringItem index="1" value="Rap"/>
|
||||
<StringItem index="2" value="Rock"/>
|
||||
<StringItem index="3" value="Muzyka Klasyczna"/>
|
||||
<StringItem index="4" value="Reggae"/>
|
||||
<StringItem index="5" value="Pop"/>
|
||||
<StringItem index="6" value="Elektroniczna"/>
|
||||
<StringArray count="8">
|
||||
<StringItem index="0" value=" "/>
|
||||
<StringItem index="1" value="Jazz"/>
|
||||
<StringItem index="2" value="Rap"/>
|
||||
<StringItem index="3" value="Rock"/>
|
||||
<StringItem index="4" value="Muzyka Klasyczna"/>
|
||||
<StringItem index="5" value="Reggae"/>
|
||||
<StringItem index="6" value="Pop"/>
|
||||
<StringItem index="7" value="Elektroniczna"/>
|
||||
</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="<String>"/>
|
||||
</AuxValues>
|
||||
|
@ -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<Album> 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
|
||||
*/
|
||||
|
@ -49,6 +49,25 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
||||
publishing.setInputVerifier(verify);
|
||||
}
|
||||
|
||||
public void search(Book b) {
|
||||
try {
|
||||
List<Book> 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<Book> 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) {
|
||||
|
@ -154,83 +154,80 @@ public class Database {
|
||||
return books;
|
||||
}
|
||||
|
||||
//public List<Book> selectBooks(Book searchData) {
|
||||
public void selectBooks(Book searchData) {
|
||||
public List<Book> selectBooks(Book searchData) {
|
||||
List<Book> books = new ArrayList<>();
|
||||
boolean EmptyAll = true;
|
||||
//try {
|
||||
List<String> 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<String> 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<Album> selectAlbums() {
|
||||
List<Album> albums = new ArrayList<Album>();
|
||||
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<Album> selectAlbums(Album searchData) {
|
||||
List<Album> albums = new ArrayList<>();
|
||||
String query = "";
|
||||
try {
|
||||
List<String> 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<Movie> selectMovies() {
|
||||
List<Movie> movies = new ArrayList<Movie>();
|
||||
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<Movie> selectMovies(Movie searchData) {
|
||||
List<Movie> movies = new ArrayList<>();
|
||||
String query = "";
|
||||
try {
|
||||
List<String> 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");
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,10 @@
|
||||
<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>
|
||||
@ -44,8 +48,10 @@
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="mainlabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="13" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" min="-2" pref="533" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="30" max="32767" 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"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
@ -88,5 +94,16 @@
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JButton" name="OK">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Wybierz pozycję..."/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="OKActionPerformed"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_ListenersCodePost" type="java.lang.String" value="int row = table.getSelectedRow();

if(row == -1)
{
OK.setVisible(false);
}
else
{
 
 // do whatever you need to do with the data from the row
}"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -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();
|
||||
}// </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
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
//</editor-fold>
|
||||
//</editor-fold>
|
||||
|
||||
|
||||
/* 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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -154,15 +154,16 @@
|
||||
<Component class="javax.swing.JComboBox" name="Category">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="8">
|
||||
<StringItem index="0" value="Kryminał"/>
|
||||
<StringItem index="1" value="Thriller"/>
|
||||
<StringItem index="2" value="Przygodowy"/>
|
||||
<StringItem index="3" value="Animowany"/>
|
||||
<StringItem index="4" value="Akcji"/>
|
||||
<StringItem index="5" value="Dla dzieci"/>
|
||||
<StringItem index="6" value="Komedia"/>
|
||||
<StringItem index="7" value="Horror"/>
|
||||
<StringArray count="9">
|
||||
<StringItem index="0" value=" "/>
|
||||
<StringItem index="1" value="Kryminał"/>
|
||||
<StringItem index="2" value="Thriller"/>
|
||||
<StringItem index="3" value="Przygodowy"/>
|
||||
<StringItem index="4" value="Animowany"/>
|
||||
<StringItem index="5" value="Akcji"/>
|
||||
<StringItem index="6" value="Dla dzieci"/>
|
||||
<StringItem index="7" value="Komedia"/>
|
||||
<StringItem index="8" value="Horror"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
@ -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<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
|
||||
}
|
||||
} else if (this.delete) {
|
||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user