javafx java_JavaFX与Java互操作性

JavaFX中使用的scenegraph是OpenSource。你可以在这里查一下(

https://scenegraph.dev.java.net

)虽然该站点尚未更新以反映Javafx1.x附带的最终版本,但您仍然可以使用JavafxSDK附带的JAR,并在Swing应用程序中混合scenegraph和Swing节点。但是,您会遇到一些困难,因为这个版本的scenegraph没有官方的API。

这里有一个“你好世界”,使用Javafx1.0提供的scenegraph。记住在构建路径中包含“scenario.jar”。

import java.awt.Color;

import java.awt.Paint;

import java.awt.geom.Point2D;

import javax.swing.JFrame;

import javax.swing.SwingUtilities;

import com.sun.scenario.scenegraph.JSGPanel;

import com.sun.scenario.scenegraph.SGGroup;

import com.sun.scenario.scenegraph.fx.FXText;

public class HelloWorldScenario101 implements Runnable {

/**

* @param args

*/

public static void main(String[] args) {

SwingUtilities.invokeLater(new HelloWorldScenario101());

}

public HelloWorldScenario101() {

//

}

@Override

public void run() {

this.frame = new JFrame();

this.panel = new JSGPanel();

this.text = new FXText();

this.paint = new Color(255, 0, 0, 255);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setTitle("Hello World");

frame.add(this.panel);

frame.setContentPane(this.panel);

scene = new SGGroup();

this.text.setText("Hello World");

this.text.setFillPaint(this.paint);

this.text.setLocation(new Point2D.Float(10, 10));

this.scene.add(this.text);

this.panel.setScene(scene);

frame.pack();

frame.setLocationByPlatform(true);

frame.setVisible(true);

}

private JFrame frame;

private JSGPanel panel;

private SGGroup scene;

private FXText text;

private Paint paint;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值