Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class Reader extends JFrame{
  6. JButton b1, b2;
  7. JLabel l1, l2, l3, l4;
  8. JTextField t1, t2;
  9. int i, k;
  10. String a, b;
  11. eHandler handler = new eHandler();
  12.  
  13. public Reader(String s){
  14. super(s);
  15. setLayout(new FlowLayout());
  16. b1 = new JButton("Очистить");
  17. b2 = new JButton("Посчитать");
  18. l1 = new JLabel("Введите 1ое число");
  19. l2 = new JLabel("Введите 2ое число");
  20. l3 = new JLabel("");
  21. l4 = new JLabel("");
  22. t1 = new JTextField(10);
  23. t2 = new JTextField(10);
  24.  
  25. add(b1);
  26. add(b2);
  27. add(l1);
  28. add(t1);
  29. add(l2);
  30. add(t2);
  31. add(l3);
  32. add(l4);
  33. b2.addActionListener(handler);
  34. b1.addActionListener(handler);
  35. }
  36.  
  37. public class eHandler implements ActionListener{
  38. public void actionPerformed(ActionEvent e) {
  39. try{
  40. if(e.getSource()==b2){
  41. i = Integer.parseInt(t1.getText());
  42. k = Integer.parseInt(t2.getText());
  43. i++;
  44. k++;
  45. a = "Ваше 1ое число теперь равно " + i;
  46. b = "Ваше 2ое число теперь равно " + k;
  47. l3.setText(a);
  48. l4.setText(b);
  49. }
  50.  
  51. if(e.getSource()==b1){
  52. t1.setText(null);
  53. t2.setText(null);
  54. l3.setText("");
  55. l4.setText("");
  56. }
  57. } catch (Exception ex){ JOptionPane.showMessageDialog(null, "введите в поле число");}
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement