Hello. The point is that in lab 3, they asked to write an interface to class lab 2. I read the book and wrote JFrame to everyone. How do I now make class inheritances and how to use methods. here is my interface I need to use the variable begin end step and methods from lab 2. for example, creating an array of these concepts and outputting to the screen.

interface code and code lab 2. thanks in advance.

package javaapplication5; import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener; import java.awt.Event.*; import java.awt.FlowLayout; import java.awt.event.ActionEvent; class JFrames implements ActionListener { JLabel jlab1; JLabel jlab2; JButton jbtn; JTextField jtf1; JTextField jtf2; JTextField jtf3; JFrames(){ JFrame jfrm = new JFrame ("Variant #5"); jfrm.getContentPane().setLayout(new FlowLayout()); jfrm.setSize(300,300); jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel jpnl = new JPanel(); jpnl.setPreferredSize(new Dimension (50,50)); jpnl.setOpaque(true); jpnl.setBorder(BorderFactory.createLineBorder(Color.BLUE)); JPanel jpnl2 = new JPanel(); jpnl2.setPreferredSize(new Dimension (50,50)); jpnl2.setOpaque(true); jpnl2.setBorder(BorderFactory.createLineBorder(Color.RED)); jlab1 = new JLabel ("Write begin, end, step"); jlab2 = new JLabel ("Write begin, end, step"); jtf1 = new JTextField(10); jtf1.setActionCommand("begin"); jtf1.addActionListener(this); jfrm.getContentPane().add(jtf1); jtf2 = new JTextField(10); jtf2.setActionCommand("end"); jtf2.addActionListener(this); jfrm.getContentPane().add(jtf2); jtf3 = new JTextField(10); jtf3.setActionCommand( "step"); jtf3.addActionListener(this); jfrm.getContentPane().add(jtf3); jbtn = new JButton("Result"); jbtn.addActionListener(actionPerfom); jbtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jlab2.setText("Result"); }}); jpnl.add(jbtn); jpnl.add(jtf1); jpnl.add(jtf2); jpnl.add(jtf3); jpnl.add(jlab1); jpnl2.add(jlab2); jfrm.getContentPane().add(jpnl); jfrm.getContentPane().add(jpnl2); jfrm.setVisible(true); } public static void main (String args[]){ SwingUtilities.invokeLater(new Runnable(){ public void run(){ new NewClass(); } }); } } 

 package javaapplication5; import static java.lang.Math.*; public class Allgol{ public static void main(String[] args) { Allgol program = new Allgol(); program.run(); } private double[] arrayX; private double[] arrayY; double EPS= 1e-6; public void run() { double start = 0.2; double end = 2.8; double step = 0.002; arrayX = createX(start, end, step); arrayY = createY(arrayX); Print();} private void Print(){ System.out.printf("MinY =: %6.3f\n", arrayY[MinY(arrayY)]); System.out.println("Number minY: " + MinY(arrayY)); System.out.printf("MaxY = %6.3f\n", arrayY[MaxY(arrayY)]); System.out.println("Number maxY: " + MaxY(arrayY)); System.out.printf("Sum = %6.3f\n", sum(arrayY)); System.out.printf("arith mean у = %6.3f\n", arithMean(arrayY));} double[] createX( double start, double end, double step) { double[] res = new double[size(start,end,step)]; for (int i = 0; i < res.length; i++) { res[i] = start + i * step; } return res; } double[] createY(double[] arrayX) { double[] res = new double[arrayX.length]; for (int i = 0; i < res.length; i++) { res[i] = amount(arrayX[i]); } return res; } double amount(double x) { final double a=2.3; if (x > 2.3 ) { return 1.5*a*cos(pow(x,2)); } else if (x<0.3 ) { return 3*a*tan(x); } else { return pow((x-2),2)+6*a; } } int size(double start, double end, double step) { return (int) Math.round((end - start) / step) + 1; } int MinY(double[] arrayY) { double miny = arrayY[0]; int j = 0; for (int i = 0; i < arrayY.length; ++i) { if (arrayY[i] < miny) { miny = arrayY[i]; j = i; } } return j; } int MaxY(double[] arrayY) { double maxy = arrayY[0]; int j = 0; for (int i = 0; i < arrayY.length; ++i) { if (arrayY[i] > maxy) { maxy = arrayY[i]; j = i; } } return j; } double sum(double[] array) { double sum = 0; for (int i = 0; i < array.length; ++i) { sum += array[i]; } return sum; } double arithMean(double[] array) { return sum(array) / array.length; } } 

    1 answer 1

    1. Highlight the creation of labels begin, end, step in a separate method that accepts the command name and number as input.
    2. Select the creation of panels in separate methods: each method returns a panel that you add later.
    3. Make the methods you need in Allgol public and call them where necessary.