I get the error No enclosing instance of type mainframeclass is accessible
when I try to compile/launch my program in Eclipse. Here is the code:
public class mainframeclass {
public static Object mainframemenuitem1;
public static void main(String[] args) {
JFrame mainframe = new JFrame(variables.mainframename);
mainframe.setLayout(new GridLayout());
mainframe.setSize(variables.mainframewith, variables.mainframeheight);
mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainframe.setVisible(variables.mainframevisible);
mainframe.setResizable(variables.mainframeresizable);
JMenuBar mainframemenubar = new JMenuBar();
JMenu mainframemenu = new JMenu("File");
JMenuItem mainframemenuitem1 = new JMenuItem("Exit");
mainframe.setJMenuBar(mainframemenubar);
mainframemenubar.add(mainframemenu);
mainframemenu.add(mainframemenuitem1);
actionlistener listen = new actionlistener();
mainframemenuitem1.addActionListener(listen);
runningclass.running();
}
public class actionlistener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == mainframemenuitem1)
System.out.println("Test");
}
}
}
It seems that I have done something wrong with the:
actionlistener listen = new actionlistener();
but I don't know what. I am new to Java and would appreciate any insight into this problem. Thanks.