2013-08-13 2 views
-1

SCHEDULE이 항상 밑줄을 긋고 작동하지 않는 이유를 이해하지 못합니다 (클래스로 분리하려고했는데 똑같은 문제가있는 곳에서 문제를 해결할 수 없습니다.) @@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@On time clicker 자바 코드 오류

import java.awt.*; 
    import java.awt.event.*; 
    import java.util.*; 
    import javax.swing.*; 


    public class assertion extends JFrame { 

    JTextField curTime, xT, yT; 
    Timer timer; 

    public static void main(String[] args){ 

     new assertion(); 

    } 


    public assertion() { 

     JFrame window = new JFrame("ВИ Кликер"); 
     window.setSize(400,400); 

     JPanel mainframe=new JPanel(); 
      window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 




      JLabel x=new JLabel(); 
      x.setText("X-Coordinate"); 
      mainframe.add(x); 

      xT=new JTextField(10); 
      mainframe.add(xT); 
      window.getContentPane().add(mainframe); 
      window.pack(); 
      window.setVisible(true); 



      JLabel y=new JLabel(); 
      y.setText("Y-Coordinate"); 
      mainframe.add(y); 

      yT=new JTextField(10); 
      mainframe.add(yT); 
      window.getContentPane().add(mainframe); 
      window.pack(); 
      window.setVisible(true); 



      JLabel time=new JLabel(); 
      time.setText("Time"); 
      mainframe.add(o); 

      curTime = new JTextField(10); 
      mainframe.add(curTime); 
      window.getContentPane().add(mainframe); 
      window.pack(); 
      window.setVisible(true); 




      JButton gO =new JButton(); 
      gO.setText("GO"); 
      mainframe.add(gO); 


      gO.addActionListener(new ActionListener(){ 
      public void actionPerformed(ActionEvent e){ 
     timer(); 
      } 
      }); 


    } 


    public void timer(){ 


     Calendar calendar = Calendar.getInstance(); 
     calendar.set(Calendar.HOUR_OF_DAY, 23); 
     calendar.set(Calendar.MINUTE, 1); 
     calendar.set(Calendar.SECOND, 0); 
     Date time = calendar.getTime(); 

     timer = new Timer(); 
     timer.schedule(new assertion(), time); 

    } 

    public void mouse() throws AWTException { 

     String xx = xT.getText(), yy = yT.getText(); 
     int xxx = Integer.parseInt(xx), yyy = Integer.parseInt(yy); 


     Robot robot = new Robot(); 
     robot.mouseMove(xxx, yyy); 
     robot.mousePress(InputEvent.BUTTON1_MASK); 
     robot.mouseRelease(InputEvent.BUTTON1_MASK); 
    } 


    } 
+0

"_ 작동하지 않음"은 정보가 아닙니다. 질문에 완전한 오류 메시지를 포함하는 것을 잊지 마십시오. – jlordo

+0

SCHEDULE은 항상 밑줄을 긋고 작동하지 않습니다. - 실제로 실행할 수 없다는 것을 의미합니다. SCHEDULE – Denzw

+0

단어 위로 마우스를 가져 가면 의미있는 오류 메시지가 나타납니다. . 여기에 게시하십시오. – jlordo

답변

1

클래스 Timer이 모호 timer.schedule 그래서 java.util.Timer 사이 javax.swing.Timer가 해결 될 수 없다.

패키지 가져 오기를 제거

import java.util.*; 

만은

import java.util.Calendar; 

javax.swing.Timer는이 설명하기 위해 코드를 리팩토링해야합니다 수 있도록 스윙에 사용할 올바른 Timer 예를 들어, 당신이 특별히 필요한 클래스를 가져옵니다. assertion의 새 인스턴스를 만들 필요가 없습니다. 모든 메서드가 스윙 타이머 ActionListener으로 호출되도록하십시오. 이외에도

Timer timer = new Timer(1000, new ActionListener() { 

    @Override 
    public void actionPerformed(ActionEvent e) { 
     // perform timer actions 
    } 
}); 

: 자바 명명 규칙은 클래스가 대문자 문자, 예를 들어, 시작 것을 보여 Assertion

+0

그래, 그 문제를 해결하지만, 이제는 일정을 가져올 필요가 있습니다. 구체적으로 날짜를 가져오고 밑줄을 다시 입력하면 – Denzw

+1

충돌을 피하기 위해 java.util에서 필요한 특정 클래스를 가져옵니다. – Reimeus

+0

여전히 DATE ((그리고 내가 다시 밑줄이 그어진 DATE 스케줄을 위해 특별히 추가 할 경우) – Denzw

1

어설 션은 필요한 TimerTask를 확장하지 않습니다.

내가 다른 질문 스레드에서 보여준 것처럼 익명의 클래스를 만드십시오.