Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the relationship between JavaFX function and Swing?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about the relationship between JavaFX functions and Swing. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

JavaFX contains many powerful functions that Java SE does not have, such as chart Charting, animation, media playback, RSS/Atom and so on, so programmers often discuss how to call JavaFX function in Java. In the JFXtras version of Stephen Chin's open source project, a wrapper class for JavaFX is provided, which can display the graphical elements of JavaFX (animations, diagrams, etc.) in Swing applications.

This is a very useful feature and good news for a wide range of Java (Swing) developers. The source code of JFXtras contains the relevant demo programs (SceneToJComponentScene.fx and SceneToJComponentTest.java). I modified the program to illustrate the problem.

/ * * MyScene.fx http://www.javafxblogs.com * @ authorHenryZhang * / packageswingtest; importjavafx.scene.Scene; importjavafx.scene.text.*; importjavafx.scene.paint.*; importjavafx.scene.shape.Rectangle; importjavafx.animation.Timeline; importjavafx.animation.KeyFrame; defw=500; defh=400; publicclassMySceneextendsScene {varxx=w/3; varyy=h/2; varrotate=0; vartext= "" Vartl=Timeline {repeatCount:Timeline.INDEFINITE keyFrames: [KeyFrame {time:70ms action:function () {text=JavaFXToSwingTest.tf.getText (); rotate= (rotate+5) mod360;}}]} overridevarcontent= [Rectangle {width:w,height:h fill:Color.BLUE}, Text {font:Font {size:24} layoutX:bindxx layoutY:bindyy rotate:bindrotate content:bindtext fill:Color.YELLOW}]; init {tl.play ();}}

1) in the above program, we use the code of JavaFX to poll the variable value of Java, in practice, this will lose a lot of performance, so we can take the initiative to notify JavaFX of the data change from the Java code. This requires a technique for calling javafx from Java, as you can see in my article: calling the JavaFX function with Java code.

2) it is feasible to call JavaFX in a Swing program, so how should such a program be compiled and run? In fact, the JavaFX function is just some jar files, so the way to combine with Java is relatively simple. There are two main ways to compile, one is to use JavaFX compiler javafxc to compile Java and JavaFX code. The second is to compile JavaFX code with javafxc and java code with javac. When running the program, we can choose the javafx or java command.

After reading the above, do you have any further understanding of the relationship between JavaFX functions and Swing? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report