Delete JTexfield and insert another data

2

Good I want to delete a JTexfield save that data in my variable num1 and insert another to fill the variable num2. These two will go to a method in the operations class that receives those 2 parameters here part of the code

JButton btnmulti = new JButton("*");
    btnmulti.setBounds(10, 132, 49, 46);
    contentPane.add(btnmulti);
    btnmulti.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if(num1==null){

                datos = textField.getText();
                num1= Integer.parseInt(datos);
                textField.setText(null);

            }
            if(num2==null){
                datos = textField.getText();
                num2= Integer.parseInt(datos);
            }

            Operaciones.multiplicacion(num1, num2);
            String res =  Integer.toString(Operaciones.multiplicacion(num1, num2));

            textField.setText(res);

        }
    });
    
asked by Rickzize 10.02.2017 в 06:32
source

1 answer

0

What you must do is add a condition before doing the multiplication to make sure that neither of the two operands is null . Modify that part of the code by adding the condition, with what will remain:

if(num1 != null && num2 != null){
    Operaciones.multiplicacion(num1, num2);
    String res =  Integer.toString(Operaciones.multiplicacion(num1, num2));

    textField.setText(res);
}
    
answered by 10.02.2017 / 10:24
source