title: Java: addActionListener(); not working
body: <p>I'm trying to create a launcher for a game, let's say PowerTown. But when i try to create a ActionListener for the button, it says non-static variable cannot be referenced from a static context. How do I fix this?</p>
  
  <pre><code>package powertown;
  
  import java.io.*;
  import java.awt.*;
  import java.awt.event.ActionEvent;
  
  import javax.swing.*;
  
  public class PowerTown {
  
  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) 
      implements ActionListener; {
      //Start Varibles
      String path = ClassLoader.getSystemClassLoader().getResource(".").getPath();
      if (!new File(path + "PowerTownSave.txt").exists()) {
          System.out.println("Creating save file...");
          File f = new File(path + "PowerTownSave.txt");
          f.getParentFile().mkdirs();
          try {
              f.createNewFile();
              try {
                  BufferedWriter out = new BufferedWriter(new FileWriter(path + "PowerTownSave.txt"));
                  out.write("Coals \n");
                  out.newLine();
                  out.write("1 \n");
                  out.newLine();
                  out.write("Oils \n");
                  out.newLine();
                  out.write("0 \n");
                  out.newLine();
                  out.write("Bios \n");
                  out.newLine();
                  out.write("0 \n");
                  out.newLine();
                  out.write("Winds \n");
                  out.newLine();
                  out.write("0 \n");
                  out.newLine();
                  out.write("Sols \n");
                  out.newLine();
                  out.write("0 \n");
                  out.newLine();
                  out.write("Nukes \n");
                  out.newLine();
                  out.write("0 \n");
                  out.newLine();
                  out.write("Money \n");
                  out.newLine();
                  out.write("50 \n");
                  out.newLine();
                  out.write("Power \n");
                  out.newLine();
                  out.write("0 \n");
                  out.newLine();
                  out.write("Customers \n");
                  out.newLine();
                  out.write("5 \n");
                  out.newLine();
                  out.write("Storage \n");
                  out.newLine();
                  out.write("10 \n");
                  out.newLine();
                  out.write("AvgUse \n");
                  out.newLine();
                  out.write("1 \n");
                  out.newLine();
                  out.write("Time \n");
                  out.newLine();
                  out.write("0 \n");
                  out.newLine();
                  out.write("Reputation \n");
                  out.newLine();
                  out.write("0 \n");
                  out.newLine();
                  out.write("Protests \n");
                  out.newLine();
                  out.write("0 \n");
                  out.newLine();
                  out.write("Coal Supply \n");
                  out.newLine();
                  out.write("800 \n");
                  out.newLine();
                  out.write("Coal Demand \n");
                  out.newLine();
                  out.write("30 \n");
                  out.newLine();
                  out.write("Oil Supply \n");
                  out.newLine();
                  out.write("100 \n");
                  out.newLine();
                  out.write("Oil Demand \n");
                  out.newLine();
                  out.write("9 \n");
                  out.newLine();
                  out.write("Bio Supply \n");
                  out.newLine();
                  out.write("7 \n");
                  out.newLine();
                  out.write("Bio Demand \n");
                  out.newLine();
                  out.write("3 \n");
                  out.newLine();
                  out.write("Nukes Supply \n");
                  out.newLine();
                  out.write("5 \n");
                  out.newLine();
                  out.write("Nukes Demand \n");
                  out.newLine();
                  out.write("3 \n");
                  out.newLine();
                  out.write("Disaster probrobility \n");
                  out.newLine();
                  out.write("0");
                  out.newLine();
                  out.close();
              } catch (IOException e) {
                  System.out.println("Failed to create save file, check your permisions. Are you admin? Are you root?");
              }
          } catch (IOException e) {
              System.out.println("Failed to create save file, check your permisions. Are you admin? Are you root?");
              return;
          }
      } else {
          System.out.println("Save file found!");
      }
      System.out.println("Current readout of file will proceed, if file is empty, go to " + path + " , and then delete that file. After that, rerun the program.");
      try (BufferedReader br = new BufferedReader(new FileReader(path + "PowerTownSave.txt"))) {
          StringBuilder sb = new StringBuilder();
          String line = br.readLine();
  
          while (line != null) {
              sb.append(line);
              sb.append(System.lineSeparator());
              line = br.readLine();
          }
          String fileReadout = sb.toString();
          System.out.println(fileReadout);
      } catch (IOException e) {
  
      }
      System.out.println("Startup save pickup has finished.");
      System.out.println("Attemptng to create a launch window... Please wait.");
      JFrame frame = new JFrame("PwrTwn Launcher");
      System.out.println("Created new frame!");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      System.out.println("Set to terminate when closed...");
      JButton startButton = new JButton("Launch");
      startButton.addActionListener(this);
      System.out.println("Created new JButton!");
      startButton.setVerticalTextPosition(AbstractButton.BOTTOM);
      startButton.setHorizontalTextPosition(AbstractButton.CENTER);
      System.out.println("Set alignment for JButton!");
      frame.setPreferredSize(new Dimension(300, 150));
      System.out.println("Set Frame size!");
      startButton.setSize(new Dimension(60, 20));
      System.out.println("Set JButton size!");
      frame.getContentPane().add(startButton, BorderLayout.CENTER);
      System.out.println("Packaging...");
      frame.pack();
      frame.setVisible(true);
      System.out.println("Launch window created!");
  }
  
  public void actionPerformed(ActionEvent e) {
  //some witty stuff goes here
      }
   }
  </code></pre>