这是一个
java程序,有两个按钮用于更改整数值并显示它.
但是在IntelliJIDEA中有两行
但是在IntelliJIDEA中有两行
increase.addActionListener(incListener()); decrease.addActionListener(decListener());
继续显示错误’预期方法调用’.
我不知道该怎么做才能解决这个问题.
任何帮助将不胜感激
谢谢
注意:完整代码附在下面.
import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Main extends JDialog { public JPanel contentPane; public JButton decrease; public JButton increase; public JLabel label; public int number; public Main() { setContentPane(contentPane); setModal(true); increase = new JButton(); decrease = new JButton(); increase.addActionListener(incListener()); decrease.addActionListener(decListener()); number = 50; label = new JLabel(); } public class incListener implements ActionListener { public void actionPerformed (ActionEvent event) { number++; label.setText("" + number); } } public class decListener implements ActionListener { public void actionPerformed (ActionEvent event) { number--; label.setText("" + number); } } public static void main(String[] args) { Main dialog = new Main(); dialog.pack(); dialog.setVisible(true); System.exit(0); } }