4
我使用Eclipse IDE作爲Java開發人員,開普勒服務版本2,jdk1.8.0作爲JRE安裝。令牌「 - 」上的語法錯誤, - 預期
我使用Java中的所有功能於一身的傻瓜學習Java SE 8,並編寫程序時,使用搖擺,我收到此錯誤:syntax error on token "-", -- expected
有了這個代碼:
button1 = new JButton("Click me!");
button1.addActionListener(e -> button1Click());
panel1.add(button1);
exitButton = new JButton("Exit");
exitButton.addActionListener(e -> exitButtonClick());
panel1.add(exitButton);
this.add(panel1);
button1和exitButton已經被聲明爲JButton,並且我已經導入了javax.swing。*和java.awt.event。*。
我該如何解決這個問題?
什麼'e'?它是什麼? –
是否將Java 8設置爲目標(err,「源」)語言? – user2864740
順便提一句,你可以使用方法引用。確保你的'button1Click'(例如)方法接受一個'ActionEvent',然後將'MyClass :: button1Click'傳遞給該方法。 –