You are misusing inheritance, and this fundamental issue is causing your code not to work. In your class above you have
calculation extends tripCostCalculatorUI
you have the calculating class extend the GUI, with hopes that the GUI fields can then be used in your calculation, but this is not what inheritance is for -- it's not present to allow you to connect data, but rather to extend behavior. Yes, your current inheritance set up will allow you to access JTextFields, but (and this is key), these JTextFields are not the same as the ones displayed in the GUI, since they're part of a completely different instance. Your calculation class does not satisfy the "is-a" relationship with the GUI class, and so should not extend it.
Rather, instead you should give the calculation class (which should be renamed Calculation, as all class names should begin with an upper-case letter) methods that take numeric parameters that allow other classes that use this class, including the Gui class, the ability to pass data into the calculation methods, and then get the results that they return.
And so Calculation should use no JTextField variables and instead use the values passed into its calculation method parameters.
So within the GUI's ActionListener, the GUI itself will extract data from its components, convert anything that needs conversion to numeric values, call the appropriate method from the Calculation class to allow a calculation, and then display the result that is returned (after converting the result to text).
Here's a simple example of just what I mean where the GUI and the calculation classes are separate, where you use method parameters:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class SimpleCalcGui extends JPanel {
private static final long serialVersionUID = 1L;
private JTextField field1 = new JTextField(5);
private JTextField field2 = new JTextField(5);
private JTextField resultField = new JTextField(5);
private JButton calcButton = new JButton("Calculate");
public SimpleCalcGui() {
resultField.setFocusable(false);
calcButton.addActionListener(new CalcListener());
add(field1);
add(new JLabel("+"));
add(field2);
add(new JLabel("="));
add(resultField);
add(calcButton);
}
private class CalcListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
try {
// extract the values and convert to numbers
int value1 = Integer.parseInt(field1.getText());
int value2 = Integer.parseInt(field2.getText());
// call MyCalc's method passing in the values
int result = MyCalc.addition(value1, value2);
// display the result
resultField.setText("" + result);
} catch (NumberFormatException e1) {
JOptionPane.showMessageDialog(calcButton, "Both text fields must have valid numbers",
"Numeric Entry Error", JOptionPane.ERROR_MESSAGE);
field1.setText("");
field2.setText("");
}
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> createAndShowGui());
}
private static void createAndShowGui() {
SimpleCalcGui mainPanel = new SimpleCalcGui();
JFrame frame = new JFrame("SimpleCalcGui");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.add(mainPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
}
public class MyCalc {
// overly simple but just to show what I mean
public static int addition(int value1, int value2) {
return value1 + value2;
}
}