gpt4 book ai didi

java - Action 监听器不工作

转载 作者:行者123 更新时间:2023-12-02 00:29:47 28 4
gpt4 key购买 nike

尝试调用 getuserinput 方法时出现错误。这是我的部分已损坏的代码。

initialvelocitybutton.addActionListener(new ActionListener() { 
public void actionPerformed(ActionEvent e) {
getuserinput(); //I am getting an error saying "The method getuserinput() is undefined for the type new ActionListener(){}"
}
});

static void getuserinput(){ //method to get users input
double initialvelocity = Double.parseDouble(
JOptionPane.showInputDialog("please enter initial velocity")); //gets initial value of intiial velcoity
double angleoflaunch = Double.parseDouble(
JOptionPane.showInputDialog("please enter angle of launch"));
}

最佳答案

getuserInput() 被声明为static。您必须使用类名来引用它:NameOfYourClass.getuserInput();

关于java - Action 监听器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9302666/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com