2012-02-15 2 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 –

관련 문제