在 if 语句中,找不到 launchBtn。我可能正在做一些愚蠢的事情。任何人都可以看到有什么问题吗?错误以粗体显示(或用两个 ** 突出显示,这是我的代码:
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);
}
}
}