如何从FXML控制器类向主应用程序类发送消息

时间:2015-11-08 04:42:55

标签: java fxml ooad

Hello stackoverflowers,

我有一个问题"我有一个fxml文件" CrawlerView.fxml"及其控制器" CrawlerController.java"我想要从控制器类向主Application类发送Message(数据库插入)的主Application类(因为我无法在GUI / fxml控制器类中执行业务逻辑)。所以我的问题是:是否可以将消息从fxml控制器类发送到主应用程序类" 代码如下 任何帮助 提前谢谢

Crawler.java

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.effect.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="628.0" prefWidth="600.0"     xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1"     fx:controller="app.model.main.CrawlerController">
   <children>
      <SplitPane dividerPositions="0.14424635332252836" layoutX="8.0" layoutY="-2.0" orientation="VERTICAL" prefHeight="628.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <items>
          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
           <children>
              <Label layoutX="105.0" layoutY="14.0" prefHeight="52.0" prefWidth="388.0" text="Khurasani Web Crawler" textFill="#792323">
                 <font>
                    <Font name="Bauhaus 93" size="34.0" />
                 </font>
              </Label>
           </children>
        </AnchorPane>
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
           <children>
              <TextField id="URL" fx:id="URL" alignment="CENTER" blendMode="DARKEN" layoutX="110.0" layoutY="25.0" prefHeight="34.0" prefWidth="359.0" text="Enter URL">
                 <font>
                    <Font name="Berlin Sans FB Demi Bold" size="17.0" />
                 </font>
                 <effect>
                    <InnerShadow choke="0.56" color="#722424" height="26.93" radius="12.965" width="26.93" />
                 </effect>
              </TextField>
              <Button id="SEARCH" fx:id="SEARCH" layoutX="247.0" layoutY="82.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="79.0" text="Search" textFill="#5e2929">
                 <font>
                    <Font name="Arial Black" size="15.0" />
                 </font>
              </Button>
           </children>
        </AnchorPane>
    </items>
  </SplitPane>

CrawlerView.fxml

package app.model.main;


import java.net.URL;
import java.sql.Statement;
import java.util.ResourceBundle;
import java.util.Stack;


import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

public class CrawlerController implements Initializable
{

    @FXML Button SEARCH;
    @FXML TextField URL; 


@Override // This method is called by the FXMLLoader when initialization is complete
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
    assert SEARCH != null : "fx:id=\"myButton\" was not injected: check your FXML file 'simple.fxml'.";


   SEARCH.setOnAction(new EventHandler<ActionEvent>() {

    @Override
    public void handle(ActionEvent event) 
    {

         //How to send message to main application class 
    }
});}



}

CrawlerController

files <- c('file001.csv', 'file002.csv', 'file003.csv', 'file004.csv')

0 个答案:

没有答案
相关问题