getting integer values from textfield

Sumeet Gavhale picture Sumeet Gavhale · Jan 5, 2013 · Viewed 123.7k times · Source

I am trying to get Integer values from my jtextfield but not able to it is showing incompatible datatypes required int found string. Is there some other way of writing my code is as follows and i want to get only integer values

private void jTextField2MouseClicked(java.awt.event.MouseEvent evt) {
        if(evt.getSource()==jTextField2){
            int jml = jTextField3.getText();
            jTextField1.setText(numberToWord(jml));

        }
    }

Answer

Rahul picture Rahul · Jan 5, 2013

You need to use Integer.parseInt(String)

private void jTextField2MouseClicked(java.awt.event.MouseEvent evt) {
        if(evt.getSource()==jTextField2){
            int jml = Integer.parseInt(jTextField3.getText());
            jTextField1.setText(numberToWord(jml));

        }
    }