當我嘗試在Eclipse中編譯/啓動我的程序時,出現錯誤No enclosing instance of type mainframeclass is accessible
。下面是代碼:沒有可訪問的類型主機類的封閉實例
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");
}
}
}
看來,我做了一些錯誤的:
actionlistener listen = new actionlistener();
,但我不知道是什麼。我是Java新手,希望對此問題有所瞭解。謝謝。