Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. package teopi4a;
  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. import javax.swing.JTextField;
  12. import javax.swing.JButton;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.Color;
  16.  
  17. public class Zadacha22 extends JFrame {
  18.  
  19. private JPanel contentPane;
  20. private JTextField textField;
  21. private JLabel lblNewLabel_1;
  22. private JTextField textField_Kola;
  23. private JLabel lblNewLabel_2;
  24. private JTextField textField_igrachka;
  25. private JLabel lblNewLabel_3;
  26. private JLabel lblOut;
  27.  
  28. /**
  29. * Launch the application.
  30. */
  31. public static void main(String[] args) {
  32. EventQueue.invokeLater(new Runnable() {
  33. public void run() {
  34. try {
  35. Zadacha22 frame = new Zadacha22();
  36. frame.setVisible(true);
  37. } catch (Exception e) {
  38. e.printStackTrace();
  39. }
  40. }
  41. });
  42. }
  43.  
  44. /**
  45. * Create the frame.
  46. */
  47. public Zadacha22() {
  48. setTitle("Rojden den - Kola");
  49. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  50. setBounds(100, 100, 450, 300);
  51. contentPane = new JPanel();
  52. contentPane.setBackground(Color.GREEN);
  53. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  54. setContentPane(contentPane);
  55. contentPane.setLayout(null);
  56.  
  57. JLabel lblNewLabel = new JLabel("\u0413\u043E\u0434\u0438\u043D\u0438");
  58. lblNewLabel.setBounds(10, 11, 46, 14);
  59. contentPane.add(lblNewLabel);
  60.  
  61. textField = new JTextField();
  62. textField.setForeground(Color.GREEN);
  63. textField.setBackground(Color.BLACK);
  64. textField.setBounds(66, 8, 86, 20);
  65. contentPane.add(textField);
  66. textField.setColumns(10);
  67.  
  68. lblNewLabel_1 = new JLabel("\u0426\u0435\u043D\u0430 \u043D\u0430 \u041A\u0430\u043B\u0430\u0448\u043D\u0438\u043A\u043E\u0444");
  69. lblNewLabel_1.setBounds(10, 38, 152, 14);
  70. contentPane.add(lblNewLabel_1);
  71.  
  72. textField_Kola = new JTextField();
  73. textField_Kola.setBackground(Color.BLACK);
  74. textField_Kola.setForeground(Color.GREEN);
  75. textField_Kola.setBounds(165, 35, 86, 20);
  76. contentPane.add(textField_Kola);
  77. textField_Kola.setColumns(10);
  78.  
  79. lblNewLabel_3 = new JLabel("\u0418\u043C\u0430 \u043B\u0438 \u043F\u0430\u0440\u0438?");
  80. lblNewLabel_3.setBounds(10, 86, 111, 14);
  81. contentPane.add(lblNewLabel_3);
  82.  
  83. lblOut = new JLabel("");
  84. lblOut.setBounds(106, 86, 46, 14);
  85. contentPane.add(lblOut);
  86.  
  87. JButton btnNewButton = new JButton("\u0421\u043C\u0435\u0442\u043D\u0438");
  88. btnNewButton.setBackground(Color.BLACK);
  89. btnNewButton.setForeground(Color.GREEN);
  90. btnNewButton.addActionListener(new ActionListener() {
  91. public void actionPerformed(ActionEvent e) {
  92. int g = Integer.valueOf(textField.getText());
  93. int cenaKola = Integer.valueOf(textField_Kola.getText());
  94. int cenaIgrachka[] = new int[(int) Math.ceil(g / 2d)];
  95. for(int i = 0; i < (int) Math.ceil(g / 2d); i++) {
  96. cenaIgrachka[i] = Integer.valueOf(JOptionPane.showInputDialog("Vuvedete cena na igrachka"));
  97. }
  98. int pari = 0;
  99. for(int i = 1; i <= g; i++) {
  100. if((i % 2) == 1) {
  101. pari += cenaIgrachka[(int) Math.ceil(i / 2d) - 1];
  102. } else {
  103. pari += 9;
  104. }
  105. }
  106. System.out.println(pari);
  107.  
  108. lblOut.setText(pari >= cenaKola ? "ะ”ะฐ" : "ะะต");
  109. }
  110. });
  111. btnNewButton.setBounds(162, 7, 89, 23);
  112. contentPane.add(btnNewButton);
  113. }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement