在if语句中,找不到launchBtn。我可能做了一些愚蠢的事情。任何人都可以看到有什么不对?这些错误是大胆的(或有两个**,这里是我的代码高亮显示:Java - Actionlistener显示错误的原因我看不到
package launcher;
import java.awt.event.*;
import javax.swing.*;
@SuppressWarnings("serial")
class Window extends JFrame implements ActionListener
{
JPanel panel = new JPanel();
public Window()
{
//Creates the blank panel
super("Launcher");
setSize(500, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(panel);
setVisible(true);
//Create the button variables
JButton launchBtn = new JButton("Launch Game");
JButton optionsBtn = new JButton("Launcher Options");
//Add the buttons to the launcher
panel.add(launchBtn);
panel.add(optionsBtn);
//Add the buttons to the action listener
launchBtn.addActionListener(this);
optionsBtn.addActionListener(this);
}
public void actionPerformed(ActionEvent event)
{
if(event.getSource() == **launchBtn**)
{
**launchBtn**.setEnabled(true);
}
}
}
我知道这将是愚蠢的!谢谢。 –