private void addBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBtnActionPerformed

        question = questionField.getText();
        instructions = instructionField.getText();
        
        if (instructions.equals("")|| instructions==null)
           JOptionPane.showMessageDialog(null, "you have to add instructions!"); 

        // set the match patter of "[]"
        Matcher matcher = Pattern.compile("\\[([^\\]]+)").matcher(question);

        ArrayList<String> answers = new ArrayList<String>();
        
          int counter = 0;

        int pos = -1;
        while (matcher.find(pos + 1)) {
            pos = matcher.start();
            // Add the matched word to the Arraylist
            answers.add(matcher.group(1));
             counter++;
        }
        
         if (counter==0)
                JOptionPane.showMessageDialog(null, "you have to add at leat one blank!");

        // Find the word with bracket and replace it with blank
        String newQuestion = question.replaceAll("\\[.*?]", "_____");

        //System.out.println(answers);
        System.out.println(newQuestion);

        int key = 0;

        try {
            connectDb();

            int QType_ID = 2;

            String sql = "INSERT INTO question (QType_ID) VALUES(" + QType_ID + ")";

            /////////////// INSERT THE QUESTION & Get the last id that was inserted for the question ////////////////
            PreparedStatement pstmt = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            pstmt.executeUpdate();
            ResultSet keys = pstmt.getGeneratedKeys();
            keys.next();
            key = keys.getInt(1);

            // Insert Question into DB
            sql1 = "INSERT INTO fib (QuestionID,QuestionText,QuestionBlank, QuestionType,Instructions) VALUES(' " + key + "', '" + question + "', '" + newQuestion + "' , 2, '" + instructions + "')";
            st.executeUpdate(sql1);

            System.out.println(sql1);

        } catch (Exception exc) {
            exc.printStackTrace();
        }

        // Loop through ArrayList and Insert Answer into DB
        for (String answer : answers) {

            try {
                connectDb();

                // Insert answer to DB
                sql2 = "INSERT INTO fibanswer (AnswerContentText,QuestionID) VALUES('" + answer + "', '" + key + "')";
                st.executeUpdate(sql2);

                System.out.println(sql2);

            } catch (Exception exc) {
                exc.printStackTrace();
            }

        }

        refresh();
        if (addingFlag == addingState.WHENEDITSECTIONS) {
            fatherPanel.refresh();
            dispose();
                        //fatherPanel.setVisible(true);

        }

        instructionField.setText("");
        questionField.setText("");

    }//GEN-LAST:event_addBtnActionPerformed