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> </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">

View File

@ -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;

View File

@ -31,14 +31,14 @@ 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() != null){
if (input.getName().equals("year")) { 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());
@ -65,6 +65,7 @@ public class Validation extends InputVerifier {
} }
return true; return true;
} }
}
return true; return true;
} }