Eclipse uses JavaFX to write a helloworkld

Source: Internet
Author: User
Tags gtk

————————————————————————————————————————————————

Operating system: Ubuntu18.04

eclipseversion:oxygen.3a Release (4.7.3a) Build id:20180405-1200

————————————————————————————————————————————————

Eclipse does not support JavaFX by default and does the following to enable access to JavaFX

1. Right-click the project->bildpath->configure Bild Path, select the Library tab, select Access rules, and click Edit on the right.

Click Add on the pop-up typeaccessrules form, pop-up the edit Access Rule form, resolution option select the Accessible,rule pattern option to fill in "javafx/**"

In this way, you can use JavaFX directly in Eclipse.

Write a HelloWorld try:

 Packagestart;Importjavafx.application.Application;Importjavafx.event.ActionEvent;ImportJavafx.event.EventHandler;ImportJavafx.scene.Scene;ImportJavafx.scene.control.Button;ImportJavafx.scene.control.Label;ImportJavafx.scene.image.Image;ImportJavafx.scene.layout.StackPane;ImportJavafx.stage.Stage; Public classStartextendsapplication{ Public Static voidMain (string[] args) {System.out.println ("Hello,world");    Launch (args); } @Override Public voidStart (Stage primarystage) {primarystage.settitle ("Hello world!"); Button btn=NewButton (); Btn.settext ("Say ' Hello World '"); Btn.setonaction (NewEventhandler<actionevent>() {@Override Public voidhandle (ActionEvent event) {System.out.println ("Helloworld!");                          }             }); Stackpane Root=NewStackpane ();             Root.getchildren (). Add (BTN); Primarystage.setscene (NewScene (Root, 300, 250));          Primarystage.show (); }  }

Note that there is a gtk-message that says "Canberra-gtk-module" cannot be loaded

The solution is as follows:

Open Terminal execute the following command to install the module can be

sudo apt-get install Libcanberra-gtk-module

Run again, snap alive.

Eclipse uses JavaFX to write a helloworkld

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.