Advertisement
sneyzi

Laba 11, 2

Jun 10th, 2021
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.79 KB | None | 0 0
  1. import java.awt.EventQueue;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JPanel;
  5. import javax.swing.border.EmptyBorder;
  6. import javax.swing.JTextField;
  7. import javax.swing.JButton;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.ActionEvent;
  10. import javax.swing.JLabel;
  11.  
  12. public class Task2 extends JFrame {
  13.  
  14.     /**
  15.      *
  16.      */
  17.     private static final long serialVersionUID = 1L;
  18.     private JPanel contentPane;
  19.     private JTextField textField;
  20.     private JTextField textField_1;
  21.     private JTextField textField_2;
  22.     private JTextField textField_3;
  23.     private JLabel lblUsd;
  24.     private JLabel lblU;
  25.     private JLabel label_1;
  26.     private JTextField textField_4;
  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.                     Task2 frame = new Task2();
  36.                     frame.setVisible(true);
  37.                 } catch (Exception e) {
  38.                     e.printStackTrace();
  39.                 }
  40.             }
  41.         });
  42.     }
  43.  
  44.     /**
  45.      * Create the frame.
  46.      */
  47.     public Task2() {
  48.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  49.         setBounds(100, 100, 450, 300);
  50.         contentPane = new JPanel();
  51.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  52.         setContentPane(contentPane);
  53.         contentPane.setLayout(null);
  54.  
  55.         textField = new JTextField();
  56.         textField.setEditable(false);
  57.         textField.setText("5.7");
  58.         textField.setBounds(117, 96, 86, 20);
  59.         contentPane.add(textField);
  60.         textField.setColumns(10);
  61.  
  62.         textField_1 = new JTextField();
  63.         textField_1.setEditable(false);
  64.         textField_1.setText("2.25");
  65.         textField_1.setColumns(10);
  66.         textField_1.setBounds(272, 98, 86, 20);
  67.         contentPane.add(textField_1);
  68.  
  69.         textField_2 = new JTextField();
  70.         textField_2.setBounds(97, 128, 86, 20);
  71.         contentPane.add(textField_2);
  72.         textField_2.setColumns(10);
  73.  
  74.         textField_3 = new JTextField();
  75.         textField_3.setColumns(10);
  76.         textField_3.setBounds(207, 128, 86, 20);
  77.         contentPane.add(textField_3);
  78.  
  79.         JButton button = new JButton("\u041E\u0431\u0447\u0438\u0441\u043B\u0438\u0442\u0438");
  80.         button.addActionListener(new ActionListener() {
  81.             public void actionPerformed(ActionEvent e) {
  82.                 double neyl_to_sm = Double.valueOf(textField.getText());
  83.                 double neyl_to_duym = Double.valueOf(textField_1.getText());
  84.                 double count = Double.valueOf(textField_2.getText());
  85.                
  86.                 textField_3.setText(String.valueOf(count * neyl_to_sm));
  87.                 textField_4.setText(String.valueOf(count * neyl_to_duym));
  88.             }
  89.         });
  90.         button.setBounds(9, 209, 185, 23);
  91.         contentPane.add(button);
  92.  
  93.         JButton button_1 = new JButton("\u041A\u0456\u043D\u0435\u0446\u044C");
  94.         button_1.addActionListener(new ActionListener() {
  95.             public void actionPerformed(ActionEvent e) {
  96.                 System.exit(0);
  97.             }
  98.         });
  99.         button_1.setBounds(336, 209, 91, 23);
  100.         contentPane.add(button_1);
  101.        
  102.         JLabel lblUan = new JLabel("1 \u043D\u0435\u0439\u043B =");
  103.         lblUan.setBounds(42, 98, 60, 14);
  104.         contentPane.add(lblUan);
  105.        
  106.         lblUsd = new JLabel("\u041D\u0435\u0439\u043B\u0438");
  107.         lblUsd.setBounds(21, 132, 50, 14);
  108.         contentPane.add(lblUsd);
  109.        
  110.         JButton button_2 = new JButton("\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u0438");
  111.         button_2.addActionListener(new ActionListener() {
  112.             public void actionPerformed(ActionEvent arg0) {
  113.                 textField_2.setText("");
  114.                 textField_3.setText("");
  115.                 textField_4.setText("");
  116.             }
  117.         });
  118.         button_2.setBounds(226, 208, 91, 23);
  119.         contentPane.add(button_2);
  120.        
  121.         lblU = new JLabel("\u0441\u043C \u0430\u0431\u043E");
  122.         lblU.setBounds(213, 99, 51, 14);
  123.         contentPane.add(lblU);
  124.        
  125.         label_1 = new JLabel("\u0434\u044E\u0439\u043C\u0456\u0432");
  126.         label_1.setBounds(371, 97, 53, 14);
  127.         contentPane.add(label_1);
  128.        
  129.         textField_4 = new JTextField();
  130.         textField_4.setColumns(10);
  131.         textField_4.setBounds(312, 130, 86, 20);
  132.         contentPane.add(textField_4);
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement