Skip to main content

FEATURED POST

Why the World is Running Out of Computers

Write a code to create a page which will be able to do the following task:  ADD  SUBTRACT  MULTIPLY  DIVIDE

 Write a code to create a page which will be able to do the following task:
Ø ADD
Ø SUBTRACT
Ø MULTIPLY
Ø DIVIDE                                                           

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

public  class Calculator extends Applet implements ActionListener

{                                                 

Label l1,l2;

TextField t1,t2,t3;

    Button add1,sub,mul,div;

    public void init()

    {

        l1=new Label("First No");

        add(l1);

        t1=new TextField(10);

        add(t1);

        l2=new Label("Second No");

        add(l2);

        t2=new TextField(10);

        add(t2);

        add1=new Button("+");

        add(add1);

        add1.addActionListener(this);

        sub=new Button("-")

add(sub);

\        sub.addActionListener(this);

mul=new Button("*");

add(mul);

mul.addActionListener(this);

        div=new Button("/");

        add(div);

div.addActionListener(this);

        t3=new TextField(20);

        add(t3);

    }

    public void actionPerformed(ActionEvent e)

    {

        if(e.getSource()==add1)

        {

            int sum=Integer.parseInt(t1.getText())+Integer.parseInt(t2.getText());

            t3.setText(String.valueOf(sum));

        }

        if(e.getSource()==sub)

        {

            int sum=Integer.parseInt(t1.getText())-Integer.parseInt(t2.getText());

            t3.setText(String.valueOf(sum));

        }

        if(e.getSource()==mul)

        {

            int sum=Integer.parseInt(t1.getText())*Integer.parseInt(t2.getText());

            t3.setText(String.valueOf(sum));

        }

        if(e.getSource()==div)

        {

            int sum=Integer.parseInt(t1.getText())/Integer.parseInt(t2.getText());

            t3.setText(String.valueOf(sum));

        }

    }

}                                                                                                                                                                                                                                            /*<applet code=Calculator.class WIDTH=300 HEIGHT=200>

</applet> */

#java applet#applet programming in java

#creating applet in java



                                                                                                                                                                                                                       



Comments

Popular Posts

Question: Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes

Question: Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes:  Ø “Car” that inherits “Vehicle” and also stores number of passengers.  Ø “Truck” that inherits “Vehicle” and also stores the load limit.  Write a main() function to create objects of these classes and display all the information about Car and Truck. Also, compare the speed of the two vehicles, Car and Truck and display “faster” or “slower” if Car is faster or slower than Truck. import java.util.*; class Vehicle{   int wheels;   double speed; } class Car extends Vehicle{   int pass;   void input(){    Scanner sc=new Scanner(System.in); System.out.println("Enter the car's details:\nNo. of wheels:");    wheels=sc.nextInt(); System.out.println("Speed of Car(Km/hr):");    speed=sc.nextDouble(); System.out.println("No. of passengers:");   ...

Question: Write a java program that implements bank transactions using user defined exception.

Question: Write a java program that implements bank transactions using user defined exception. import java.util.*; class UDE{     public static void main(String ts7[]) throws MinimumBal {         Scanner sc= new Scanner(System.in);         double bal; System.out.println("Enter current balance:"); bal=sc.nextDouble(); System.out.println("Enter amount to withdrawal");         int n = sc.nextInt();         try {             if (bal<n)                   throw new MinimumBal("Account ae taka nei bhai !\nYour Current balance is "+bal);             else      System.out.print...

How to view hidden files in computer?

It is very easy to see hidden files or folders in a Windows computer. In this answer, I will show you how to hidden files as well as how to hide a file or folder. So let's understand step-by-step How to hide a file or folder: Step 1 : Select any file (or folder) you want to hide by clicking once on the icon of that folder.                                                                     Safe Online - सेफ ऑनलाइन Step 2: Now right-click it on the folder and click on 'Properties' at the bottom of the menu which is open. To open the properties of a folder, you can also select the folder and use the shortcut Alt + Enter.                                                 ...