Eliminating global variables in GUI program I'm just getting started on GUI programming using swing in Java, and I would love some critiques on my code. I understand there is a danger in using global variables.  If someone can hint me on how to get rid of my globals (which will be later registered for event handling), I'd really appreciate it.

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public final class Calculator extends JFrame
{
    //initialise various variables for use within the program
    //BUTTONS
    private final JButton additionButton = new JButton("+"); 
    private final JButton subtractionButton = new JButton("-");
    private final JButton divisionButton = new JButton("/");
    private final JButton multiplicationButton = new JButton("*");    

    //PANELS
    private JPanel operatorPanel;
    private JPanel operandPanel;

    //LABELS
    private JLabel operationLabel;    

    //constructor to initialise the frame and add components into it
    public Calculator()
    {
        super("Clancy's Calculator");
        setLayout(new BorderLayout(5, 10));
        setResizable(false);
        setSize(370, 200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setVisible(true);

        //create a message label to display the operation that has just taken place
        operationLabel = new JLabel("YOU HAVE PERFORMED SOME OPERATION", SwingConstants.CENTER);

        add(getOperatorPanel(), BorderLayout.NORTH);
        add(getOperandPanel(), BorderLayout.CENTER);
        add(operationLabel, BorderLayout.SOUTH);

        pack();
    }

    //setter method for the operator panel
    public void setOperatorPanel()
    {
        operatorPanel = new JPanel();
        operatorPanel.setLayout(new FlowLayout());

        operatorPanel.add(additionButton);
        operatorPanel.add(subtractionButton);
        operatorPanel.add(multiplicationButton);
        operatorPanel.add(divisionButton);
    }
    //getter method for the operator panel
    public JPanel getOperatorPanel()
    {
        setOperatorPanel();
        return operatorPanel;
    }

    //setter method for operands panel
    public void setOperandPanel()
    {
        operandPanel = new JPanel();
        operandPanel.setLayout(new GridLayout(3, 2, 5, 5));

        //LABELS
        JLabel operandOneLabel = new JLabel("Enter the first Operand: ");
        JLabel operandTwoLabel = new JLabel("Enter the second Operand: ");
        JLabel answerLabel = new JLabel("ANSWER: ");

        //TEXT FIELDS
        JTextField operandOneText = new JTextField();   //retrieves one operand
        JTextField operandTwoText = new JTextField();   //retrieves another operand
        JTextField answerText = new JTextField();   //displays answer

        answerText.setEditable(false);  //ensure the answer field is not editable

        operandPanel.add(operandOneLabel);
        operandPanel.add(operandOneText);
        operandPanel.add(operandTwoLabel);
        operandPanel.add(operandTwoText);
        operandPanel.add(answerLabel);
        operandPanel.add(answerText);

    }
    //getter method for operand panel
    public JPanel getOperandPanel()
    {
        setOperandPanel();
        return operandPanel;
    }

    /** main method */
    public static void main(String[] args)
    {
        new Calculator();
    }
}
A thing I like to do is instead of using four different JButtons is use an array of four JButtons that is initialized in the same method that you build the JPanel this would remove the need to have them as global variables. Also instead of using two different methods to create your JPanels just use one that returns a JPanel as you can see you can remove the JButtons and the two JPanels this way:

public JPanel buildOperatorPanel()
{
    JPanel operatorPanel = new JPanel();
    operatorPanel.setLayout(new FlowLayout());

    JButton[] buttons = new JButton[4];//the array of JButtons
    String[] buttonNames = {"+", "-", "/", "*"};//the names to be displayed on the JButtons
    for(int i = 0; i &lt; buttons.length; i++)
    {
        buttons[i] = new JButton(buttonNames[i]);
        //buttons[i].addActionListener(yourActionListener)//for whenever you add event handling
        operatorPanel.add(buttons[i]);
    }
    return operatorPanel;
}


Another thing I could suggest is instead of named reference variables for your JLabels use anonymous objects so for operationLabel (this is only assuming your not going to use the JLabels later):

add(new JLabel("YOU HAVE PERFORMED SOME OPERATION", SwingConstants.CENTER), BorderLayout.SOUTH);


However I am going to suggest that you move the JTextFields to global variables. Based on what I'm assuming you have to do with this calculator you are going to want the JTextFields to be accessible to everything.
Here is my revision of your code:

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public final class Calculator extends JFrame
{
    private JTextField operandOneText;//these get initialized in buildOperandPanel() method which is called in the constructor
    private JTextField operandTwoText;
    private JTextField answerText;

    //constructor to initialise the frame and add components into it
    public Calculator()
    {
        super("Clancy's Calculator");
        setLayout(new BorderLayout(5, 10));
        setResizable(false);
        setSize(370, 200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setVisible(true);

        add(buildOperatorPanel(), BorderLayout.NORTH);
        add(buildOperandPanel(), BorderLayout.CENTER);
        add(new JLabel("YOU HAVE PERFORMED SOME OPERATION", SwingConstants.CENTER), BorderLayout.SOUTH);

        pack();
    }

    //method builds and returns operatorPanel
    public JPanel buildOperatorPanel()
    {
        JPanel operatorPanel = new JPanel();//JPanels are FlowLayout by default

        JButton[] buttons = new JButton[4];
        String[] buttonNames = {"+", "-", "/", "*"};
        for(int i = 0; i &lt; buttons.length; i++)
        {
            buttons[i] = new JButton(buttonNames[i]);//the array of JButtons
            //buttons[i].addActionListener(yourActionListener)//for whenever you add event handling
            operatorPanel.add(buttons[i]);
        }
        return operatorPanel;
    }

    //method builds and returns operandPanel
    public JPanel buildOperandPanel()
    {
        JPanel operandPanel = new JPanel();
        operandPanel.setLayout(new GridLayout(3, 2, 5, 5));

        //Initialize TEXT FIELDS
        operandOneText = new JTextField();  //retrieves one operand
        operandTwoText = new JTextField();  //retrieves another operand
        answerText = new JTextField();    //displays answer

        answerText.setEditable(false);  //ensure the answer field is not editable

        operandPanel.add(new JLabel("Enter the first Operand: "));
        operandPanel.add(operandOneText);
        operandPanel.add(new JLabel("Enter the second Operand: "));
        operandPanel.add(operandTwoText);
        operandPanel.add(new JLabel("ANSWER: "));
        operandPanel.add(answerText);

        return operandPanel;
    }

    /** main method */
    public static void main(String[] args)
    {
        new Calculator();
    }
}