JavaFX按钮事件处理程序编译错误

时间:2017-09-10 04:57:41

标签: button javafx eventhandler

我的一段代码

p + q

下一个语句的错误是

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>(){})

1 个答案:

答案 0 :(得分:1)

因为您尝试将awt包的ActionEvent添加到javaFx组件&#34; node&#34;。将import java.awt.event.ActionEvent;更改为import javafx.event.ActionEvent