Applet for add two numbers

Applet for add two numbers

what is the java applet code for add two numbers?

View Answers

April 18, 2011 at 2:35 PM

import java.awt.Graphics;

import javax.swing.*;

public class AddApplet extends JApplet {

int sum;

int x;

int y;

public void init() {

String num1;

String num2;

// read first number from the keyboard

num1 = JOptionPane.showInputDialog("Enter a First number");

// read seond number from the ketboard

num2 = JOptionPane.showInputDialog("Enter a Second number");

x= Integer.parseInt(num1); // comvert the string to an integer

y= Integer.parseInt(num2); // convert the string to an integer

sum = x + y;

}

public void paint(Graphics g) {

//writes the output in the applet starting at position 30, 30

g.drawString("The sum of x ("+x+") +y ("+y+")="+sum, 30,30);

}

}


April 18, 2011 at 3:23 PM

1)AppletSum.java:

  import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;

    public class AppletSum extends Applet implements ActionListener{
      TextField text1,text2,output;
      Label label1,label2,label3;
      Button button;
      public void init(){
        setLayout(null);
        label1 = new Label("Enter Number1: ");
        label1.setBounds(20,20,100,20);
        add(label1);

        text1 = new TextField(5);
        text1.setBounds(150,20,100,20);
        add(text1);

        label2 = new Label("Enter Number2: ");
        label2.setBounds(20,50,100,20);
        add(label2);

        text2 = new TextField(5);
        text2.setBounds(150,50,100,20);
        add(text2);

        label3 = new Label("Sum of Two Numbers: ");
        label3.setBounds(20,80,130,20);
        add(label3);

        output = new TextField(5);
        output.setBounds(150,80,100,20);
        add(output);

        button = new Button("Sum");
        button.setBounds(150,110,100,20);
        add(button);

        button.addActionListener(this);
        }
        public void actionPerformed(ActionEvent ae){
        int num1=Integer.parseInt(text1.getText());
        int num2=Integer.parseInt(text2.getText());
        int sum=num1+num2;
        output.setText(Integer.toString(sum));
        }
    }

2)applet.html:

<HTML>
<BODY>
<APPLET ALIGN="CENTER" CODE="AppletSum.class" width = "700" height = "400"></APPLET>
</BODY>
</HTML>









