Use JavaFX to create a MQTT client desktop program that can subscribe and publish

      Using JavaFX, we can create desktop programs like Swing. The specific introduction to JavaFX can be found on Baidu. Here I mainly introduce the use of JavaFX to create a desktop program to link the MQTT server. The MQTT server uses apache-apollo. You can go to the official website http://activemq.apache.org/apollo/download.html to download, the installation process can refer to http://jingyan.baidu.com/article/d45ad148b8efb769542b8066.html?st=2&net_type=&bd_page_type=1&os=0&rst= &word=%E6%80%8E%E6%A0%B7%E7%A7%9F%E6%9C%8D%E5%8A%A1%E5%99%A8 , the selected MQTT framework is paho, and the download address is http://www.eclipse.org/paho , when creating a JavaFX desktop program, we can visually create a desktop client by dragging. The tool used is SceneBuilder, and its download address is http://gluonhq. com/products/scene-builder/ , because my development system is windows, so I choose to download the windows Installer, anyway, according to my own needs.

     Next, we can create a JavaFX project. The development tool I choose is IntelliJ Idea. We can directly choose to create a JavaFX project when creating a project. For the convenience of packaging, I directly change the project to For projects that support maven, you can right-click on the JavaFX project and select "Add Frameworks Support"--->"Maven" to convert it to a maven-supported project. After completing the above steps, you can use the SceneBuilder tool to draw the interface diagram. I The interface after drawing is as follows:



      For each label and button, after defining the fx:id in the fxml file, the corresponding variables and methods must be defined in the controller, and the name and fx:id must be the same to take effect, otherwise an error will be reported when starting, the specific code It is not analyzed in the article. You can refer to my code. You can download the rar package here or download it from my git https://github.com/422518490/mqtt-client .

     Updates are as follows:

    The position of the button and table of the client has been updated on git to display the support for changing the size and the fixed size on both sides cannot be dragged.

     

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326458490&siteId=291194637