title: non-static variable s cannot be referenced from a static context
body: <p>I'm trying to write a piece of code that when I check one of the two checkboxes, it will change the message that appears when I then select the button. </p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  
  public class  FirstWindow extends JFrame{
  
          String message;
  
          public static void main(String[] args){
  
              //the string to show the message for button 1
              message = "goodjob \n";
  
              //all of the main window
              JFrame frame = new JFrame("heading");
              frame.setVisible(true);
              frame.setSize(600,400);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setLocationRelativeTo(null);
  
              //makes seperate panels
              JPanel panel1 = new JPanel();
              JPanel panel2 = new JPanel();
              JPanel panel3 = new JPanel(new GridBagLayout());
  
              //set of buttons
              JButton button1 = new JButton("Button 1");
              JButton button2 = new JButton("Button 2");
  
              //makes an ACTION LISTENER, which tells the button what to do when
              //it is pressed.
              button1.addActionListener(new ActionListener(){
  
                      //the command to button 
                      @Override
                      public void actionPerformed(ActionEvent e) {
                      JOptionPane.showMessageDialog(null, message);
  
                      }
          });
  
              //for panel adds buttons
              panel1.add(button1);
              panel1.add(button2);
  
              //set of checkboxes 
              JCheckBox checkBox = new JCheckBox("Option1");
              JCheckBox checkBox2 = new JCheckBox("Option2");
  
              //adds text if the box is checked
                  if (checkBox.isSelected())
                  {
                      message += "you picked option 1";
                  }
              if (checkBox2.isSelected())
                  {
                      message += "you picked option 2";
                  }   
  
              //for panel2 adds checkboxes
              panel2.add(checkBox);
              panel2.add(checkBox2);
  
              //makes a new label, text area and field
              JLabel label = new JLabel("This is a label");
              JTextArea textArea = new JTextArea("this is a text area");
              JTextField textField = new JTextField("text field");
  
              //makes an invisible grid
              GridBagConstraints grid = new GridBagConstraints();
              grid.insets = new Insets(15, 15, 15, 15);
  
              //sets the the coordinates 0,0. adds the label, and sets position
              grid.gridx = 0;
              grid.gridy = 0;
              panel3.add(label, grid);
  
              //sets the the coordinates 0,1. adds the textArea, and sets position
              grid.gridx = 0;
              grid.gridy = 1;
              panel3.add(textArea, grid);
  
              //sets the the coordinates 0,2. adds the text field, and sets position
              grid.gridx = 0;
              grid.gridy = 2;
              panel3.add(textField, grid);
  
              //adds each PANEL to the FRAME and positions it
              frame.add(panel1, BorderLayout.SOUTH);
              frame.add(panel3, BorderLayout.CENTER);
              frame.add(panel2, BorderLayout.NORTH);
  
          }
  }
  </code></pre>
  
  <p>The error message I'm receiving is:</p>
  
  <p>"FirstWindow.java:12: error: non-static variable message cannot be referenced from a static context
              message = "goodjob \n";"</p>
  
  <p>for lines 12, 37, 53, 57. I've tried declaring the String variable in the main but then I will just receive the error:</p>
  
  <p>"FirstWindow.java:38: error: local variables referenced from an inner class must be final or effectively final JOptionPane.showMessageDialog(null, message);"</p>
  
  <p>How to solve this problem?</p>