Input Verifier - pola wymagane poprawione
This commit is contained in:
parent
9ef87ea55f
commit
100efa20f7
@ -142,6 +142,7 @@
|
|||||||
</Events>
|
</Events>
|
||||||
<AuxValues>
|
<AuxValues>
|
||||||
<AuxValue name="JavaCodeGenerator_SerializeTo" type="java.lang.String" value="BookFieldPattern_bookTitle"/>
|
<AuxValue name="JavaCodeGenerator_SerializeTo" type="java.lang.String" value="BookFieldPattern_bookTitle"/>
|
||||||
|
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
|
||||||
</AuxValues>
|
</AuxValues>
|
||||||
</Component>
|
</Component>
|
||||||
<Component class="javax.swing.JLabel" name="authorname">
|
<Component class="javax.swing.JLabel" name="authorname">
|
||||||
|
@ -32,7 +32,12 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
|||||||
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(verify);
|
||||||
|
authorName.setInputVerifier(verify);
|
||||||
|
authorSurname.setInputVerifier(verify);
|
||||||
|
year.setInputVerifier(verify);
|
||||||
|
ISBN.setInputVerifier(verify);
|
||||||
|
publishing.setInputVerifier(verify);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean add = false, delete = false, edit = false, search = false;
|
public boolean add = false, delete = false, edit = false, search = false;
|
||||||
@ -344,7 +349,7 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
|||||||
private javax.swing.JTextField authorSurname;
|
private javax.swing.JTextField authorSurname;
|
||||||
private javax.swing.JLabel authorname;
|
private javax.swing.JLabel authorname;
|
||||||
private javax.swing.JLabel authorsurname;
|
private javax.swing.JLabel authorsurname;
|
||||||
private javax.swing.JTextField bookTitle;
|
javax.swing.JTextField bookTitle;
|
||||||
private javax.swing.JButton cancel;
|
private javax.swing.JButton cancel;
|
||||||
private javax.swing.JLabel jLabel1;
|
private javax.swing.JLabel jLabel1;
|
||||||
private javax.swing.JLabel lISBN;
|
private javax.swing.JLabel lISBN;
|
||||||
|
@ -31,39 +31,40 @@ public class Validation extends InputVerifier {
|
|||||||
|
|
||||||
public boolean checkField(JComponent input) {
|
public boolean checkField(JComponent input) {
|
||||||
JTextField tf = (JTextField) input;
|
JTextField tf = (JTextField) input;
|
||||||
if(required){
|
if (required) {
|
||||||
if("".equals(tf.getText())){
|
if ((tf.getText().equals(""))) {
|
||||||
JOptionPane.showMessageDialog(null, "Pole wymagane!", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Pole wymagane!", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (input.getName().equals("year")) {
|
if (input.getName() != null){
|
||||||
|
if (input.getName().equals("year")) {
|
||||||
if (!"".equals(tf.getText())) {
|
if (!"".equals(tf.getText())) {
|
||||||
try {
|
try {
|
||||||
year = Integer.parseInt(tf.getText());
|
year = Integer.parseInt(tf.getText());
|
||||||
if (year > 2016 || year < 1900) {
|
if (year > 2016 || year < 1900) {
|
||||||
JOptionPane.showMessageDialog(null, "Data spoza zakresu.", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Data spoza zakresu.", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Wpisz datę w formacie: YYYY", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
JOptionPane.showMessageDialog(null, "Wpisz datę w formacie: YYYY", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (input.getName().equals("isbn")) {
|
||||||
if (input.getName().equals("isbn")) {
|
if (!"".equals(tf.getText())) {
|
||||||
if (!"".equals(tf.getText())) {
|
Pattern p = Pattern.compile("[0-9][0-9][0-9]-[0-9]-[0-9][0-9][0-9][0-9]-[0-9]");
|
||||||
Pattern p = Pattern.compile("[0-9][0-9][0-9]-[0-9]-[0-9][0-9][0-9][0-9]-[0-9]");
|
Matcher m = p.matcher(tf.getText());
|
||||||
Matcher m = p.matcher(tf.getText());
|
if (m.matches()) {
|
||||||
if (m.matches()) {
|
return true;
|
||||||
return true;
|
} else {
|
||||||
} else {
|
JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user