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...

Question: Develop an abstract class “GeometricObject” which will have two variables colourand weight. It would have constructor function for setting the colour as “white” and the weight as 1.0 as default values. The class should have methods getColour() and getWeight() to return the colour and weight values to the caller. The class should have two abstract methods findArea() and findCircumference(). Write a subclass for “GeometricObject” called “Triangle” which will be able to calculate area and circumference for a triangle.

Question: Develop an abstract class “GeometricObject” which will have two variables colourand weight. It would have constructor function for setting the colour as “white” and the weight as 1.0 as default values. The class should have methods getColour() and getWeight() to return the colour and weight values to the caller. The class should have two abstract methods findArea() and findCircumference().  Write a subclass for “GeometricObject” called “Triangle” which will be able to calculate area and circumference for a triangle. import java.util.*; import java.math.*; abstract class GeometricObject {             String colour;             double weight;             public GeometricObject()             {      ...