尝试调用方法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/