2017-09-10 3 views
0

자바 FX 버튼 이벤트 핸들러 컴파일 오류

package scr; 

import java.awt.event.ActionEvent; 
import java.io.DataInputStream; 
import java.io.DataOutputStream; 
import java.io.IOException; 
import java.net.Socket; 
import java.net.UnknownHostException; 

import javafx.application.Application; 
import javafx.beans.value.ChangeListener; 
import javafx.beans.value.ObservableValue; 
import javafx.event.EventHandler; 
import javafx.fxml.FXML; 
import javafx.geometry.Insets; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.Control; 
import javafx.scene.control.Dialogs; 
import javafx.scene.control.ListView; 
import javafx.scene.control.ScrollPane; 
import javafx.scene.control.TextArea; 
import javafx.scene.control.TextField; 
import javafx.scene.layout.BorderPane; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 


public class Client extends Application implements Runnable{ 

    @FXML 
    private TextArea chatHistory; 
    private TextField txtMessage ; 




    // define the socket and io streams 
    Socket client; 
    DataInputStream dis; 
    DataOutputStream dos; 


    @Override 
    public void start(Stage stage) throws Exception { 
     String input = Dialogs.showInputDialog(stage, "Please enter your name:", "Input Dialog", "title"); 
     BorderPane root = new BorderPane(); 
      VBox vb = new VBox(); 
      vb.setSpacing(10); 

      TextArea chatHistory = new TextArea(); 
      vb.getChildren().add(chatHistory); 


      TextField txtMessage=new TextField() ; 
      vb.getChildren().add(txtMessage); 

      Button btnSend = new Button(); 
      btnSend.setText("Send"); 
      vb.getChildren().add(btnSend); 

      ListView<String> lvList = new ListView<String>(); 
     // lvList.setItems(items); 
      lvList.setMaxHeight(Control.USE_PREF_SIZE); 

      vb.setPadding(new Insets(10, 10, 10, 10)); 
      root.setTop(vb); 
      root.setRight(lvList); 
       // Set margin for top area. 
      BorderPane.setMargin(vb, new Insets(10, 10, 10, 10)); 

오류 다음 문에 대한 내 코드의 조각은

Multiple markers at this line 
    - Bound mismatch: The type ActionEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T> 
    - The method setOnAction(EventHandler<ActionEvent>) in the type ButtonBase is not applicable  for the arguments (new EventHandler<ActionEvent>(){}) 
//btnSend event 
      btnSend.setOnAction(new EventHandler<ActionEvent>() { 

      public void handle(ActionEvent event){ 

         try { 
          dos.writeInt(ServerConstants.CHAT_MESSAGE); // determine the type of message to be sent 
          dos.writeUTF(txtMessage.getText()); // message payload 

          dos.flush(); // force the message to be sent (sometimes data can be buffered) 
         } 
         catch (IOException e){ 
          e.printStackTrace(); 
         } 

      } 
      }); 
+0

더 이상 유효하지 않습니다! – Nadia

+0

람다 표현식이 익명 클래스보다 낫습니다. –

답변

1

입니다 구성 요소 "노드". 변경 import java.awt.event.ActionEvent;import javafx.event.ActionEvent