Java Netbeans GUI application that demonstrate arithmetic operators.

Q7. Design a Java Netbeans GUI application that gives demonstration of all arithmetic operators.

Sol:

Create a GUI application as per following screenshot.

Screenshot

Double click BtnAdd button boundary and type the following code, below the line that says, ‘// TODO add your handling code here’

 

int n1,n2,a;

n1=Integer.parseInt(txt1.getText());

n2=Integer.parseInt(txt2.getText());

a=n1+n2;

lblres.setText(a+””);

lbl1.setText(“+”);

}

Double click BtnSub button boundary and type the following code, below the line that says, ‘// TODO add your handling code here’

int n1,n2,a;

n1=Integer.parseInt(txt1.getText());

n2=Integer.parseInt(txt2.getText());

a=n1-n2;

lblres.setText(a+””);

lbl1.setText(“-“);

}

Double click BtnMul button boundary and type the following code, below the line that says, ‘// TODO add your handling code here’

int n1,n2,a;

n1=Integer.parseInt(txt1.getText());

n2=Integer.parseInt(txt2.getText());

a=n1*n2;

lblres.setText(a+””);

lbl1.setText(“*”);

}

Double click BtnDiv button boundary and type the following code, below the line that says, ‘// TODO add your handling code here’

int n1,n2,a;

n1=Integer.parseInt(txt1.getText());

n2=Integer.parseInt(txt2.getText());

a=n1/n2;

lblres.setText(a+””);

lbl1.setText(“/”);

Double click BtnMod button boundary and type the following code, below the line that says, ‘// TODO add your handling code here’

int n1,n2,a;

n1=Integer.parseInt(txt1.getText());

n2=Integer.parseInt(txt2.getText());

a=n1%n2;

lblres.setText(a+””);

lbl1.setText(“%”);

Double click BtnClr button boundary and type the following code, below the line that says, ‘// TODO add your handling code here’

txt1.setText(“”);

txt2.setText(“”);

lblres.setText(“”);

lbl1.setText(“?”);

Double click BtnAdd button boundary and type the following code, below the line that says, ‘// TODO add your handling code here’

System.exit(0);

 

OUTPUT:

Leave a Reply

Your email address will not be published. Required fields are marked *