Advertisement
Codex

AddApplet

Jul 2nd, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.awt.Graphics;
  2. import javax.swing.*;
  3. public class AddApplet extends JApplet
  4. {
  5. int sum;
  6. int x;
  7. int y;
  8. public void init()
  9. {
  10. String num1;
  11. String num2;
  12. // read first number from the keyboard
  13. num1 = JOptionPane.showInputDialog("Enter a whole number");
  14. // read seond number from the ketboard
  15. num2 = JOptionPane.showInputDialog("Enter a whole number");
  16. x= Integer.parseInt(num1); // comvert the string to an integer
  17. y= Integer.parseInt(num2); // convert the string to an integer
  18. sum = x + y;
  19. }
  20. public void paint(Graphics g)
  21. {
  22. //writes the output in the applet starting at position 30, 30
  23. g.drawString("the sum ot x (="+x+")+y(="+y+")="+sum, 30,30);
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement