2017-09-10 7 views
0

Ein Stück meines CodesJavaFX Schaltfläche Ereignishandler Kompilierungsfehler

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

Fehler für die nächste Anweisung ist

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

nicht mehr gültig VERKAUFT! – Nadia

+0

Verwenden Lambda-Ausdruck ist besser als anonyme Klasse. –

Antwort

1

Weil Sie versucht Action von AWT-Paket zu JavaFX hinzufügen Komponente "Knoten". Ändern import java.awt.event.ActionEvent; zu import javafx.event.ActionEvent

Verwandte Themen