Java Awt

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

Calculator using

javaAWT
BY-
RUSHIKESH PADIR
HEMANT PATIL
AMEYA PATIL
• Elements used in this application are as follows :
1. Buttons(b1,...,b17)
2. Text field(tf)
3. Panel (p)
4. Frame(f)
Methods used

 addActionlistener-(inherited from Action Listener class)


 Action Performed-In this method ,coding for operation is
to be done()
Steps

1. Declare objects for layout, panel ,frame ,button( Frame f; Button b1)
2.Define the content of buttons and give them attribute(font ,background)
3.Adding buttons to panel and panel &text field to
frame( f.setBackground(Color.GRAY);
4.Define Actionperformed to execute the operation of button on clicking( if(e.getSource()==b1)
{
s3 = tf.getText();
s4 = "0";
s5 = s3+s4;
tf.setText(s5);
}
if(e.getSource()==b12)
{
s1 = tf.getText();
tf.setText("");
c=2;

} {
s2 = tf.getText();
if(c==1)
{
n = Integer.parseInt(s1)+Integer.parseInt(s2);
tf.setText(String.valueOf(n));
}
else
if(c==2)
{
n = Integer.parseInt(s1)-Integer.parseInt(s2);
tf.setText(String.valueOf(n));
}
Exception Handling
• In this program Try catch exception handling is used to avoid Arithmetic exception :/by zero
• try
• {
• int p=Integer.parseInt(s2);
• if(p!=0)
• {
• n = Integer.parseInt(s1)/Integer.parseInt(s2);
• tf.setText(String.valueOf(n));
• }
• else
• tf.setText("infinite");

• }
• catch(Exception i){}
• }

You might also like