Działa dodawanie książek, praca nad dodawaniem reszty
This commit is contained in:
parent
ab0325b065
commit
f7ae927511
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -127,9 +127,6 @@
|
|||||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||||
<Font name="Tahoma" size="14" style="0"/>
|
<Font name="Tahoma" size="14" style="0"/>
|
||||||
</Property>
|
</Property>
|
||||||
<Property name="inputVerifier" type="javax.swing.InputVerifier" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
|
||||||
<Connection code="new library.Validation("[a-zA-z0-9]+", this.add)" type="code"/>
|
|
||||||
</Property>
|
|
||||||
</Properties>
|
</Properties>
|
||||||
<Events>
|
<Events>
|
||||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bookTitleActionPerformed"/>
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bookTitleActionPerformed"/>
|
||||||
@ -215,6 +212,9 @@
|
|||||||
<Font name="Tahoma" size="14" style="0"/>
|
<Font name="Tahoma" size="14" style="0"/>
|
||||||
</Property>
|
</Property>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ISBNActionPerformed"/>
|
||||||
|
</Events>
|
||||||
</Component>
|
</Component>
|
||||||
<Component class="javax.swing.JLabel" name="lcategory">
|
<Component class="javax.swing.JLabel" name="lcategory">
|
||||||
<Properties>
|
<Properties>
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -21,7 +21,7 @@ public class Album extends Item {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void insertToDB(){
|
public void insertToDB(){
|
||||||
String query = "INSERT INTO albums VALUES(NULL, '" +this.getName() + "', '" + this.getMusican() + "', '" + this.getYear() + "', '"+ this.getCategory() + "');";
|
// String query = "INSERT INTO albums VALUES(NULL, '" +this.getName() + "', '" + this.getMusican() + "', '" + this.getYear() + "', '"+ this.getCategory() + "');";
|
||||||
};
|
};
|
||||||
@Override
|
@Override
|
||||||
public void delFromDB(){
|
public void delFromDB(){
|
||||||
|
@ -21,12 +21,14 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
|||||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
initComponents();
|
initComponents();
|
||||||
}
|
}
|
||||||
public AlbumFieldPattern(boolean required) {
|
|
||||||
|
public AlbumFieldPattern(boolean required) {
|
||||||
initComponents();
|
initComponents();
|
||||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
albumTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
albumTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
||||||
}
|
}
|
||||||
public boolean add= false, delete = false, edit = false;
|
public boolean add = false, delete = false, edit = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called from within the constructor to initialize the form.
|
* 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
|
* WARNING: Do NOT modify this code. The content of this method is always
|
||||||
@ -150,23 +152,21 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
|||||||
|
|
||||||
public void ChangeOkButtonText(String s) {
|
public void ChangeOkButtonText(String s) {
|
||||||
this.SaveChanges.setText(s);
|
this.SaveChanges.setText(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CategoryActionPerformed
|
private void CategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CategoryActionPerformed
|
||||||
// TODO add your handling code here:
|
// TODO add your handling code here:
|
||||||
}//GEN-LAST:event_CategoryActionPerformed
|
}//GEN-LAST:event_CategoryActionPerformed
|
||||||
|
|
||||||
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
||||||
if(this.add){
|
if (this.add) {
|
||||||
JOptionPane.showMessageDialog(null, "DODAJ");
|
JOptionPane.showMessageDialog(null, "DODAJ");
|
||||||
|
} else if (this.edit) {
|
||||||
|
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||||
|
} else if (this.delete) {
|
||||||
|
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||||
}
|
}
|
||||||
else if(this.edit){
|
dispose();
|
||||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
|
||||||
}
|
|
||||||
else if(this.delete){
|
|
||||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
|
||||||
}
|
|
||||||
dispose();
|
|
||||||
}//GEN-LAST:event_SaveChangesActionPerformed
|
}//GEN-LAST:event_SaveChangesActionPerformed
|
||||||
|
|
||||||
private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed
|
private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed
|
||||||
@ -209,9 +209,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
|||||||
new AlbumFieldPattern().setVisible(false);
|
new AlbumFieldPattern().setVisible(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
|
@ -9,62 +9,77 @@ package library;
|
|||||||
*
|
*
|
||||||
* @author Agnieszka
|
* @author Agnieszka
|
||||||
*/
|
*/
|
||||||
public class Book extends Item{
|
public class Book extends Item {
|
||||||
Book(){
|
|
||||||
//nothing to do
|
Book() {
|
||||||
|
//nothing to do
|
||||||
}
|
}
|
||||||
Book(int id, String n, String an, String asn, int y, String isbn, String p, String c){
|
|
||||||
this.setId(id);
|
Book(int id, String n, String an, String asn, int y, String isbn, String p, String c) {
|
||||||
this.setName(n);
|
this.setId(id);
|
||||||
this.authorName = an;
|
this.setName(n);
|
||||||
this.authorSurname = asn;
|
this.authorName = an;
|
||||||
this.setYear(y);
|
this.authorSurname = asn;
|
||||||
this.setCategory(c);
|
this.setYear(y);
|
||||||
this.ISBN = isbn;
|
this.setCategory(c);
|
||||||
this.publishing = p;
|
this.ISBN = isbn;
|
||||||
}
|
this.publishing = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertToDB() {
|
||||||
|
db.insertBookQ(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
;
|
||||||
@Override
|
@Override
|
||||||
public void insertToDB(){
|
public void delFromDB() {
|
||||||
db.insertBookQ(this);
|
|
||||||
};
|
|
||||||
@Override
|
|
||||||
public void delFromDB(){
|
|
||||||
String query = "DELETE FROM books WHERE id=" + this.getId() + ";";
|
String query = "DELETE FROM books WHERE id=" + this.getId() + ";";
|
||||||
};
|
}
|
||||||
|
|
||||||
|
;
|
||||||
@Override
|
@Override
|
||||||
public void editInDB(){
|
public void editInDB() {
|
||||||
|
|
||||||
};
|
}
|
||||||
|
|
||||||
|
;
|
||||||
/*public void insertQuery(){
|
/*public void insertQuery(){
|
||||||
System.out.println("INSERT INTO books VALUES('NULL', '" +name + "', '" + authorName + "', '" + authorSurname + "', '"+ publishing + "', '"+ year + "', '"+ ISBN + "', '"+ category + "');");
|
System.out.println("INSERT INTO books VALUES('NULL', '" +name + "', '" + authorName + "', '" + authorSurname + "', '"+ publishing + "', '"+ year + "', '"+ ISBN + "', '"+ category + "');");
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public void setPublishing(String s){
|
public void setPublishing(String s) {
|
||||||
this.publishing = s;
|
this.publishing = s;
|
||||||
}
|
}
|
||||||
public void setAuthorName(String s){
|
|
||||||
this.authorName = s;
|
public void setAuthorName(String s) {
|
||||||
}
|
this.authorName = s;
|
||||||
public void setAuthorSurname(String s){
|
}
|
||||||
this.authorSurname = s;
|
|
||||||
}
|
public void setAuthorSurname(String s) {
|
||||||
public void setISBN(String s){
|
this.authorSurname = s;
|
||||||
this.ISBN = s;
|
}
|
||||||
}
|
|
||||||
public String getAuthorName(){
|
public void setISBN(String s) {
|
||||||
return this.authorName;
|
this.ISBN = s;
|
||||||
}
|
}
|
||||||
public String getAuthorSurname(){
|
|
||||||
return this.authorSurname;
|
public String getAuthorName() {
|
||||||
}
|
return this.authorName;
|
||||||
public String getPublishing(){
|
}
|
||||||
return this.publishing;
|
|
||||||
}
|
public String getAuthorSurname() {
|
||||||
public String getISBN(){
|
return this.authorSurname;
|
||||||
return this.publishing;
|
}
|
||||||
}
|
|
||||||
private String authorName, authorSurname, publishing, ISBN;
|
public String getPublishing() {
|
||||||
private Database db = new Database();
|
return this.publishing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getISBN() {
|
||||||
|
return this.ISBN;
|
||||||
|
}
|
||||||
|
private String authorName, authorSurname, publishing, ISBN;
|
||||||
|
private Database db = new Database();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -127,9 +127,6 @@
|
|||||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||||
<Font name="Tahoma" size="14" style="0"/>
|
<Font name="Tahoma" size="14" style="0"/>
|
||||||
</Property>
|
</Property>
|
||||||
<Property name="inputVerifier" type="javax.swing.InputVerifier" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
|
||||||
<Connection code="new library.Validation("[a-zA-z0-9]+", this.add)" type="code"/>
|
|
||||||
</Property>
|
|
||||||
</Properties>
|
</Properties>
|
||||||
<Events>
|
<Events>
|
||||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bookTitleActionPerformed"/>
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bookTitleActionPerformed"/>
|
||||||
@ -215,6 +212,9 @@
|
|||||||
<Font name="Tahoma" size="14" style="0"/>
|
<Font name="Tahoma" size="14" style="0"/>
|
||||||
</Property>
|
</Property>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ISBNActionPerformed"/>
|
||||||
|
</Events>
|
||||||
</Component>
|
</Component>
|
||||||
<Component class="javax.swing.JLabel" name="lcategory">
|
<Component class="javax.swing.JLabel" name="lcategory">
|
||||||
<Properties>
|
<Properties>
|
||||||
|
@ -5,7 +5,10 @@
|
|||||||
*/
|
*/
|
||||||
package library;
|
package library;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
@ -22,14 +25,15 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
|||||||
initComponents();
|
initComponents();
|
||||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
}
|
}
|
||||||
public BookFieldPattern(boolean required) {
|
|
||||||
|
public BookFieldPattern(boolean required) {
|
||||||
initComponents();
|
initComponents();
|
||||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
bookTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
//bookTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean add = false, delete = false, edit = false;
|
||||||
public boolean add= false, delete = false, edit = false;
|
|
||||||
/**
|
/**
|
||||||
* This method is called from within the constructor to initialize the form.
|
* 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
|
* WARNING: Do NOT modify this code. The content of this method is always
|
||||||
@ -62,7 +66,6 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
|||||||
Title.setText("Tytuł:");
|
Title.setText("Tytuł:");
|
||||||
|
|
||||||
bookTitle.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
bookTitle.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||||
bookTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", this.add));
|
|
||||||
bookTitle.addActionListener(new java.awt.event.ActionListener() {
|
bookTitle.addActionListener(new java.awt.event.ActionListener() {
|
||||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
bookTitleActionPerformed(evt);
|
bookTitleActionPerformed(evt);
|
||||||
@ -98,6 +101,11 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
|||||||
lISBN.setText("ISBN:");
|
lISBN.setText("ISBN:");
|
||||||
|
|
||||||
ISBN.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
ISBN.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||||
|
ISBN.addActionListener(new java.awt.event.ActionListener() {
|
||||||
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
ISBNActionPerformed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
lcategory.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
lcategory.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||||
lcategory.setText("Kategoria:");
|
lcategory.setText("Kategoria:");
|
||||||
@ -202,33 +210,24 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
|||||||
private void CategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CategoryActionPerformed
|
private void CategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CategoryActionPerformed
|
||||||
// TODO add your handling code here:
|
// TODO add your handling code here:
|
||||||
}//GEN-LAST:event_CategoryActionPerformed
|
}//GEN-LAST:event_CategoryActionPerformed
|
||||||
|
|
||||||
public void ChangeOkButtonText(String s) {
|
public void ChangeOkButtonText(String s) {
|
||||||
this.SaveChanges.setText(s);
|
this.SaveChanges.setText(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
||||||
if(this.add){
|
if (this.add) {
|
||||||
Book b = new Book();
|
|
||||||
/*
|
Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), Integer.parseInt(year.getText()), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
|
||||||
b.name = bookTitle.getText();
|
b.insertToDB();
|
||||||
b.authorName = authorName.getText();
|
|
||||||
b.authorSurname = authorSurname.getText();
|
} else if (this.edit) {
|
||||||
b.publishing = publishing.getText();
|
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||||
b.year = Integer.parseInt(year.getText());
|
} else if (this.delete) {
|
||||||
b.ISBN = ISBN.getText();
|
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||||
b.category = Category.getSelectedItem().toString();
|
|
||||||
b.insertQuery();
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
else if(this.edit){
|
dispose();
|
||||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
|
||||||
}
|
|
||||||
else if(this.delete){
|
|
||||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
|
||||||
}
|
|
||||||
dispose();
|
|
||||||
}//GEN-LAST:event_SaveChangesActionPerformed
|
}//GEN-LAST:event_SaveChangesActionPerformed
|
||||||
|
|
||||||
private void authorSurnameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_authorSurnameActionPerformed
|
private void authorSurnameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_authorSurnameActionPerformed
|
||||||
@ -239,6 +238,10 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
|||||||
// TODO add your handling code here:
|
// TODO add your handling code here:
|
||||||
}//GEN-LAST:event_bookTitleActionPerformed
|
}//GEN-LAST:event_bookTitleActionPerformed
|
||||||
|
|
||||||
|
private void ISBNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ISBNActionPerformed
|
||||||
|
// TODO add your handling code here:
|
||||||
|
}//GEN-LAST:event_ISBNActionPerformed
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
*/
|
*/
|
||||||
@ -273,9 +276,7 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
|||||||
new BookFieldPattern().setVisible(false);
|
new BookFieldPattern().setVisible(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
package library;
|
package library;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -13,27 +14,27 @@ import java.sql.Statement;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Agnieszka
|
* @author Agnieszka insert, delete i update do przeniesienia tutaj (9metod)
|
||||||
* insert, delete i update do przeniesienia tutaj (9metod)
|
|
||||||
*/
|
*/
|
||||||
public class Database {
|
public class Database {
|
||||||
|
|
||||||
public static final String DRIVER = "org.sqlite.JDBC";
|
public static final String DRIVER = "org.sqlite.JDBC";
|
||||||
public static final String DB_URL = "jdbc:sqlite:biblioteka.db"; // ścieżka do bazy
|
public static final String DB_URL = "jdbc:sqlite:biblioteka.db"; // ścieżka do bazy
|
||||||
|
|
||||||
private Connection conn;
|
private Connection conn;
|
||||||
private Statement stat;
|
private Statement stat;
|
||||||
|
|
||||||
public Database() {
|
public Database() {
|
||||||
try {
|
try {
|
||||||
Class.forName(Database.DRIVER);
|
Class.forName(Database.DRIVER);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
System.err.println("Brak sterownika JDBC");
|
System.err.println("Brak sterownika JDBC");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = DriverManager.getConnection(DB_URL);
|
conn = DriverManager.getConnection(DB_URL);
|
||||||
stat = conn.createStatement();
|
stat = conn.createStatement();
|
||||||
@ -41,27 +42,40 @@ public class Database {
|
|||||||
System.err.println("Problem z otwarciem polaczenia");
|
System.err.println("Problem z otwarciem polaczenia");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
createTables();
|
createTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean createTables() {
|
public void selectAllFromBooks() {
|
||||||
String createBooks = "CREATE TABLE IF NOT EXISTS books (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(255), author_name varchar(50), author_surname varchar(50), publishing varchar(50), year int, isbn varchar(12), category varchar(100))";
|
try {
|
||||||
String createAlbums ="CREATE TABLE IF NOT EXISTS albums (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(255), musican varchar(50), author_surname varchar(50), year int, category varchar(100))";
|
ResultSet result = stat.executeQuery("SELECT * FROM books");
|
||||||
|
|
||||||
|
while (result.next()) {
|
||||||
|
System.out.println("WYniki");
|
||||||
|
System.out.println(result.getInt("id") + " " + result.getInt("year") + result.getString("name") + result.getString("author_name") + result.getString("author_surname") + result.getString("publishing") + result.getString("isbn") + result.getString("category"));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean createTables() {
|
||||||
|
String createBooks = "CREATE TABLE IF NOT EXISTS books (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(255), author_name varchar(50), author_surname varchar(50), publishing varchar(50), year int, isbn varchar(20), category varchar(100))";
|
||||||
|
String createAlbums = "CREATE TABLE IF NOT EXISTS albums (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(255), musican varchar(50), author_surname varchar(50), year int, category varchar(100))";
|
||||||
String createMovies = "CREATE TABLE IF NOT EXISTS movies (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(255), director varchar(50), year int, category varchar(100))";
|
String createMovies = "CREATE TABLE IF NOT EXISTS movies (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(255), director varchar(50), year int, category varchar(100))";
|
||||||
try {
|
try {
|
||||||
stat.execute(createBooks);
|
stat.execute(createBooks);
|
||||||
stat.execute(createAlbums);
|
stat.execute(createAlbums);
|
||||||
stat.execute(createMovies);
|
stat.execute(createMovies);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
JOptionPane.showMessageDialog(null, "Błąd przy tworzeniu tabel bazy danych.", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Błąd przy odczycie zbazy danych.", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertBookQ(Book b){
|
public void insertBookQ(Book b) {
|
||||||
try {
|
try {
|
||||||
PreparedStatement prepStmt = conn.prepareStatement(
|
PreparedStatement prepStmt = conn.prepareStatement(
|
||||||
"INSERT INTO books VALUES (NULL, ?, ?, ?, ?, ?, ?, ?);");
|
"INSERT INTO books VALUES (NULL, ?, ?, ?, ?, ?, ?, ?);");
|
||||||
prepStmt.setString(1, b.getName());
|
prepStmt.setString(1, b.getName());
|
||||||
@ -71,10 +85,10 @@ public class Database {
|
|||||||
prepStmt.setInt(5, b.getYear());
|
prepStmt.setInt(5, b.getYear());
|
||||||
prepStmt.setString(6, b.getISBN());
|
prepStmt.setString(6, b.getISBN());
|
||||||
prepStmt.setString(7, b.getCategory());
|
prepStmt.setString(7, b.getCategory());
|
||||||
|
|
||||||
prepStmt.execute();
|
prepStmt.execute();
|
||||||
|
|
||||||
/* String sel = "SELECT * FROM books WHERE name LIKE ? AND author_name LIKE ? AND author_surname LIKE ? AND publishing LIKE ? AND year = ? AND isbn LIKE ? AND category LIKE ? ;";
|
/* String sel = "SELECT * FROM books WHERE name LIKE ? AND author_name LIKE ? AND author_surname LIKE ? AND publishing LIKE ? AND year = ? AND isbn LIKE ? AND category LIKE ? ;";
|
||||||
PreparedStatement prepStmt2 = conn.prepareStatement(sel);
|
PreparedStatement prepStmt2 = conn.prepareStatement(sel);
|
||||||
prepStmt.setString(1, b.getName());
|
prepStmt.setString(1, b.getName());
|
||||||
prepStmt.setString(2, b.getAuthorName());
|
prepStmt.setString(2, b.getAuthorName());
|
||||||
@ -86,20 +100,36 @@ public class Database {
|
|||||||
|
|
||||||
ResultSet rs = stat.executeQuery(sel);
|
ResultSet rs = stat.executeQuery(sel);
|
||||||
b = new Book(rs.getInt("id"), rs.getString("name"), rs.getString("author_name"), rs.getString("suthor_surname"), rs.getInt("year"), rs.getString("isbn"), rs.getString("publishing"), rs.getString("category"));
|
b = new Book(rs.getInt("id"), rs.getString("name"), rs.getString("author_name"), rs.getString("suthor_surname"), rs.getInt("year"), rs.getString("isbn"), rs.getString("publishing"), rs.getString("category"));
|
||||||
*/
|
*/
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void insertAlbumQ(Album a) {
|
||||||
|
try {
|
||||||
|
PreparedStatement prepStmt = conn.prepareStatement(
|
||||||
|
"INSERT INTO albums VALUES (NULL, ?, ?, ?, ?);");
|
||||||
|
prepStmt.setString(1, a.getName());
|
||||||
|
prepStmt.setString(2, a.getMusican());
|
||||||
|
prepStmt.setInt(3, a.getYear());
|
||||||
|
prepStmt.setString(4, a.getCategory());
|
||||||
|
|
||||||
|
prepStmt.execute();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public List<Book> selectBooks() {
|
public List<Book> selectBooks() {
|
||||||
List<Book> books = new LinkedList<Book>();
|
List<Book> books = new LinkedList<Book>();
|
||||||
try {
|
try {
|
||||||
ResultSet result = stat.executeQuery("SELECT * FROM books");
|
ResultSet result = stat.executeQuery("SELECT * FROM books");
|
||||||
int id, year;
|
int id, year;
|
||||||
String name, authorName, authorSurname, isbn, category, publishing;
|
String name, authorName, authorSurname, isbn, category, publishing;
|
||||||
while(result.next()) {
|
while (result.next()) {
|
||||||
id = result.getInt("id");
|
id = result.getInt("id");
|
||||||
year = result.getInt("year");
|
year = result.getInt("year");
|
||||||
name = result.getString("name");
|
name = result.getString("name");
|
||||||
@ -108,7 +138,6 @@ public class Database {
|
|||||||
publishing = result.getString("publishing");
|
publishing = result.getString("publishing");
|
||||||
isbn = result.getString("isbn");
|
isbn = result.getString("isbn");
|
||||||
category = result.getString("category");
|
category = result.getString("category");
|
||||||
|
|
||||||
books.add(new Book(id, name, authorName, authorSurname, year, isbn, publishing, category));
|
books.add(new Book(id, name, authorName, authorSurname, year, isbn, publishing, category));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -123,13 +152,13 @@ public class Database {
|
|||||||
ResultSet result = stat.executeQuery("SELECT * FROM albums");
|
ResultSet result = stat.executeQuery("SELECT * FROM albums");
|
||||||
int id, year;
|
int id, year;
|
||||||
String name, musican, category;
|
String name, musican, category;
|
||||||
while(result.next()) {
|
while (result.next()) {
|
||||||
id = result.getInt("id");
|
id = result.getInt("id");
|
||||||
year = result.getInt("year");
|
year = result.getInt("year");
|
||||||
name = result.getString("name");
|
name = result.getString("name");
|
||||||
musican = result.getString("musican");
|
musican = result.getString("musican");
|
||||||
category = result.getString("category");
|
category = result.getString("category");
|
||||||
|
|
||||||
albums.add(new Album(id, name, musican, year, category));
|
albums.add(new Album(id, name, musican, year, category));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -137,27 +166,28 @@ public class Database {
|
|||||||
}
|
}
|
||||||
return albums;
|
return albums;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Movie> selectMovies() {
|
public List<Movie> selectMovies() {
|
||||||
List<Movie> movies = new LinkedList<Movie>();
|
List<Movie> movies = new LinkedList<Movie>();
|
||||||
try {
|
try {
|
||||||
ResultSet result = stat.executeQuery("SELECT * FROM movies");
|
ResultSet result = stat.executeQuery("SELECT * FROM movies");
|
||||||
int id, year;
|
int id, year;
|
||||||
String name, category, director;
|
String name, category, director;
|
||||||
while(result.next()) {
|
while (result.next()) {
|
||||||
id = result.getInt("id");
|
id = result.getInt("id");
|
||||||
year = result.getInt("year");
|
year = result.getInt("year");
|
||||||
name = result.getString("name");
|
name = result.getString("name");
|
||||||
director = result.getString("director");
|
director = result.getString("director");
|
||||||
category = result.getString("category");
|
category = result.getString("category");
|
||||||
movies.add(new Movie(id, name, director, year, category));
|
movies.add(new Movie(id, name, director, year, category));
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
}
|
}
|
||||||
return movies;
|
return movies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeConnection() {
|
public void closeConnection() {
|
||||||
try {
|
try {
|
||||||
conn.close();
|
conn.close();
|
||||||
@ -167,4 +197,3 @@ public class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,41 +8,48 @@ package library;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Agnieszka
|
* @author Agnieszka
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class Item {
|
public abstract class Item {
|
||||||
|
|
||||||
public abstract void insertToDB();
|
public abstract void insertToDB();
|
||||||
public abstract void delFromDB();
|
|
||||||
public abstract void editInDB();
|
public abstract void delFromDB();
|
||||||
|
|
||||||
public void setName(String s){
|
public abstract void editInDB();
|
||||||
|
|
||||||
|
public void setName(String s) {
|
||||||
this.name = s;
|
this.name = s;
|
||||||
}
|
}
|
||||||
public void setCategory(String s){
|
|
||||||
|
public void setCategory(String s) {
|
||||||
this.category = s;
|
this.category = s;
|
||||||
}
|
}
|
||||||
public void setYear(int i){
|
|
||||||
|
public void setYear(int i) {
|
||||||
this.year = i;
|
this.year = i;
|
||||||
}
|
}
|
||||||
public void setId(int i){
|
|
||||||
|
public void setId(int i) {
|
||||||
this.id = i;
|
this.id = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
public String getName(){
|
return this.name;
|
||||||
return this.name;
|
}
|
||||||
}
|
|
||||||
public String getCategory(){
|
public String getCategory() {
|
||||||
return this.category;
|
return this.category;
|
||||||
}
|
}
|
||||||
public int getYear(){
|
|
||||||
return this.year;
|
public int getYear() {
|
||||||
}
|
return this.year;
|
||||||
public int getId(){
|
}
|
||||||
return this.id;
|
|
||||||
}
|
public int getId() {
|
||||||
|
return this.id;
|
||||||
private String name, category;
|
}
|
||||||
private int year, id;
|
|
||||||
|
private String name, category;
|
||||||
|
private int year, id;
|
||||||
}
|
}
|
||||||
|
@ -92,9 +92,7 @@ public class ListResult extends javax.swing.JFrame {
|
|||||||
new ListResult().setVisible(true);
|
new ListResult().setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
|
@ -203,40 +203,40 @@ public class MainMenu extends javax.swing.JFrame {
|
|||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
private void bMovieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bMovieActionPerformed
|
private void bMovieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bMovieActionPerformed
|
||||||
if(radioBAdd.getModel().isSelected()){
|
if (radioBAdd.getModel().isSelected()) {
|
||||||
MovieFieldPattern b = new MovieFieldPattern(true);
|
MovieFieldPattern b = new MovieFieldPattern(true);
|
||||||
b.setVisible(true);
|
b.setVisible(true);
|
||||||
b.add=true;
|
b.add = true;
|
||||||
}
|
}
|
||||||
if(radioBEdit.getModel().isSelected()){
|
if (radioBEdit.getModel().isSelected()) {
|
||||||
MovieFieldPattern b = new MovieFieldPattern();
|
MovieFieldPattern b = new MovieFieldPattern();
|
||||||
b.setVisible(true);
|
b.setVisible(true);
|
||||||
b.edit=true;
|
b.edit = true;
|
||||||
}
|
}
|
||||||
if(radioBSearch.getModel().isSelected()){
|
if (radioBSearch.getModel().isSelected()) {
|
||||||
MovieFieldPattern b = new MovieFieldPattern();
|
MovieFieldPattern b = new MovieFieldPattern();
|
||||||
b.setVisible(true);
|
b.setVisible(true);
|
||||||
b.delete=true;
|
b.delete = true;
|
||||||
}
|
}
|
||||||
}//GEN-LAST:event_bMovieActionPerformed
|
}//GEN-LAST:event_bMovieActionPerformed
|
||||||
|
|
||||||
private void bAlbumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAlbumActionPerformed
|
private void bAlbumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAlbumActionPerformed
|
||||||
|
|
||||||
if(radioBAdd.getModel().isSelected()){
|
if (radioBAdd.getModel().isSelected()) {
|
||||||
AlbumFieldPattern b = new AlbumFieldPattern(true);
|
AlbumFieldPattern b = new AlbumFieldPattern(true);
|
||||||
b.setVisible(true);
|
b.setVisible(true);
|
||||||
b.add=true;
|
b.add = true;
|
||||||
}
|
}
|
||||||
if(radioBEdit.getModel().isSelected()){
|
if (radioBEdit.getModel().isSelected()) {
|
||||||
AlbumFieldPattern b = new AlbumFieldPattern();
|
AlbumFieldPattern b = new AlbumFieldPattern();
|
||||||
b.setVisible(true);
|
b.setVisible(true);
|
||||||
b.edit=true;
|
b.edit = true;
|
||||||
}
|
}
|
||||||
if(radioBSearch.getModel().isSelected()){
|
if (radioBSearch.getModel().isSelected()) {
|
||||||
MovieFieldPattern b = new MovieFieldPattern();
|
MovieFieldPattern b = new MovieFieldPattern();
|
||||||
b.setVisible(true);
|
b.setVisible(true);
|
||||||
b.delete=true;
|
b.delete = true;
|
||||||
}
|
}
|
||||||
}//GEN-LAST:event_bAlbumActionPerformed
|
}//GEN-LAST:event_bAlbumActionPerformed
|
||||||
|
|
||||||
private void bUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bUserActionPerformed
|
private void bUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bUserActionPerformed
|
||||||
@ -256,22 +256,22 @@ public class MainMenu extends javax.swing.JFrame {
|
|||||||
}//GEN-LAST:event_radioBAddActionPerformed
|
}//GEN-LAST:event_radioBAddActionPerformed
|
||||||
|
|
||||||
private void bBookActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBookActionPerformed
|
private void bBookActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBookActionPerformed
|
||||||
if(radioBAdd.getModel().isSelected()){
|
if (radioBAdd.getModel().isSelected()) {
|
||||||
BookFieldPattern b = new BookFieldPattern(true);
|
BookFieldPattern b = new BookFieldPattern(true);
|
||||||
b.setVisible(true);
|
b.setVisible(true);
|
||||||
b.add=true;
|
b.add = true;
|
||||||
}
|
}
|
||||||
if(radioBEdit.getModel().isSelected()){
|
if (radioBEdit.getModel().isSelected()) {
|
||||||
BookFieldPattern b = new BookFieldPattern();
|
BookFieldPattern b = new BookFieldPattern();
|
||||||
b.setVisible(true);
|
b.setVisible(true);
|
||||||
b.edit=true;
|
b.edit = true;
|
||||||
}
|
}
|
||||||
if(radioBSearch.getModel().isSelected()){
|
if (radioBSearch.getModel().isSelected()) {
|
||||||
BookFieldPattern b = new BookFieldPattern();
|
BookFieldPattern b = new BookFieldPattern();
|
||||||
b.setVisible(true);
|
b.setVisible(true);
|
||||||
b.delete=true;
|
b.delete = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}//GEN-LAST:event_bBookActionPerformed
|
}//GEN-LAST:event_bBookActionPerformed
|
||||||
|
|
||||||
private void radioBDelete1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioBDelete1ActionPerformed
|
private void radioBDelete1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioBDelete1ActionPerformed
|
||||||
@ -279,15 +279,18 @@ public class MainMenu extends javax.swing.JFrame {
|
|||||||
}//GEN-LAST:event_radioBDelete1ActionPerformed
|
}//GEN-LAST:event_radioBDelete1ActionPerformed
|
||||||
|
|
||||||
private void allBooksShowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allBooksShowActionPerformed
|
private void allBooksShowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allBooksShowActionPerformed
|
||||||
|
|
||||||
ListResult n = new ListResult();
|
ListResult n = new ListResult();
|
||||||
n.setVisible(true);
|
n.setVisible(true);
|
||||||
Database d = new Database();
|
Database d = new Database();
|
||||||
List<Book> books = new LinkedList<>();
|
List<Book> books = new LinkedList<>();
|
||||||
books = d.selectBooks();
|
books = d.selectBooks();
|
||||||
System.out.println("Lista książek:");
|
System.out.println("Lista książek:");
|
||||||
for(Book k: books)
|
for (Book k : books) {
|
||||||
System.out.println(k);
|
System.out.println(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
d.selectAllFromBooks();
|
||||||
}//GEN-LAST:event_allBooksShowActionPerformed
|
}//GEN-LAST:event_allBooksShowActionPerformed
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -321,7 +324,7 @@ public class MainMenu extends javax.swing.JFrame {
|
|||||||
/* Create and display the form */
|
/* Create and display the form */
|
||||||
java.awt.EventQueue.invokeLater(() -> {
|
java.awt.EventQueue.invokeLater(() -> {
|
||||||
new MainMenu().setVisible(true);
|
new MainMenu().setVisible(true);
|
||||||
/* java.awt.EventQueue.invokeLater(() ->*/ });
|
/* java.awt.EventQueue.invokeLater(() ->*/ });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
|
@ -21,12 +21,14 @@ public class MovieFieldPattern extends javax.swing.JFrame {
|
|||||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
initComponents();
|
initComponents();
|
||||||
}
|
}
|
||||||
public MovieFieldPattern(boolean required) {
|
|
||||||
|
public MovieFieldPattern(boolean required) {
|
||||||
initComponents();
|
initComponents();
|
||||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
movieTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
movieTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
||||||
}
|
}
|
||||||
public boolean add= false, delete = false, edit = false;
|
public boolean add = false, delete = false, edit = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called from within the constructor to initialize the form.
|
* 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
|
* WARNING: Do NOT modify this code. The content of this method is always
|
||||||
@ -167,23 +169,21 @@ public class MovieFieldPattern extends javax.swing.JFrame {
|
|||||||
|
|
||||||
public void ChangeOkButtonText(String s) {
|
public void ChangeOkButtonText(String s) {
|
||||||
this.SaveChanges.setText(s);
|
this.SaveChanges.setText(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CategoryActionPerformed
|
private void CategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CategoryActionPerformed
|
||||||
// TODO add your handling code here:
|
// TODO add your handling code here:
|
||||||
}//GEN-LAST:event_CategoryActionPerformed
|
}//GEN-LAST:event_CategoryActionPerformed
|
||||||
|
|
||||||
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
||||||
if(this.add){
|
if (this.add) {
|
||||||
JOptionPane.showMessageDialog(null, "DODAJ");
|
JOptionPane.showMessageDialog(null, "DODAJ");
|
||||||
|
} else if (this.edit) {
|
||||||
|
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||||
|
} else if (this.delete) {
|
||||||
|
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||||
}
|
}
|
||||||
else if(this.edit){
|
dispose();
|
||||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
|
||||||
}
|
|
||||||
else if(this.delete){
|
|
||||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
|
||||||
}
|
|
||||||
dispose();
|
|
||||||
}//GEN-LAST:event_SaveChangesActionPerformed
|
}//GEN-LAST:event_SaveChangesActionPerformed
|
||||||
|
|
||||||
private void scriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scriptActionPerformed
|
private void scriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scriptActionPerformed
|
||||||
@ -228,9 +228,7 @@ public class MovieFieldPattern extends javax.swing.JFrame {
|
|||||||
new MovieFieldPattern().setVisible(false);
|
new MovieFieldPattern().setVisible(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
|
@ -14,44 +14,39 @@ import javax.swing.JTextField;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Agnieszka
|
* @author Agnieszka walitator używający wyrażeń regularnych do sprawdzania pól
|
||||||
* walitator używający wyrażeń regularnych do sprawdzania pól formularzy
|
* formularzy wyrażenia regularne jako parametr konstuktora
|
||||||
* wyrażenia regularne jako parametr konstuktora
|
|
||||||
*/
|
*/
|
||||||
public class Validation extends InputVerifier {
|
public class Validation extends InputVerifier {
|
||||||
public Validation(String ex, boolean rq){
|
|
||||||
expression=ex;
|
public Validation(String ex, boolean rq) {
|
||||||
|
expression = ex;
|
||||||
required = rq;
|
required = rq;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean verify(JComponent input) {
|
public boolean verify(JComponent input) {
|
||||||
JTextField tf = (JTextField) input;
|
JTextField tf = (JTextField) input;
|
||||||
Pattern p = Pattern.compile(expression);
|
Pattern p = Pattern.compile(expression);
|
||||||
Matcher m = p.matcher(tf.getText());
|
Matcher m = p.matcher(tf.getText());
|
||||||
if(required) {
|
if (required) {
|
||||||
if (m.matches()){
|
if (m.matches()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else{
|
if ("".equals(tf.getText())) {
|
||||||
if("".equals(tf.getText())){
|
JOptionPane.showMessageDialog(null, "Pole wymagane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
JOptionPane.showMessageDialog(null, "Pole wymagane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
|
} else {
|
||||||
}
|
JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
else{
|
}
|
||||||
JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
} else if (m.matches() || "".equals(tf.getText())) {
|
||||||
}
|
return true;
|
||||||
}
|
} else {
|
||||||
else{
|
JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
if (m.matches() || "".equals(tf.getText())){
|
return false;
|
||||||
return true;
|
}
|
||||||
}
|
}
|
||||||
else{
|
String expression;
|
||||||
JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
|
boolean required = false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String expression;
|
|
||||||
boolean required = false;
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user