Java ---无需破解(最简洁版)使用javafx

1,这里主要用于跳转到浏览页界面

public class JavaFXBrower {
	private static final int WIDTH = 800;
	private static final int HEIGHT = 600;
	
	/**
	 * 在构造函数中调用
	 * @param url
	 */
	public JavaFXBrower(String url) {
		JFrame frame = new JFrame("JavaFX 浏览器");
		final JFXPanel webBrowser = new JFXPanel();
		frame.setLayout(new BorderLayout());
		frame.add(webBrowser, BorderLayout.CENTER);
		
		//刷新UI
		Platform.runLater(new Runnable() {

			@Override
			public void run() {
				Group root = new Group();
				Scene scene = new Scene(root, WIDTH, HEIGHT);
				webBrowser.setScene(scene);
				Double widthDouble = new Integer(WIDTH).doubleValue();
				Double heightDouble = new Integer(HEIGHT).doubleValue();
				//调用WebView组件
				WebView view = new WebView();
				view.setMinSize(widthDouble, heightDouble);
				view.setPrefSize(widthDouble, heightDouble);
				WebEngine eng = view.getEngine();
				
				eng.load(url);
				root.getChildren().add(view);

			}
		});

		int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
		int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
		frame.setSize(WIDTH, HEIGHT);
		frame.setLocation((screenWidth - WIDTH) / 2, (screenHeight - HEIGHT) / 2);
		frame.setVisible(true);
	}
}

 

你可能感兴趣的:(java)