2016-12-01 65 views
1

我不明白爲什麼eclipse自從導入它後將無法識別EventHandler。這裏是我的代碼: 包應用程序;當我嘗試在Java中爲視頻媒體播放器創建播放按鈕時發生EventHandler錯誤

import java.awt.event.ActionEvent; 

import com.sun.glass.ui.Accessible.EventHandler; 

import javafx.geometry.Insets; 
import javafx.geometry.Pos; 
import javafx.scene.control.Button; 
import javafx.scene.control.Label; 
import javafx.scene.control.Slider; 
import javafx.scene.layout.HBox; 
import javafx.scene.layout.Priority; 
import javafx.scene.media.MediaPlayer; 

public class MediaBar extends HBox { 


    Slider time =new Slider(); 

    Slider vol =new Slider(); 

    Button playButton=new Button("||"); 
    Label volume=new Label("Volume"); 
    MediaPlayer player; 

    public MediaBar(MediaPlayer play){ 
     player=play; 

     setAlignment(Pos.CENTER); 
     setPadding(new Insets(5,10,5,10)); 
     vol.setPrefWidth(70); 
     vol.setMin(30); 
     vol.setValue(100); 

     HBox.setHgrow(time, Priority.ALWAYS); 

     playButton.setPrefWidth(30); 

     getChildren().add(playButton); 
     getChildren().add(time); 
     getChildren().add(volume); 
     getChildren().add(vol); 


     playButton.setOnAction(new EventHandler<ActionEvent>(){ 
      public void handle(ActionEvent e){ 
       Status status=player.getStatus(); 

       if(status==Status.Playing){ 
        if(player.getCurrentTime().greaterThanOrEqualTo(player.getTotalDuration())){ 
         player.seek(player.getStartTime()); 
         player.play(); 
      } 
        else{ 
         player.pause(); 
         playerButton.setText(">"); 
        } 
      } 
      if(status==Status.PAUSE ||status==Status.HALTED||status==Status.STOPPED){ 
       player.play(); 
       playButton.setText("||"); 
      } 

      } 

     }); 
    } 

} 

以下是錯誤消息:

The type Accessible.EventHandler is not generic; it cannot be parameterized with arguments <ActionEvent> 

我在做什麼錯?

回答

3

糾正你使用JavaFX不能搖擺/ AWT進口:

取代:

import java.awt.event.ActionEvent; 
import com.sun.glass.ui.Accessible.EventHandler; 

有:

import javafx.event.ActionEvent; 
import javafx.event.EventHandler; 

避免自動進口還是要注意要導入的!

相關問題