NellyIvanova29

Степени на 2

Mar 22nd, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. package Zadachi;
  2.  
  3. import java.awt.EventQueue;
  4. import javax.swing.*;
  5. import java.awt.*;
  6.  
  7. import javax.swing.JFrame;
  8. import javax.swing.JOptionPane;
  9. import javax.swing.JTextField;
  10. import javax.swing.JButton;
  11. import java.awt.event.ActionListener;
  12. import java.awt.event.ActionEvent;
  13. import javax.swing.JLabel;
  14. import javax.swing.JTextArea;
  15.  
  16. public class StepeniNa2 {
  17.  
  18.     private JFrame frame;
  19.     private JTextField textField1;
  20.     private JTextField textField2;
  21.     private JLabel lblNewLabel;
  22.     private JLabel lblNewLabel_1;
  23.  
  24.     /**
  25.      * Launch the application.
  26.      */
  27.     public static void main(String[] args) {
  28.         EventQueue.invokeLater(new Runnable() {
  29.             public void run() {
  30.                 try {
  31.                     StepeniNa2 window = new StepeniNa2();
  32.                     window.frame.setVisible(true);
  33.                 } catch (Exception e) {
  34.                     e.printStackTrace();
  35.                 }
  36.             }
  37.         });
  38.     }
  39.  
  40.     /**
  41.      * Create the application.
  42.      */
  43.     public StepeniNa2() {
  44.         initialize();
  45.     }
  46.  
  47.     /**
  48.      * Initialize the contents of the frame.
  49.      */
  50.     private void initialize() {
  51.         frame =new JFrame();
  52.         frame.setTitle("\u0421\u0442\u0435\u043F\u0435\u043D\u0438 \u043D\u0430 \u0447\u0438\u0441\u043B\u043E\u0442\u043E 2");
  53.         frame.setBounds(100, 100, 450, 190);
  54.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  55.         frame.getContentPane().setLayout(null);
  56.        
  57.         textField1 = new JTextField();
  58.         textField1.setBounds(10, 49, 103, 20);
  59.         frame.getContentPane().add(textField1);
  60.         textField1.setColumns(10);
  61.        
  62.         textField2 = new JTextField();
  63.         textField2.setText("");
  64.         textField2.setBounds(154, 49, 103, 20);
  65.         frame.getContentPane().add(textField2);
  66.         textField2.setColumns(10);
  67.        
  68.         JTextArea textArea = new JTextArea();
  69.         textArea.setBounds(27, 104, 380, 28);
  70.         frame.getContentPane().add(textArea);
  71.        
  72.         JButton btnNewButton = new JButton("\u041F\u0440\u0435\u0441\u043C\u0435\u0442\u043D\u0438");
  73.         btnNewButton.addActionListener(new ActionListener() {
  74.             public void actionPerformed(ActionEvent e) {
  75.             int a=Integer.parseInt(textField1.getText());
  76.             int b=Integer.parseInt(textField2.getText());
  77.             for (int i=a; i <b+1; i ++) {
  78.                 if (i>0&&i==Math.pow(2,Math.round(Math.log(i)/Math.log(2)))) {
  79.                     textArea.setText(textArea.getText()+" "+Integer.toString(i));
  80.                
  81.                 }
  82.             }
  83.             }
  84.         });
  85.         btnNewButton.setBounds(318, 48, 89, 23);
  86.         frame.getContentPane().add(btnNewButton);
  87.        
  88.         lblNewLabel = new JLabel("\u041D\u0430\u0447\u0430\u043B\u043E \u043D\u0430 \u0438\u043D\u0442\u0435\u0440\u0432\u0430\u043B\u0430");
  89.         lblNewLabel.setBounds(10, 18, 123, 20);
  90.         frame.getContentPane().add(lblNewLabel);
  91.        
  92.         lblNewLabel_1 = new JLabel("\u041A\u0440\u0430\u0439 \u043D\u0430 \u0438\u043D\u0442\u0435\u0440\u0432\u0430\u043B\u0430");
  93.         lblNewLabel_1.setBounds(154, 21, 134, 14);
  94.         frame.getContentPane().add(lblNewLabel_1);
  95.        
  96.        
  97.        
  98.        
  99.     }
  100. }
Add Comment
Please, Sign In to add comment