0

I have made a feedback submit page when user click on submit button it will submit using mysql jdbc connector.

I want to change text of submit button on click then it will execute sql statements after completing queries it will show submit button again. It's like a loader animation on submit button.

 public  void submitFeedback() throws SQLException, ClassNotFoundException {
------> feedbtn.setText("Submitting ...");    <-----------------------------------
        ConnectionClass connectionclass = new ConnectionClass();
        Connection connection = (Connection) connectionclass.getConnection();
        System.out.println("connection" +connection);
        star =  Math.round(rating.getRating());
        msg = feedtextarea.getText();
        name = nameinput.getText();
        email = emailinput.getText();


        String sql  = "INSERT INTO feedback(name,msg,star,email) VALUES('"+name+"','"+msg+"',"+star+",'"+email+"')";
        Statement st = connection.createStatement();
        System.out.println(sql);
        result = st.executeUpdate(sql);

        if(result == 1)
        {
            System.out.println(result);
            response.setText("Your response has been submitted !");
            rating.setRating(0.0);
            feedtextarea.setText("");
            nameinput.setText("");
            emailinput.setText("");
        }else{
            System.out.println(result);
            response.setText("Something went wrong !");
        }
        feedbtn.setText("Submit");
    }

feedbtn is id of submit button .when click on submit button it should show submitting... but it shows after execute all queries then converts to submit again very fast.

Gaurav
  • 1
  • Try to add a timer to the queries to see if the queries execute to fast for your text changing to happen – ADSquared Jun 22 '22 at 14:16
  • 1
    You're (presumably: you would get exceptions otherwise) executing this all on the FX Application Thread. That thread is responsible for rendering the UI. Since it's busy running your database queries, it can't actually update the UI with the changes you made to the button's text until everything is completed, at which point the text is back to its original value. – James_D Jun 22 '22 at 15:00
  • @James_D Yes James, You'are correct I am getting this error . So what should I do. – Gaurav Jun 22 '22 at 16:05
  • See the duplicate question: it has a complete answer. – James_D Jun 22 '22 at 16:06
  • can you give link of that question if you've no problem thanks :) – Gaurav Jun 22 '22 at 16:13
  • It is linked at the top of the page, where it says "This question already has answers here" – James_D Jun 22 '22 at 16:53
  • You could try having a look at this article here: https://www.pragmaticcoding.ca/javafx/elements/fxat . It explains exactly how to do what you want. – DaveB Jun 22 '22 at 19:43

0 Answers0