I have problem with Text Field Auto Calculation in JAVA using Netbeans 7.2
My Question is if I will input numeric values in Text Field i-e (admission fee, monthly fee, transport fee etc) for auto addition and then input numeric values in Text Field i-e (dues) to auto subtract from the above auto addition before clicking submit Button to insert the total values in database so how i will get result of those numeric values in Text Field (Total) before clicking submit Button.
Please check snapshot:
My Source code:
try
{
String insrt = "Insert into fee (admission, monthly, transport, dues, total) values (?, ?, ?, ?, ?)";
PreparedStatement pstmt = conn.prepareStatement(insrt);
pstmt.setString(1, adm_fee.getText());
pstmt.setString(2, mnth_fee.getText());
pstmt.setString(3, trnsprt_fee.getText());
pstmt.setString(4, dues_fee.getText());
pstmt.setString(5, total_fee.getText());
pstmt.executeUpdate();
JOptionPane.showMessageDialog(null,"Record successfully inserted");
}
catch (Exception exp)
{
JOptionPane.showMessageDialog(null, exp);
}

I suggest use a
DocumentFilterthis will allow us to kill 2 birds with 1 stone.1) we need to filter what is inputted to
JTextFields to make sure our calculation wont go wrong2) We need to update the total on the fly i.e as more digits are added/removed.
Here is an example I made which uses
DocumentFilterand as you will see the Total field will be updated each time a new digit is entered/added to theJTextField(s) (also it wont allow alphabetic characters etc only digits):