Advertisement
plantbae

awt

Oct 10th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. package operacionesad;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class Operacionesad
  6. {
  7. Label L1,L2,L3;
  8. Button B1,B2, B3, B4;
  9. TextField T1, T2, T3;
  10. Frame F1;
  11.  
  12. public void c1 ()
  13. {
  14. L1= new Label ("Número 1");
  15. L2= new Label ("Número 2");
  16. L3= new Label ("Resultado");
  17. T1= new TextField (20);
  18. T2= new TextField (20);
  19. T3= new TextField (20);
  20.  
  21. // Botón de sumar
  22. B1= new Button ("+");
  23. B1.addActionListener(new ActionListener()
  24. {
  25. public void actionPerformed(ActionEvent e)
  26. {
  27. suma ();
  28. }
  29. });
  30.  
  31. //Botón de restar
  32. B2= new Button ("-");
  33. B2.addActionListener(new ActionListener()
  34. {
  35. public void actionPerformed(ActionEvent e)
  36. {
  37. resta ();
  38. }
  39. });
  40.  
  41. //Botón de multiplicar
  42. B3= new Button ("*");
  43. B3.addActionListener(new ActionListener()
  44. {
  45. public void actionPerformed(ActionEvent e)
  46. {
  47. multi ();
  48. }
  49. });
  50.  
  51. //Botón de dividir
  52. B4= new Button ("/");
  53. B4.addActionListener(new ActionListener()
  54. {
  55. public void actionPerformed(ActionEvent e)
  56. {
  57. div ();
  58. }
  59. });
  60.  
  61. F1= new Frame ("Operaciones");
  62.  
  63. //Display
  64. F1.add(L1);
  65. F1.add(T1);
  66. F1.add(L2);
  67. F1.add(T2);
  68. F1.add(B1);
  69. F1.add(B2);
  70. F1.add(B3);
  71. F1.add(B4);
  72. F1.add(T3);
  73.  
  74.  
  75. F1.show();
  76. F1.setLayout(new FlowLayout ());
  77. F1.setSize(260, 150);
  78. F1.setResizable(false);
  79. }
  80.  
  81. public void suma ()
  82. {
  83. String TT1, TT2, TT3;
  84. double a, b, c;
  85. //
  86. a= Double.parseDouble(TT1= T1.getText());
  87. b= Double.parseDouble(TT2= T2.getText());
  88. c= a+b;
  89. TT3= Double.toString(c);
  90. T3.setText(TT3);
  91. }
  92.  
  93. public void resta ()
  94. {
  95. String TT1, TT2, TT3;
  96. double a, b, c;
  97. //
  98. a= Double.parseDouble(TT1= T1.getText());
  99. b= Double.parseDouble(TT2= T2.getText());
  100. c= a-b;
  101. TT3= Double.toString(c);
  102. T3.setText(TT3);
  103. }
  104.  
  105. public void multi ()
  106. {
  107. String TT1, TT2, TT3;
  108. double a, b, c;
  109. //
  110. a= Double.parseDouble(TT1= T1.getText());
  111. b= Double.parseDouble(TT2= T2.getText());
  112. c= a*b;
  113. TT3= Double.toString(c);
  114. T3.setText(TT3);
  115. }
  116.  
  117. public void div ()
  118. {
  119. String TT1, TT2, TT3;
  120. double a, b, c;
  121. //
  122. a= Double.parseDouble(TT1= T1.getText());
  123. b= Double.parseDouble(TT2= T2.getText());
  124. c= a/b;
  125. TT3= Double.toString(c);
  126. T3.setText(TT3);
  127. }
  128.  
  129. public static void main(String[] args)
  130. {
  131. Operacionesad n=new Operacionesad();
  132. n.c1();
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement