Last active
April 1, 2019 18:56
-
-
Save knappologi/c0de5ef8e5a767e720a840d820eb3e55 to your computer and use it in GitHub Desktop.
Installera Java, Eclipse och JavaFx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ----------- Eclipse ----------- | |
| ------------------------------- | |
| 1. Uppdatera Eclipse till senaste versionen | |
| 2. Hämta JDK 12 https://www.oracle.com/technetwork/java/javase/downloads/jdk12-downloads-5295953.html och installera | |
| 3. Hämta JavaFx 11 https://gluonhq.com/products/javafx/ | |
| 4. Zippa upp JavaFx och placera mappen på lämplig plats, | |
| där den kan hittas | |
| 5. Följ JavaPoints guide för JavaFx och Eclipse: | |
| https://www.javatpoint.com/javafx-with-eclipse | |
| 5a: För ett projekt, högerklicka projektmappen -> Properties -> Java build path -> Libraries | |
| 5b: Klicka Add External JARs... | |
| 5c: User library | |
| 5d: New och ge biblioteket ett namn (som "JavaFx") | |
| 5e: Markera det nya biblioteket och klicka Add External JARs... | |
| 5f: välj alla JAR-filer från javafx-mappens lib | |
| 5g: apply & close | |
| 6. Gör en klass och kör testkod för att kontrollera att det fungerar | |
| ----------- Intellij ----------- | |
| -------------------------------- | |
| 1. Ladda hem JDK och JavaFx 11 https://gluonhq.com/products/javafx/ | |
| 2. Zippa upp JavaFx och placera mappen på lämplig plats, | |
| där den kan hittas | |
| 3. I Intellij, skapa ett nytt global library: | |
| Project settings -> Global library -> + (skapa nytt) -> Java | |
| 4. Välj alla JAR-filer från JavaFx-mappens lib | |
| 5. Ge biblioteket ett namn | |
| För projektet som ska använda JavaFX: | |
| 1. Högerklicka på projektets mapp i Intellij, välj Open module settings | |
| 2. Under Global Libraries, högerklicka biblioteket för JavaFx och välj Add to modules... | |
| 3. Testa köra kod för att kontrollera om det fungerar. | |
| Om meddelande som "Error:(3, 26) java: cannot access javafx.application.Application | |
| bad class file: C:\Program Files\Java\OpenJDK\javafx-sdk-11.0.1\lib\javafx.graphics.jar(javafx/application/Application.class) class file has wrong version 54.0, should be 52.0 | |
| Please remove or make sure it appears in the correct subdirectory of the classpath.", | |
| gör följande: | |
| 1. Högerklicka på projektmappen, välj Open module settings -> Project | |
| 2. I dropdown för Project language level, välj 11 (eller 10) | |
| --------------------------------- | |
| ----------- testkod ------------- | |
| Testkod för HelloWorld i fx: | |
| https://docs.oracle.com/javafx/2/get_started/hello_world.htm | |
| import javafx.application.Application; | |
| import javafx.event.ActionEvent; | |
| import javafx.event.EventHandler; | |
| import javafx.scene.Scene; | |
| import javafx.scene.control.Button; | |
| import javafx.scene.layout.StackPane; | |
| import javafx.stage.Stage; | |
| public class HelloFx extends Application { | |
| public static void main(String[] args) { | |
| launch(args); | |
| } | |
| @Override | |
| public void start(Stage primaryStage) { | |
| primaryStage.setTitle("Hello World!"); | |
| Button btn = new Button(); | |
| btn.setText("Say 'Hello World'"); | |
| btn.setOnAction(new EventHandler<ActionEvent>() { | |
| @Override | |
| public void handle(ActionEvent event) { | |
| System.out.println("Hello World!"); | |
| } | |
| }); | |
| StackPane root = new StackPane(); | |
| root.getChildren().add(btn); | |
| primaryStage.setScene(new Scene(root, 300, 250)); | |
| primaryStage.show(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment