Advertisement
sneyzi

Laba 12, 2-3 (5 variant)

Jun 21st, 2021 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.56 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. public class Main extends javax.swing.JFrame {
  8.  
  9.     /**
  10.      * Creates new form Main
  11.      */
  12.     public Main() {
  13.         initComponents();
  14.     }
  15.  
  16.     /**
  17.      * This method is called from within the constructor to initialize the form.
  18.      * WARNING: Do NOT modify this code. The content of this method is always
  19.      * regenerated by the Form Editor.
  20.      */
  21.     @SuppressWarnings("unchecked")
  22.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  23.     private void initComponents() {
  24.  
  25.         jScrollPane1 = new javax.swing.JScrollPane();
  26.         jTextArea1 = new javax.swing.JTextArea();
  27.         jPanel1 = new javax.swing.JPanel();
  28.         jCheckBox1 = new javax.swing.JCheckBox();
  29.         jCheckBox2 = new javax.swing.JCheckBox();
  30.         jCheckBox3 = new javax.swing.JCheckBox();
  31.         jTextField1 = new javax.swing.JTextField();
  32.         jTextField2 = new javax.swing.JTextField();
  33.         jTextField3 = new javax.swing.JTextField();
  34.         jLabel1 = new javax.swing.JLabel();
  35.         jLabel2 = new javax.swing.JLabel();
  36.         jLabel3 = new javax.swing.JLabel();
  37.         jLabel4 = new javax.swing.JLabel();
  38.         jMenuBar1 = new javax.swing.JMenuBar();
  39.         jMenu1 = new javax.swing.JMenu();
  40.         jMenuItem1 = new javax.swing.JMenuItem();
  41.         jMenuItem2 = new javax.swing.JMenuItem();
  42.         jMenu2 = new javax.swing.JMenu();
  43.         jMenuItem3 = new javax.swing.JMenuItem();
  44.         jMenuItem4 = new javax.swing.JMenuItem();
  45.         jMenuItem5 = new javax.swing.JMenuItem();
  46.  
  47.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  48.  
  49.         jTextArea1.setColumns(20);
  50.         jTextArea1.setRows(5);
  51.         jScrollPane1.setViewportView(jTextArea1);
  52.  
  53.         jCheckBox1.setText("на екран");
  54.         jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
  55.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  56.                 jCheckBox1ActionPerformed(evt);
  57.             }
  58.         });
  59.  
  60.         jCheckBox2.setText("похідна");
  61.  
  62.         jCheckBox3.setText("у масив");
  63.  
  64.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  65.         jPanel1.setLayout(jPanel1Layout);
  66.         jPanel1Layout.setHorizontalGroup(
  67.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  68.             .addGroup(jPanel1Layout.createSequentialGroup()
  69.                 .addContainerGap()
  70.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  71.                     .addComponent(jCheckBox1)
  72.                     .addComponent(jCheckBox2)
  73.                     .addComponent(jCheckBox3))
  74.                 .addContainerGap(13, Short.MAX_VALUE))
  75.         );
  76.         jPanel1Layout.setVerticalGroup(
  77.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  78.             .addGroup(jPanel1Layout.createSequentialGroup()
  79.                 .addContainerGap()
  80.                 .addComponent(jCheckBox1)
  81.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  82.                 .addComponent(jCheckBox2)
  83.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  84.                 .addComponent(jCheckBox3)
  85.                 .addContainerGap(18, Short.MAX_VALUE))
  86.         );
  87.  
  88.         jLabel1.setText("крок");
  89.  
  90.         jLabel2.setText("права межа");
  91.  
  92.         jLabel3.setText("ліва межа");
  93.  
  94.         jLabel4.setText("y=2sinx-1");
  95.  
  96.         jMenu1.setText("Обчислення");
  97.  
  98.         jMenuItem1.setText("протабулювати");
  99.         jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
  100.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  101.                 jMenuItem1ActionPerformed(evt);
  102.             }
  103.         });
  104.         jMenu1.add(jMenuItem1);
  105.  
  106.         jMenuItem2.setText("очистити");
  107.         jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
  108.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  109.                 jMenuItem2ActionPerformed(evt);
  110.             }
  111.         });
  112.         jMenu1.add(jMenuItem2);
  113.  
  114.         jMenuBar1.add(jMenu1);
  115.  
  116.         jMenu2.setText("Кінець");
  117.  
  118.         jMenuItem3.setText("про програму");
  119.         jMenu2.add(jMenuItem3);
  120.  
  121.         jMenuItem4.setText("про автора");
  122.         jMenu2.add(jMenuItem4);
  123.  
  124.         jMenuItem5.setText("вихід");
  125.         jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
  126.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  127.                 jMenuItem5ActionPerformed(evt);
  128.             }
  129.         });
  130.         jMenu2.add(jMenuItem5);
  131.  
  132.         jMenuBar1.add(jMenu2);
  133.  
  134.         setJMenuBar(jMenuBar1);
  135.  
  136.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  137.         getContentPane().setLayout(layout);
  138.         layout.setHorizontalGroup(
  139.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  140.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  141.                 .addContainerGap()
  142.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 449, Short.MAX_VALUE)
  143.                 .addGap(18, 18, 18)
  144.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  145.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  146.                         .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  147.                         .addComponent(jTextField1)
  148.                         .addComponent(jTextField2)
  149.                         .addComponent(jTextField3))
  150.                     .addComponent(jLabel1)
  151.                     .addComponent(jLabel2)
  152.                     .addComponent(jLabel3))
  153.                 .addGap(25, 25, 25))
  154.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  155.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  156.                 .addComponent(jLabel4)
  157.                 .addGap(63, 63, 63))
  158.         );
  159.         layout.setVerticalGroup(
  160.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  161.             .addGroup(layout.createSequentialGroup()
  162.                 .addGap(4, 4, 4)
  163.                 .addComponent(jLabel4)
  164.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  165.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  166.                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 290, javax.swing.GroupLayout.PREFERRED_SIZE)
  167.                     .addGroup(layout.createSequentialGroup()
  168.                         .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  169.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  170.                         .addComponent(jLabel3)
  171.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  172.                         .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  173.                         .addGap(5, 5, 5)
  174.                         .addComponent(jLabel2)
  175.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  176.                         .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  177.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  178.                         .addComponent(jLabel1)
  179.                         .addGap(11, 11, 11)
  180.                         .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  181.                 .addContainerGap(20, Short.MAX_VALUE))
  182.         );
  183.  
  184.         pack();
  185.     }// </editor-fold>                        
  186.  
  187.     private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  188.         if (jCheckBox1.isSelected()) {
  189.             jTextArea1.setText("x f(x)");
  190.         }
  191.         double a = Double.parseDouble(jTextField1.getText());
  192.         double b = Double.parseDouble(jTextField2.getText());
  193.         double h = Double.parseDouble(jTextField3.getText());
  194.  
  195.         int i = 0, positiveNumbers = 0;
  196.  
  197.         double x = a, y;
  198.         double[] masiv = new double[(int) ((b - a) / h) + 1];
  199.         double min = 2 * Math.sin(x) - 1;
  200.         double max = 2 * Math.sin(x) - 1;
  201.  
  202.         while (x <= b) {
  203.             y = jCheckBox2.isSelected() ? 2 * Math.cos(x) : 2 * Math.sin(x) - 1;
  204.  
  205.             if (jCheckBox3.isSelected()) {
  206.                 masiv[i] = y;
  207.  
  208.                 if (masiv[i] > 0) {
  209.                     positiveNumbers++;
  210.                 }
  211.  
  212.                 if (masiv[i] < min) {
  213.                     min = masiv[i];
  214.                 }
  215.  
  216.                 if (masiv[i] > min) {
  217.                     max = masiv[i];
  218.                 }
  219.  
  220.                 i++;
  221.             }
  222.             if (jCheckBox1.isSelected()) {
  223.                 jTextArea1.append("\n" + x + " " + y + (jCheckBox3.isSelected() ? " -" + i + "ий елемент масиву " : ""));
  224.             }
  225.             x = x + h;
  226.         }
  227.         if (jCheckBox3.isSelected()) {
  228.             jTextArea1.append("\nРізниця між  мінімальним і максимальним елементами " + String.valueOf(min - max));
  229.             jTextArea1.append("\nКількість додатніх елементів " + positiveNumbers);
  230.         }
  231.     }                                          
  232.  
  233.     private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  234.         // TODO add your handling code here:
  235.     }                                          
  236.  
  237.     private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  238.         jTextArea1.setText("");
  239.     }                                          
  240.  
  241.     private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  242.         System.exit(0);
  243.     }                                          
  244.  
  245.     /**
  246.      * @param args the command line arguments
  247.      */
  248.     public static void main(String args[]) {
  249.         /* Set the Nimbus look and feel */
  250.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  251.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  252.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  253.          */
  254.         try {
  255.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  256.                 if ("Nimbus".equals(info.getName())) {
  257.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  258.                     break;
  259.                 }
  260.             }
  261.         } catch (ClassNotFoundException ex) {
  262.             java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  263.         } catch (InstantiationException ex) {
  264.             java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  265.         } catch (IllegalAccessException ex) {
  266.             java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  267.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  268.             java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  269.         }
  270.         //</editor-fold>
  271.  
  272.         /* Create and display the form */
  273.         java.awt.EventQueue.invokeLater(new Runnable() {
  274.             public void run() {
  275.                 new Main().setVisible(true);
  276.             }
  277.         });
  278.     }
  279.  
  280.     // Variables declaration - do not modify                    
  281.     private javax.swing.JCheckBox jCheckBox1;
  282.     private javax.swing.JCheckBox jCheckBox2;
  283.     private javax.swing.JCheckBox jCheckBox3;
  284.     private javax.swing.JLabel jLabel1;
  285.     private javax.swing.JLabel jLabel2;
  286.     private javax.swing.JLabel jLabel3;
  287.     private javax.swing.JLabel jLabel4;
  288.     private javax.swing.JMenu jMenu1;
  289.     private javax.swing.JMenu jMenu2;
  290.     private javax.swing.JMenuBar jMenuBar1;
  291.     private javax.swing.JMenuItem jMenuItem1;
  292.     private javax.swing.JMenuItem jMenuItem2;
  293.     private javax.swing.JMenuItem jMenuItem3;
  294.     private javax.swing.JMenuItem jMenuItem4;
  295.     private javax.swing.JMenuItem jMenuItem5;
  296.     private javax.swing.JPanel jPanel1;
  297.     private javax.swing.JScrollPane jScrollPane1;
  298.     private javax.swing.JTextArea jTextArea1;
  299.     private javax.swing.JTextField jTextField1;
  300.     private javax.swing.JTextField jTextField2;
  301.     private javax.swing.JTextField jTextField3;
  302.     // End of variables declaration                  
  303. }
  304.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement