Advertisement
everblut

Untitled

Aug 20th, 2011
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.25 KB | None | 0 0
  1. import java.awt.*;
  2. import java.applet.*;
  3. import java.awt.event.*;
  4. public class Main extends Applet implements ActionListener {
  5. Label l1, l2,l3;
  6. TextField t1,t2,t3;
  7. Button b1,b2,b3,b4,b5,b6,b7,b8;
  8. public Main () {
  9. l1 = new Label("Numero 1");
  10. t1 = new TextField(8);
  11. l2 = new Label("Numero 2");
  12. t2 = new TextField(8);
  13. b1 = new Button("Suma");
  14. b2 = new Button("Resta");
  15. b3 = new Button("Multiplica");
  16. b4 = new Button("Divide");
  17. b5 = new Button("Raiz de 1");
  18. b6 = new Button("Raiz de 2");
  19. b7 = new Button("Mayor");
  20. b8 = new Button("Limpia");
  21. l3 = new Label("Resultado");
  22. t3 = new TextField(8);
  23. add(l1);
  24. add(t1);
  25. add(l2);
  26. add(t2);
  27. add(b1);
  28. add(b2);
  29. add(b3);
  30. add(b4);
  31. add(b5);
  32. add(b6);
  33. add(b7);
  34. add(b8);
  35. add(l3);
  36. add(t3);
  37. b1. addActionListener(this);
  38. b2. addActionListener(this);
  39. b3. addActionListener(this);
  40. b4. addActionListener(this);
  41. b5. addActionListener(this);
  42. b6. addActionListener(this);
  43. b7. addActionListener(this);
  44. b8. addActionListener(this);
  45. }
  46. public void actionPerformed(ActionEvent ae) {
  47. if (ae.getSource() == b1) {
  48. int n1 = Integer.parseInt(t1.getText());
  49. int n2 = Integer.parseInt(t2.getText());
  50. int suma = 0;
  51. suma = n1 + n2;
  52. t3.setText("" + suma);
  53. }
  54. if (ae.getSource() == b2) {
  55. int n1 = Integer.parseInt(t1.getText());
  56. int n2 = Integer.parseInt(t2.getText());
  57. int resta = 0;
  58. resta = n2 - n1;
  59. t3.setText("" + resta);
  60. }
  61. if (ae.getSource() == b3) {
  62. int n1 = Integer.parseInt(t1.getText());
  63. int n2 = Integer.parseInt(t2.getText());
  64. int multi = 0;
  65. multi = n1 * n2;
  66. t3.setText("" + multi);
  67. }
  68. if (ae.getSource() == b4) {
  69. int n1 = Integer.parseInt(t1.getText());
  70. int n2 = Integer.parseInt(t2.getText());
  71. int div = 0;
  72. div = n1 / n2;
  73. t3.setText("" + div);
  74. }
  75. if (ae.getSource() == b5) {
  76. int n1 = Integer.parseInt(t1.getText());
  77. double raiz = 0;
  78. raiz = Math.sqrt(n1);
  79. t3.setText("" + raiz);
  80. }
  81. if (ae.getSource() == b6) {
  82. int n2 = Integer.parseInt(t2.getText());
  83. double raiz = 0;
  84. raiz = Math.sqrt(n2);
  85. t3.setText("" + raiz);
  86. }
  87. if (ae.getSource() == b7) {
  88. int n1 = Integer.parseInt(t1.getText());
  89. int n2 = Integer.parseInt(t2.getText());
  90. int mayor = 0;
  91. if (n1 > n2)
  92. mayor = n1;
  93. else
  94. mayor = n2;
  95. t3.setText("" + mayor);
  96. }
  97. if (ae.getSource() == b8) {
  98. t1.setText("");
  99. t2.setText("");
  100. t3.setText("");
  101. }
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement