Swing-GUI GPA Calculator

Solution 1:

You appear to have used static without need.

static JLabel addLabel = new JLabel();

Make the above non-static, (ideally also make private)

public static void addElements

Make the above non static also, rename to something like setLabelText

DisplayPanel displayPanel = new DisplayPanel();
MyPanel myPanel = new MyPanel(displayPanel);

As shown above, pass displayPanel as a parameter to myPanel. Obviously in MyPanel, you would have one more instance variable:

DisplayPanel displayPanel;

which would be initialized in the constructor, using the constructor argument.

In MyPanel#actionPerformed, instead of:

//add to table panel
DisplayPanel.addElements(){
}

do:

displayPanel.addElements(....);

or rather

displayPanel.setLabelText(...);

invoke the DisplayPanel#setLabelText method on grade calculation and resetting also.

Also invoke the

Finally, remove line:

addLabel.setText("");

If you want DisplayPanel, why then also have the following?

public void createLabel(){