parsing primitive types using java.util.Scanner
- by Rich Fluckiger
I'm new to java so forgive the noob question.
I have created a swing application that basically has three input strings in JTextFields:
loanAmount, interestRate and loanYears and a single submit button with the EventAction.
I'm trying to use the java.util.Scanner to parse the input to primitive types that I can use in calculations.
I'm getting an error in NetBeans indicating that my variables are not recognized?
should I not be calling System.in?
private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
    Scanner keyInput = new Scanner(System.in);
    while (true)
        try{
            double amount = keyInput.nextDouble(loanAmount.getText());
            double interest = keyInput.nextDouble(interestRate.getText());
            int years = keyInput.nextInt(loanYears.getText());
        } catch (NumberFormatException nfe){
        }
}