Input Verifier - pola wymagane poprawione

This commit is contained in:
Agnieszka Janicka 2016-06-09 21:05:57 +02:00
parent 9ef87ea55f
commit 100efa20f7
3 changed files with 33 additions and 26 deletions

View File

@ -142,6 +142,7 @@
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_SerializeTo" type="java.lang.String" value="BookFieldPattern_bookTitle"/>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="authorname">

View File

@ -32,7 +32,12 @@ public class BookFieldPattern extends javax.swing.JFrame {
public BookFieldPattern(boolean required) {
initComponents();
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;
@ -344,7 +349,7 @@ public class BookFieldPattern extends javax.swing.JFrame {
private javax.swing.JTextField authorSurname;
private javax.swing.JLabel authorname;
private javax.swing.JLabel authorsurname;
private javax.swing.JTextField bookTitle;
javax.swing.JTextField bookTitle;
private javax.swing.JButton cancel;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel lISBN;

View File

@ -31,39 +31,40 @@ public class Validation extends InputVerifier {
public boolean checkField(JComponent input) {
JTextField tf = (JTextField) input;
if(required){
if("".equals(tf.getText())){
if (required) {
if ((tf.getText().equals(""))) {
JOptionPane.showMessageDialog(null, "Pole wymagane!", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
return false;
return false;
}
}
if (input.getName().equals("year")) {
if (!"".equals(tf.getText())) {
try {
year = Integer.parseInt(tf.getText());
if (year > 2016 || year < 1900) {
JOptionPane.showMessageDialog(null, "Data spoza zakresu.", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
if (input.getName() != null){
if (input.getName().equals("year")) {
if (!"".equals(tf.getText())) {
try {
year = Integer.parseInt(tf.getText());
if (year > 2016 || year < 1900) {
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;
}
} 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 (!"".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]");
Matcher m = p.matcher(tf.getText());
if (m.matches()) {
return true;
} else {
JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
return false;
if (input.getName().equals("isbn")) {
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]");
Matcher m = p.matcher(tf.getText());
if (m.matches()) {
return true;
} else {
JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
return false;
}
}
return true;
}
return true;
}
return true;