0% found this document useful (0 votes)
2 views

calculator and facorial program using event handling

The document contains two Java applet classes: 'factorial_event' for calculating the factorial of a number and 'calculator_event' for performing basic arithmetic operations (addition, subtraction, multiplication, and division). Each applet uses a graphical user interface with text fields for input and buttons for triggering calculations. The results are displayed in the applet interface after the user interacts with the buttons.

Uploaded by

ps3639944
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

calculator and facorial program using event handling

The document contains two Java applet classes: 'factorial_event' for calculating the factorial of a number and 'calculator_event' for performing basic arithmetic operations (addition, subtraction, multiplication, and division). Each applet uses a graphical user interface with text fields for input and buttons for triggering calculations. The results are displayed in the applet interface after the user interacts with the buttons.

Uploaded by

ps3639944
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

import java.awt.

*;

import java.applet.*;

import java.awt.event.*;

public class factorial_event extends Applet implements ActionListener

TextField t1,t2;

Label l1,l2;

Button b1,b2;

public void init()

setLayout(new GridLayout(3,2));

l1=new Label("enter no");

l2=new Label("FACTORIAL");

t1=new TextField(15);

t2=new TextField(15);

b1=new Button("FACT");

add(l1);add(t1);

add(l2);add(t2);

add(b1);

b1.addActionListener(this);

public void actionPerformed(ActionEvent ae)

int no;

int n=Integer.parseInt(t1.getText());
//if(ae.getSource()==b1)

//{

int fact=1;

for(int i=1;i<=n;i++)

fact=fact*i;

t2.setText(Integer.toString(fact));

//}

/*<applet code=factorial_event width=200 height=200>

</applet>*/

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

public class calculator_event extends Applet implements ActionListener

TextField t1,t2,t3;

Label l1,l2,l3;

Button b1,b2,b3,b4;

public void init()


{

setLayout(new GridLayout(5,2));

l1=new Label("enter no1");

l2=new Label("enter no2");

l3=new Label();

t1=new TextField(15);

t2=new TextField(15);

t3=new TextField(15);

b1=new Button("ADD");

b2=new Button("SUB");

b3=new Button("MUL");

b4=new Button("DIV");

add(l1);add(t1);

add(l2);add(t2);

add(l3);add(t3);

add(b1);add(b2);add(b3);add(b4);

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

b4.addActionListener(this);

public void actionPerformed(ActionEvent ae)

int no;

int n1=Integer.parseInt(t1.getText());
int n2=Integer.parseInt(t2.getText());

if(ae.getSource()==b1)

{int add=n1+n2;

l3.setText("addition");

t3.setText(Integer.toString(add));

if(ae.getSource()==b2)

{int sub=n1-n2;

l3.setText("substration");

t3.setText(Integer.toString(sub));

if(ae.getSource()==b3)

{int mul=n1*n2;

l3.setText("multi");

t3.setText(Integer.toString(mul));

if(ae.getSource()==b4)

{int div=n1/n2;

l3.setText("division");

t3.setText(Integer.toString(div));

}}}

/*<applet code=calculator_event width=200 height=200>

</applet>*/

You might also like