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
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
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 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
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
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
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
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
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
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
add tow numbers with out using arthamatic operaters
add tow numbers with out using arthamatic operaters  add tow numbers with out using arthamatic operaters
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
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
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
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
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
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
Applet
Applet  Write an applet to display a string in an applet. String should be passed as a parameter to an applet
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
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
applet
applet  applet to open new tab not working.here's my code import...*; public class NewURL extends Applet implements ActionListener{ public void init...); b.addActionListener(this); add(b); } public void actionPerformed
Applet
Applet  Explain the start() and stop() methods of applet life cycle.   Start and Start method of Applet Life Cycle Start () method: The start method of an applet is called after the initialization method init
Applet
Applet  Write a short note on applet life cycle
Applet
Applet  I have a java applet that has a button. On clicking the button it should disappear and another applet should appear. How to write this code???? Also in login applet after successful login it should display admin applet
Applet
Applet  Draw the class hierarchy of an Applet class. Also explain how to set background and forground colors in java
applet
applet  what is applet in java   An applet is a small program that can be sent along with a Web page to a user. Java applets can perform... the following link: Applet Tutorials
Swap two numbers without using third variable
Swap two numbers without using third variable In this section we are going to swap two variables without using the third variable. For this, we have used... arithmetic operations like we have added both the numbers and stored
Applet
Applet  Write a Java applet that drwas a line between 2 points. The co-ordinates of 2 points should be passed as parametrs from html file. The color of the line should be red

Ads