群晖打开wordpress4.9.8,邯郸seo营销,建网站公司是如何赚钱,自做头像的网站java-快速将普通main类变为javafx类#xff0c;并加载自定义fxml 前提步骤1. 普通类继承Application2. 实现main方法3. 写一个controller4. 写一个fxml文件5. 写start方法加载fxml6. 具体代码7. 运行即可 前提
使用自带javafx的jdk#xff0c;这里使用的是jdk1.834#xff… java-快速将普通main类变为javafx类并加载自定义fxml 前提步骤1. 普通类继承Application2. 实现main方法3. 写一个controller4. 写一个fxml文件5. 写start方法加载fxml6. 具体代码7. 运行即可 前提
使用自带javafx的jdk这里使用的是jdk1.834当然你可以使用其他的可行版本。
步骤
1. 普通类继承Application public class server extends Application { 2. 实现main方法 public static void main(String[] args) {launch();}3. 写一个controller
普通类实现implements Initializable即可
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;import java.net.URL;
import java.util.ResourceBundle;public class controller implements Initializable {FXMLprivate TextArea allStatus;FXMLprivate TextArea pkRecord;FXMLprivate Label mount;FXMLprivate Label monitorStatus;Overridepublic void initialize(URL location, ResourceBundle resources) {System.out.println(2222);}
}
4. 写一个fxml文件
将fxml文件放在项目的resources目录下后面好引用。另外重要的是在GridPane节点上增加和controller类的关系使用fx:controller“controller”
?xml version1.0 encodingUTF-8??import javafx.geometry.*?
?import javafx.scene.control.*?
?import java.lang.*?
?import javafx.scene.layout.*?GridPane fx:controllercontroller maxHeight-Infinity maxWidth-Infinity minHeight-Infinity minWidth-Infinity prefHeight400.0 prefWidth600.0 xmlnshttp://javafx.com/javafx/8 xmlns:fxhttp://javafx.com/fxml/1columnConstraintsColumnConstraints hgrowSOMETIMES maxWidth302.0 minWidth10.0 prefWidth158.0 /ColumnConstraints hgrowSOMETIMES maxWidth324.0 minWidth10.0 prefWidth285.0 /ColumnConstraints hgrowSOMETIMES maxWidth140.0 minWidth10.0 prefWidth140.0 //columnConstraintsrowConstraintsRowConstraints maxHeight128.0 minHeight4.0 prefHeight4.0 vgrowSOMETIMES /RowConstraints maxHeight303.0 minHeight10.0 prefHeight303.0 vgrowSOMETIMES /RowConstraints maxHeight124.0 minHeight10.0 prefHeight41.0 vgrowSOMETIMES //rowConstraintschildrenTextArea fx:idallStatus prefHeight200.0 prefWidth200.0 GridPane.columnIndex1 GridPane.rowIndex1GridPane.marginInsets right10.0 //GridPane.margin/TextAreaTextArea fx:idpkRecord prefHeight200.0 prefWidth200.0 GridPane.rowIndex1GridPane.marginInsets left10.0 right10.0 //GridPane.margin/TextAreaVBox alignmentTOP_CENTER prefHeight200.0 prefWidth100.0 GridPane.columnIndex2 GridPane.rowIndex1childrenLabel fx:idmount prefHeight36.0 prefWidth140.0 textLabelopaqueInsetsInsets //opaqueInsetsVBox.marginInsets bottom20.0 //VBox.margin/LabelLabel fx:idmonitorStatus prefHeight39.0 prefWidth140.0 textLabel //children/VBox/children
/GridPane
5. 写start方法加载fxml Overridepublic void start(Stage primaryStage) throws IOException {Parent root FXMLLoader.load(getClass().getResource(/monitor.fxml));primaryStage.setTitle(KeDD);primaryStage.setResizable(false);primaryStage.setScene(new Scene(root, 800, 500));primaryStage.show();}6. 具体代码
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.omg.CORBA.portable.ApplicationException;
import java.io.IOException;public class server extends Application {public static void main(String[] args) {launch();}Overridepublic void start(Stage primaryStage) throws IOException {Parent root FXMLLoader.load(getClass().getResource(/monitor.fxml));primaryStage.setTitle(KeDD);primaryStage.setResizable(false);primaryStage.setScene(new Scene(root, 800, 500));primaryStage.show();}
}
7. 运行即可
运行后会弹出窗口然后打印出上面的2222