Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 whole number");
- // read seond number from the ketboard
- num2 = JOptionPane.showInputDialog("Enter a whole 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 ot x (="+x+")+y(="+y+")="+sum, 30,30);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement