2012-02-15 9 views
0

getuserinputメソッドを呼び出すときにエラーが発生します。ここに私の壊れたコードのビットがあります。actionlistenerが動作しない

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")); 
} 

答えて

3

getuserInput()staticとして宣言されています。クラス名を使用して参照する必要があります。NameOfYourClass.getuserInput();

+0

申し訳ありませんが、クラス名がわかりません。私はMain.getusername()を試しました;私はactionPerformed.getuserinput();を試しました。もう少し説明してください。 – user1183685

+0

@ user1183685 [基本的なレビューをする]時間がかかるかもしれません(http://docs.oracle.com /javase/tutorial/java/concepts/class.html)。 – Jeffrey

+0

これは 'class'キーワードと貼り付けたメソッドの上のどこかのソースコードの' {'シンボルに続く単語です。ソースコードファイルの名前と同じものが使用されている可能性があります。 Javaチュートリアルのクラスの宣言について詳しくは:http://docs.oracle.com/javase/tutorial/java/javaOO/classdecl.html –

関連する問題