Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package teopi4a;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.Color;
- public class Zadacha22 extends JFrame {
- private JPanel contentPane;
- private JTextField textField;
- private JLabel lblNewLabel_1;
- private JTextField textField_Kola;
- private JLabel lblNewLabel_2;
- private JTextField textField_igrachka;
- private JLabel lblNewLabel_3;
- private JLabel lblOut;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Zadacha22 frame = new Zadacha22();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Zadacha22() {
- setTitle("Rojden den - Kola");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBackground(Color.GREEN);
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel lblNewLabel = new JLabel("\u0413\u043E\u0434\u0438\u043D\u0438");
- lblNewLabel.setBounds(10, 11, 46, 14);
- contentPane.add(lblNewLabel);
- textField = new JTextField();
- textField.setForeground(Color.GREEN);
- textField.setBackground(Color.BLACK);
- textField.setBounds(66, 8, 86, 20);
- contentPane.add(textField);
- textField.setColumns(10);
- lblNewLabel_1 = new JLabel("\u0426\u0435\u043D\u0430 \u043D\u0430 \u041A\u0430\u043B\u0430\u0448\u043D\u0438\u043A\u043E\u0444");
- lblNewLabel_1.setBounds(10, 38, 152, 14);
- contentPane.add(lblNewLabel_1);
- textField_Kola = new JTextField();
- textField_Kola.setBackground(Color.BLACK);
- textField_Kola.setForeground(Color.GREEN);
- textField_Kola.setBounds(165, 35, 86, 20);
- contentPane.add(textField_Kola);
- textField_Kola.setColumns(10);
- lblNewLabel_3 = new JLabel("\u0418\u043C\u0430 \u043B\u0438 \u043F\u0430\u0440\u0438?");
- lblNewLabel_3.setBounds(10, 86, 111, 14);
- contentPane.add(lblNewLabel_3);
- lblOut = new JLabel("");
- lblOut.setBounds(106, 86, 46, 14);
- contentPane.add(lblOut);
- JButton btnNewButton = new JButton("\u0421\u043C\u0435\u0442\u043D\u0438");
- btnNewButton.setBackground(Color.BLACK);
- btnNewButton.setForeground(Color.GREEN);
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int g = Integer.valueOf(textField.getText());
- int cenaKola = Integer.valueOf(textField_Kola.getText());
- int cenaIgrachka[] = new int[(int) Math.ceil(g / 2d)];
- for(int i = 0; i < (int) Math.ceil(g / 2d); i++) {
- cenaIgrachka[i] = Integer.valueOf(JOptionPane.showInputDialog("Vuvedete cena na igrachka"));
- }
- int pari = 0;
- for(int i = 1; i <= g; i++) {
- if((i % 2) == 1) {
- pari += cenaIgrachka[(int) Math.ceil(i / 2d) - 1];
- } else {
- pari += 9;
- }
- }
- System.out.println(pari);
- lblOut.setText(pari >= cenaKola ? "ะะฐ" : "ะะต");
- }
- });
- btnNewButton.setBounds(162, 7, 89, 23);
- contentPane.add(btnNewButton);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement