actionlistener无法正常工作

时间:2012-02-15 22:45:06

标签: java button jbutton

尝试调用方法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"));
}

1 个答案:

答案 0 :(得分:3)

getuserInput()被声明为static。您必须使用类名称NameOfYourClass.getuserInput();

来引用它