Advertisement
Guest User

deber calculadora

a guest
Apr 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.13 KB | None | 0 0
  1. package clase1004;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.EventQueue;
  5.  
  6. import javax.swing.JFrame;
  7. import javax.swing.JPanel;
  8. import javax.swing.border.EmptyBorder;
  9. import javax.swing.JLabel;
  10. import javax.swing.JOptionPane;
  11.  
  12. import java.awt.Font;
  13. import java.awt.Color;
  14. import javax.swing.JTextField;
  15. import java.awt.event.MouseAdapter;
  16. import java.awt.event.MouseEvent;
  17. import javax.swing.JButton;
  18. import javax.swing.border.BevelBorder;
  19. import javax.swing.border.LineBorder;
  20. import javax.swing.ImageIcon;
  21. import java.awt.event.ActionListener;
  22. import java.awt.event.ActionEvent;
  23.  
  24. public class calcuxx extends JFrame {
  25.  
  26. private JPanel contentPane;
  27. private JTextField txtIngresePrimercalcuxxndo;
  28. private JTextField txtIngreseSegundocalcuxxndo;
  29. private JLabel lblResultado;
  30.  
  31. /**
  32. * Launch the application.
  33. */
  34. public static void main(String[] args) {
  35. EventQueue.invokeLater(new Runnable() {
  36. public void run() {
  37. try {
  38. calcuxx frame = new calcuxx();
  39. frame.setVisible(true);
  40. } catch (Exception e) {
  41. e.printStackTrace();
  42. }
  43. }
  44. });
  45. }
  46.  
  47. /**
  48. * Create the frame.
  49. */
  50. public calcuxx() {
  51. setResizable(false);
  52. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  53. setBounds(100, 100, 868, 544);
  54. contentPane = new JPanel();
  55. contentPane.setBackground(new Color(169, 169, 169));
  56. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  57. setContentPane(contentPane);
  58. contentPane.setLayout(null);
  59.  
  60. JLabel lblBienvenidoALa = new JLabel("Bienvenido a la calculadora");
  61. lblBienvenidoALa.setForeground(new Color(75, 0, 130));
  62. lblBienvenidoALa.setFont(new Font("Viner Hand ITC", Font.PLAIN, 25));
  63. lblBienvenidoALa.setBounds(252, 32,7924, 89);
  64. contentPane.add(lblBienvenidoALa);
  65.  
  66. txtIngresePrimercalcuxxndo = new JTextField();
  67. txtIngresePrimercalcuxxndo.setBorder(new LineBorder(new Color(255, 0, 255), 4));
  68. txtIngresePrimercalcuxxndo.addMouseListener(new MouseAdapter() {
  69. @Override
  70. public void mouseClicked(MouseEvent arg0) {
  71. txtIngresePrimercalcuxxndo.setText("");
  72. }
  73. });
  74. txtIngresePrimercalcuxxndo.setText("Ingrese primer termino");
  75. txtIngresePrimercalcuxxndo.setBounds(58, 158, 228, 35);
  76. contentPane.add(txtIngresePrimercalcuxxndo);
  77. txtIngresePrimercalcuxxndo.setColumns(10);
  78.  
  79. txtIngreseSegundocalcuxxndo = new JTextField();
  80. txtIngreseSegundocalcuxxndo.setBorder(new LineBorder(new Color(255, 0, 255), 4));
  81. txtIngreseSegundocalcuxxndo.addMouseListener(new MouseAdapter() {
  82. @Override
  83. public void mouseClicked(MouseEvent e) {
  84. txtIngreseSegundocalcuxxndo.setText("");
  85. }
  86. });
  87. txtIngreseSegundocalcuxxndo.setText("Ingrese segundo termino");
  88. txtIngreseSegundocalcuxxndo.setColumns(10);
  89. txtIngreseSegundocalcuxxndo.setBounds(58, 221, 228, 35);
  90. contentPane.add(txtIngreseSegundocalcuxxndo);
  91.  
  92.  
  93.  
  94. lblResultado = new JLabel("");
  95. lblResultado.setFont(new Font("Nyala", Font.PLAIN, 23));
  96. lblResultado.setBounds(564, 197, 322, 78);
  97. contentPane.add(lblResultado);
  98.  
  99. JButton botonsuma = new JButton("SUMAR");
  100. botonsuma.addActionListener(new ActionListener() {
  101. public void actionPerformed(ActionEvent arg0) {
  102. try {
  103. lblResultado.setText(String.valueOf(Integer.parseInt(txtIngresePrimercalcuxxndo.getText())+Integer.parseInt(txtIngreseSegundocalcuxxndo.getText())));
  104.  
  105. } catch (java.lang.NumberFormatException coscu) {
  106. // TODO: handle exception
  107.  
  108. if(txtIngresePrimercalcuxxndo.getText().isEmpty()) {
  109. JOptionPane.showMessageDialog(null, "error tabacio el 1");
  110. txtIngresePrimercalcuxxndo.requestFocus();
  111. }else if(txtIngreseSegundocalcuxxndo.getText().isEmpty()) {
  112. JOptionPane.showMessageDialog(null, "error tabacio el 2");
  113. txtIngreseSegundocalcuxxndo.requestFocus();
  114. }else {
  115. if(!txtIngresePrimercalcuxxndo.getText().matches("[0-9]+")) {
  116. JOptionPane.showMessageDialog(null, "caracteres invalidos en el 1");
  117. txtIngresePrimercalcuxxndo.requestFocus();
  118. txtIngresePrimercalcuxxndo.setText("");
  119.  
  120. }
  121. else if(!txtIngreseSegundocalcuxxndo.getText().matches("[0-9]+")) {
  122. JOptionPane.showMessageDialog(null, "caracteres invalidos en el 2");
  123. txtIngreseSegundocalcuxxndo.setText("");
  124. txtIngreseSegundocalcuxxndo.requestFocus();
  125. }
  126. }
  127.  
  128. }
  129.  
  130. }
  131. });
  132. botonsuma.setIcon(new ImageIcon("C:\\Users\\aVA\\Desktop\\Captura.PNG"));
  133. botonsuma.setBounds(543, 113, 80, 35);
  134. contentPane.add(botonsuma);
  135.  
  136. JButton botondivision = new JButton("DIVIDIR");
  137. botondivision.addActionListener(new ActionListener() {
  138. public void actionPerformed(ActionEvent e) {
  139. try {
  140. lblResultado.setText(String.valueOf(Integer.parseInt(txtIngresePrimercalcuxxndo.getText())/Integer.parseInt(txtIngreseSegundocalcuxxndo.getText())));
  141.  
  142. } catch (java.lang.NumberFormatException coscu) {
  143. // TODO: handle exception
  144.  
  145. if(txtIngresePrimercalcuxxndo.getText().isEmpty()) {
  146. JOptionPane.showMessageDialog(null, "error tabacio el 1");
  147. txtIngresePrimercalcuxxndo.requestFocus();
  148. }else if(txtIngreseSegundocalcuxxndo.getText().isEmpty()) {
  149. JOptionPane.showMessageDialog(null, "error tabacio el 2");
  150. txtIngreseSegundocalcuxxndo.requestFocus();
  151. }else {
  152. if(!txtIngresePrimercalcuxxndo.getText().matches("[0-9]+")) {
  153. JOptionPane.showMessageDialog(null, "caracteres invalidos en el 1");
  154. txtIngresePrimercalcuxxndo.requestFocus();
  155. txtIngresePrimercalcuxxndo.setText("");
  156.  
  157. }
  158. else if(!txtIngreseSegundocalcuxxndo.getText().matches("[0-9]+")) {
  159. JOptionPane.showMessageDialog(null, "caracteres invalidos en el 2");
  160. txtIngreseSegundocalcuxxndo.setText("");
  161. txtIngreseSegundocalcuxxndo.requestFocus();
  162. }
  163. }
  164.  
  165. }
  166. }
  167. });
  168. botondivision.setBounds(543, 158, 80, 35);
  169. contentPane.add(botondivision);
  170.  
  171. JButton botonresta = new JButton("RESTAR");
  172. botonresta.addActionListener(new ActionListener() {
  173. public void actionPerformed(ActionEvent e) {
  174. ////
  175. try {
  176. lblResultado.setText(String.valueOf(Integer.parseInt(txtIngresePrimercalcuxxndo.getText())-Integer.parseInt(txtIngreseSegundocalcuxxndo.getText())));
  177.  
  178. } catch (java.lang.NumberFormatException coscu) {
  179. // TODO: handle exception
  180.  
  181. if(txtIngresePrimercalcuxxndo.getText().isEmpty()) {
  182. JOptionPane.showMessageDialog(null, "error tabacio el 1");
  183. txtIngresePrimercalcuxxndo.requestFocus();
  184. }else if(txtIngreseSegundocalcuxxndo.getText().isEmpty()) {
  185. JOptionPane.showMessageDialog(null, "error tabacio el 2");
  186. txtIngreseSegundocalcuxxndo.requestFocus();
  187. }else {
  188. if(!txtIngresePrimercalcuxxndo.getText().matches("[0-9]+")) {
  189. JOptionPane.showMessageDialog(null, "caracteres invalidos en el 1");
  190. txtIngresePrimercalcuxxndo.requestFocus();
  191. txtIngresePrimercalcuxxndo.setText("");
  192.  
  193. }
  194. else if(!txtIngreseSegundocalcuxxndo.getText().matches("[0-9]+")) {
  195. JOptionPane.showMessageDialog(null, "caracteres invalidos en el 2");
  196. txtIngreseSegundocalcuxxndo.setText("");
  197. txtIngreseSegundocalcuxxndo.requestFocus();
  198. }
  199. }
  200.  
  201. }
  202.  
  203. }
  204. });
  205. botonresta.setBounds(453, 113, 80, 35);
  206. contentPane.add(botonresta);
  207.  
  208. JButton botonmult = new JButton("MULTIPLICAR");
  209. botonmult.addActionListener(new ActionListener() {
  210. public void actionPerformed(ActionEvent e) {
  211. try {
  212. lblResultado.setText(String.valueOf(Integer.parseInt(txtIngresePrimercalcuxxndo.getText())*Integer.parseInt(txtIngreseSegundocalcuxxndo.getText())));
  213.  
  214. } catch (java.lang.NumberFormatException coscu) {
  215. // TODO: handle exception
  216.  
  217. if(txtIngresePrimercalcuxxndo.getText().isEmpty()) {
  218. JOptionPane.showMessageDialog(null, "error tabacio el 1");
  219. txtIngresePrimercalcuxxndo.requestFocus();
  220. }else if(txtIngreseSegundocalcuxxndo.getText().isEmpty()) {
  221. JOptionPane.showMessageDialog(null, "error tabacio el 2");
  222. txtIngreseSegundocalcuxxndo.requestFocus();
  223. }else {
  224. if(!txtIngresePrimercalcuxxndo.getText().matches("[0-9]+")) {
  225. JOptionPane.showMessageDialog(null, "caracteres invalidos en el 1");
  226. txtIngresePrimercalcuxxndo.requestFocus();
  227. txtIngresePrimercalcuxxndo.setText("");
  228.  
  229. }
  230. else if(!txtIngreseSegundocalcuxxndo.getText().matches("[0-9]+")) {
  231. JOptionPane.showMessageDialog(null, "caracteres invalidos en el 2");
  232. txtIngreseSegundocalcuxxndo.setText("");
  233. txtIngreseSegundocalcuxxndo.requestFocus();
  234. }
  235. }
  236.  
  237. }
  238. }
  239. });
  240. botonmult.setBounds(453, 158, 80, 35);
  241. contentPane.add(botonmult);
  242. }
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement