My error is on line 23-24. non-static variable cannot be referenced from a static context
I know why I am getting the error but I don't know how to fix it in this case:
import javax.swing.*;
import java.awt.event.*;
import java.awt.AWTEvent;
import java.awt.MouseInfo;
import java.awt.Toolkit;
public class VideoGamerEvent implements ActionListener {
VideoGamer gui;
String theEvent;
String theCoords;
public VideoGamerEvent(VideoGamer in){
gui = in;
}
public static class Listener implements AWTEventListener {
public void eventDispatched(AWTEvent event) {
System.out.print(MouseInfo.getPointerInfo().getLocation() + " | ");
System.out.println(event);
//error here
theEvent = event.toString();
theCoords = MouseInfo.getPointerInfo().getLocation().toString();
//end error
}
}
public void actionPerformed(ActionEvent e){
if(theEvent.contains("FOCUS_LOST")){
gui.coords.setText(theCoords);
}
}
}
I need to eventually get theCoords into a JTextField (gui.coords).