Related Tutorials/Questions & Answers:
Applet for add two numbers
Applet for add two numbers  what is the java applet code for add two numbers?   import java.awt.Graphics; import javax.swing.*; public...); add(text2); label3 = new Label("Sum of Two Numbers
Add two big numbers
Add two big numbers       In this section, you will learn how to add two big numbers...(BigDecimal big): This method is used to add the two BigDecimal numbers. Here
Advertisements
How to add two numbers in Java?
How to add two numbers in a Java program? In Java you can easily add two number by using the plus (+) operator. The plus operator will add two... this will print: Sum is: 30 So, in this program you learned how to sum(add) two numbers
Add two big numbers - Java Beginners
Add two big numbers - Java Beginners  Hi, I am beginner in Java and leaned basic concepts of Java. Now I am trying to find example code for adding big numbers in Java. I need basic Java Beginners example. It should easy
Add Two Numbers in Java
Add Two Numbers in Java     ... Addition of two numbers! Sum: 32... these arguments and print the addition of those numbers. In this example, args
Addition of two numbers
Addition of two numbers  addition of two numbers
JavaScript determine add, product of two numbers
JavaScript determine add, product of two numbers In this section, you... numbers. To find this, we have created two textboxes and four button...("Sum of two numbers is: "+sum); } function divide
Add two number in java
Add two number in java In this section you will learn about how to add two... be added, So two add,  convert these String into numeric type..."); System.out.println("Please Enter two number to add :"); Scanner sin=new
how to add to numbers in java
how to add to numbers in java  how to add to numbers in java
Adding two numbers
Adding two numbers  Accepting value ffrom the keyboard and adding two numbers
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi... the numbers. Check the tutorial Write a program to list all even numbers between two
ModuleNotFoundError: No module named 'add_numbers'
ModuleNotFoundError: No module named 'add_numbers'  Hi, My Python... 'add_numbers' How to remove the ModuleNotFoundError: No module named 'add_numbers' error? Thanks   Hi, In your python environment
adding of two numbers in designing of frame
adding of two numbers in designing of frame  hello sir, now i'm create two textfield for mark1&mark2 from db.how to add these two numbers in another one text field.how to write a coding... if u have another one idea pls
adding two numbers with out using any operator
adding two numbers with out using any operator  how to add two numbers with out using any operator   import java.math.*; class AddNumbers { public static void main(String[] args) { BigInteger num1=new
mysql difference between two numbers
mysql difference between two numbers  How to get total bate difference between two dates for example 1/01/2012 and 1/02/2012 in MYSQL?   ... between two date. The syntax of DATEDIFF is .. SELECT DATEDIFF('2012-01-31 23:59
To find first two maximum numbers in an array
To find first two maximum numbers in an array  Java program to find first two maximum numbers in an array,using single loop without sorting array
adding two numbers - Java Beginners
adding two numbers  hii friends....... this is my program...]=Integer.parseInt(in.readLine()); int s=x[1]+y[1]; System.out.println("Sum of two...]; System.out.println("Sum of two no. is:"+s); } } For read more
add tow numbers with out using arthamatic operaters
add tow numbers with out using arthamatic operaters  add tow numbers with out using arthamatic operaters
Add Complex Numbers Java
How to Add Complex Numbers Java In this Java tutorial section, you will learn how to add complex Numbers in Java Programming Language. As you are already aware of Complex numbers. It is composed of two part - a real part and an imaginary
adding two numbers using bitwise operators
adding two numbers using bitwise operators  adding two integer numbers with using bitwise opeators   Hi Friend, Try the following code: public class AddNumberUsingBitwiseOperators { public static void main(String
how to add database in Java Applet
to add database in Java Applet below this code is my applet source code . thank...how to add database in Java Applet  hi every java master or Java... Applet implements ActionListener{ TextField
Two user chess game - Applet
Two user chess game  Write a program for a two user chess game(Users must be on different systems)? please send me this source code to my mail id with step by step explanation
Generate random number between two numbers in Scala
Generate random number between two numbers in Scala  Hi, How to Generate random number between two numbers in Scala? Thanks   Hi, Following code can be used for generating random number in scala: val rand = new
Generate random number between two numbers in Scala
Generate random number between two numbers in Scala  Hi, How to Generate random number between two numbers in Scala? Thanks   Hi, Following code can be used for generating random number in scala: val rand = new
Comparing Two Numbers
Comparing Two Numbers      ... of comparing two numbers and finding out the greater one. First of all, name a class "Comparing" and take two numbers in this class. Here we have taken a=24
Write a program to list all even numbers between two numbers
Write a program to list all even numbers between two numbers       Java Even Numbers - Even... all the even numbers between two numbers. For this first create a class named
Swapping of two numbers
Swapping of two numbers      ... program to calculate swap of two numbers. Swapping is used where  you want... ability. In this program we will see how we can swap two numbers. We can do
Sum of two numbers using command line arguments in Java
sum = a+b; Check complete example code at Add Two Numbers in Java. Thanks...Sum of two numbers using command line arguments in Java  Hi, How...? The calculate the sum of two numbers using command line arguments in Java
Swapping of two numbers in java
Swapping of two numbers in java In this example we are going to describe swapping of two numbers in java  without using the third number in java. We... values from the command prompt. The swapping of two numbers is based on simple
How to add dropdown list in a row of a sort table applet?
How to add dropdown list in a row of a sort table applet?  How to add dropdown list in a row of a sort table applet
Swapping of two numbers without using third variable
Swapping of two numbers without using third variable In this tutorial we will learn about swapping of two number in java without using third variable. This is simple program to swap two value using arithmetic operation Swapping of two
python merge two dictionaries add values
python merge two dictionaries add values  Hi, In Python I have two dictionaries with same keys. I want to merge the two dictionaries and add the values (int values) into the merged dictionary. For example student marks in three
How to add two calendars on the same html page
How to add two calendars on the same html page  I have used the same code as on this site http://www.roseindia.net/javascript/javascript... use single calendar for a single html page.but while implementing two calendars
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
add
How to add two int numbers in Java Example  How to add two int numbers in Java Example  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new column in table before two column in sql.   Syntax of Alter table: ALTER... named 'employee' having three fields id, name and salary. Now we want to add two
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new column in table before two column in sql.   Syntax of Alter table: ALTER... named 'employee' having three fields id, name and salary. Now we want to add two
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new column in table before two column in sql.   Syntax of Alter table: ALTER... named 'employee' having three fields id, name and salary. Now we want to add two
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new column in table before two column in sql.   Syntax of Alter table: ALTER... named 'employee' having three fields id, name and salary. Now we want to add two
How can you add elements of two arrayLists in java?
How can you add elements of two arrayLists in java?  if you have an arrayList of tempArr = [hi, my, name, is, john] and another arrayList of tempArray2 = [a, b, c, d, e] and you want it to result in newArr = [hi a, my b, name c
Find L.C.M. of two numbers in Java
Find L.C.M. of two numbers in Java Program In this section, you will learn how to find LCM(Least Common Element) of two integers.The least common multiple is the smallest positive integer that is a multiple of both the numbers. Here we
add
How to add two numbers in Java  add two number   Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers { public static void main(String[] args
how to add two object in a particular file - Java Beginners
how to add two object in a particular file  Hi frend.. I have two arraylist object in which there is some data..............now i want to add these two objects in a particular file using file handling in java....and also
Applet
Applet  Write an applet to display a string in an applet. String should be passed as a parameter to an applet
applet
applet  What is the immediate superclass of the Applet class
Applet
Applet  how to run an applet on a web browser
applet
applet  Explain different stages in the lifecycle of an applet with figure.   Stages of Applet: Life cycle of an Applet: init(): This method is called to initialized an applet start(): This method is called after
Applet
Applet  Give the class hierarchy of an Applet class
Applet
Applet  Write a ava applet that sets blue color foreground and yellow color background at the start of an applet

Ads