├── .github └── FUNDING.yml ├── .gitignore ├── CHANGES.md ├── Chapter_01_Introduction └── README.md ├── Chapter_02_Tools ├── README.md ├── javafx-resistors │ ├── README.md │ ├── pom.xml │ ├── screenshots │ │ ├── javafx-led-resistor-value.png │ │ ├── javafx-resistor-value-330.png │ │ └── javafx-table.png │ ├── src │ │ └── main │ │ │ └── java │ │ │ ├── be │ │ │ └── webtechie │ │ │ │ └── resistors │ │ │ │ ├── App.java │ │ │ │ └── views │ │ │ │ ├── BandCalculator.java │ │ │ │ ├── ColorsTableView.java │ │ │ │ └── LedResistorCalculator.java │ │ │ └── module-info.java │ └── target │ │ ├── resistors-0.0.1-jar-with-dependencies.jar │ │ └── resistors-0.0.1.jar ├── schemes │ └── rgb-led.fzz └── scripts │ └── modify-waveshare-7inch-hdmi.config.txt ├── Chapter_03_IDE └── README.md ├── Chapter_04_Java ├── README.md ├── java-crash-course │ ├── EnumSwitch.java │ ├── HelloWorld.java │ ├── IfThenElse.java │ ├── MainArguments.java │ ├── NumberValues.java │ ├── ReadTextFile.java │ ├── UsingMethod.java │ ├── UsingObject.java │ └── resources │ │ └── testdata.csv ├── java-helloworld │ └── HelloWorld.java ├── javafx-timeline │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ ├── be │ │ └── webtechie │ │ │ └── timeline │ │ │ ├── App.java │ │ │ ├── DataSet.java │ │ │ └── JavaTimeline.java │ │ └── module-info.java └── scripts │ ├── install_liberica_11.0.2.sh │ ├── install_liberica_11.0.4.sh │ ├── install_liberica_12.0.2.sh │ ├── install_liberica_13.sh │ └── install_liberica_14.sh ├── Chapter_05_PiPinning ├── README.md └── javafx-pinning-info │ ├── README.md │ ├── pom.xml │ ├── screenshots │ └── headerpins_in_header.png │ ├── src │ └── main │ │ └── java │ │ ├── be │ │ └── webtechie │ │ │ ├── App.java │ │ │ └── pinninginfo │ │ │ ├── util │ │ │ └── Converter.java │ │ │ └── views │ │ │ ├── BooleanTableCell.java │ │ │ ├── HeaderPinView.java │ │ │ ├── HeaderTableView.java │ │ │ ├── PinTypeView.java │ │ │ └── PinView.java │ │ └── module-info.java │ └── target │ ├── pinning-info-0.0.1-jar-with-dependencies.jar │ └── pinning-info-0.0.1.jar ├── Chapter_06_Maven ├── README.md ├── java-maven-logging │ ├── demoApplication.log │ ├── logs │ │ └── app.log │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── be │ │ │ └── webtechie │ │ │ └── App.java │ │ └── resources │ │ └── log4j2.xml ├── java-maven-minimal │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── be │ │ │ └── webtechie │ │ │ └── App.java │ │ └── test │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── AppTest.java └── scripts │ └── start-new-maven-project.sh ├── Chapter_07_JavaFX ├── README.md ├── java-hellogpio │ └── HelloGpio.java ├── javafx-dashboard │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ ├── be │ │ └── webtechie │ │ │ ├── App.java │ │ │ ├── FxScreen.java │ │ │ └── Gpio.java │ │ └── module-info.java ├── javafx-i2c-relay │ ├── README.md │ ├── pictures │ │ ├── relay-app-on-pi.png │ │ └── relay-enabled.jpg │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ ├── be │ │ └── webtechie │ │ │ ├── App.java │ │ │ ├── i2c │ │ │ ├── RelayController.java │ │ │ └── definition │ │ │ │ ├── Board.java │ │ │ │ ├── Relay.java │ │ │ │ └── State.java │ │ │ └── ui │ │ │ └── ToggleSwitchScreen.java │ │ └── module-info.java ├── javafx-minimal-fxml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ ├── be │ │ │ └── webtechie │ │ │ │ ├── App.java │ │ │ │ ├── PrimaryController.java │ │ │ │ └── SecondaryController.java │ │ └── module-info.java │ │ └── resources │ │ └── be │ │ └── webtechie │ │ ├── primary.fxml │ │ └── secondary.fxml ├── javafx-minimal │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ ├── be │ │ └── webtechie │ │ │ ├── App.java │ │ │ └── SystemInfo.java │ │ └── module-info.java ├── schemes │ └── dashboard-led-button.fzz └── scripts │ ├── gluonhq_add_archetypes.sh │ ├── gluonhq_create_empty_javafx_fxml_project.sh │ └── gluonhq_create_empty_javafx_project.sh ├── Chapter_08_BitsAndBytes ├── README.md ├── java-value-limits │ ├── HexIntegerToString.java │ └── PrintLimits.java ├── javafx-bits-calculator │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ ├── be │ │ └── webtechie │ │ │ └── javafxbitscalculator │ │ │ ├── App.java │ │ │ └── BitsAndBytes.java │ │ └── module-info.java ├── javafx-led-number-display-controller │ ├── README.md │ ├── out │ │ └── led-number-display-controller-0.0.1.jar │ ├── pom.xml │ ├── screenshots │ │ ├── led_segment_app.png │ │ └── led_segment_scheme_breadboard.png │ └── src │ │ └── main │ │ ├── java │ │ ├── be │ │ │ └── webtechie │ │ │ │ └── lednumberdisplaycontroller │ │ │ │ ├── App.java │ │ │ │ ├── Executor.java │ │ │ │ └── SegmentSelection.java │ │ └── module-info.java │ │ └── resources │ │ └── shift.py └── schemes │ ├── 74NC595-led-number.fzz │ └── segment-display.fzz ├── Chapter_09_Pi4J ├── README.md ├── arduino-serial │ └── arduino-serial.ino ├── fxgl-game │ ├── assets │ │ └── run.sh │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ ├── be │ │ │ └── webtechie │ │ │ │ └── fxgl │ │ │ │ ├── GameApp.java │ │ │ │ ├── GameFactory.java │ │ │ │ ├── component │ │ │ │ ├── CloudComponent.java │ │ │ │ └── PlayerComponent.java │ │ │ │ └── pi4j │ │ │ │ └── Pi4JFactory.java │ │ └── module-info.java │ │ └── resources │ │ └── assets │ │ └── textures │ │ ├── cloud-network.png │ │ ├── duke.png │ │ └── sprite_bullet.png ├── java-pi4j-digital-input-button │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── pi4jgpio │ │ ├── App.java │ │ └── handler │ │ └── InputChangeEventListener.java ├── java-pi4j-digital-output-led │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── pi4jgpio │ │ └── App.java ├── java-pi4j-distancesensor │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── be │ │ │ └── webtechie │ │ │ └── pi4jgpio │ │ │ ├── App.java │ │ │ └── helper │ │ │ └── Calculation.java │ │ └── test │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── pi4jgpio │ │ └── Calculation │ │ └── CalculationTest.java ├── java-pi4j-lcddisplay │ ├── README.md │ ├── images │ │ ├── lcd-output.jpg │ │ └── lcd-wiring.png │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── be │ │ │ └── webtechie │ │ │ └── pi4jgpio │ │ │ ├── App.java │ │ │ ├── lcd │ │ │ └── LcdOutput.java │ │ │ └── weather │ │ │ ├── data │ │ │ ├── Coordinates.java │ │ │ ├── Forecast.java │ │ │ ├── WeatherDescription.java │ │ │ ├── WeatherInfo.java │ │ │ └── WindInfo.java │ │ │ └── helper │ │ │ ├── WeatherMapper.java │ │ │ └── WeatherRequest.java │ │ └── test │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── pi4jgpio │ │ └── weather │ │ └── helper │ │ ├── WeatherMapperTest.java │ │ └── WeatherRequestTest.java ├── java-pi4j-motorshield │ └── README.md ├── java-pi4j-pwm-output-led │ ├── hs_err_pid7118.log │ ├── pom.xml │ └── src │ │ ├── .vscode │ │ └── launch.json │ │ └── main │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── pi4jgpio │ │ └── App.java ├── java-pi4j-pwm-output-motor │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── pi4jgpio │ │ └── App.java ├── java-pi4j-spi-tft │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── pi4jgpio │ │ ├── App.java │ │ ├── definition │ │ ├── AsciiCharacter.java │ │ ├── Image.java │ │ └── SpiCommand.java │ │ └── helper │ │ ├── AsciiCharacterMode.java │ │ ├── DemoMode.java │ │ └── ImageMode.java ├── java-pi4j-spi │ ├── README.md │ ├── pictures │ │ ├── matrix-output.jpg │ │ └── matrix-wiring-setup.jpg │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── pi4jgpio │ │ ├── App.java │ │ ├── definition │ │ ├── AsciiCharacter.java │ │ ├── Image.java │ │ └── SpiCommand.java │ │ └── helper │ │ ├── AsciiCharacterMode.java │ │ ├── DemoMode.java │ │ └── ImageMode.java ├── javafx-pi4j-serial │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ ├── be │ │ │ └── webtechie │ │ │ │ └── pi4j │ │ │ │ └── serial │ │ │ │ ├── App.java │ │ │ │ ├── data │ │ │ │ ├── ArduinoMessage.java │ │ │ │ └── ArduinoMessageMapper.java │ │ │ │ ├── serial │ │ │ │ ├── SerialListener.java │ │ │ │ └── SerialSender.java │ │ │ │ └── ui │ │ │ │ └── MeasurementChart.java │ │ │ └── module-info.java │ │ └── test │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── pi4j │ │ └── serial │ │ └── data │ │ └── ArduinoMapperTest.java └── schemes │ ├── 8x8-led-matrix.fzz │ ├── digital-input-button.fzz │ ├── digital-output-led-multiple-resistors.fzz │ ├── digital-output-led-one-resistor.fzz │ ├── digital-output-pwm-led.fzz │ ├── distancesensor.fzz │ ├── lcd.fzz │ ├── serial-arduino-lightsensor.fzz │ └── spi-max7219.fzz ├── Chapter_10_Spring ├── README.md ├── java-spring-image-server │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── be │ │ │ │ └── webtechie │ │ │ │ └── javaspringrest │ │ │ │ ├── JavaSpringRestApplication.java │ │ │ │ ├── configuration │ │ │ │ └── SwaggerConfig.java │ │ │ │ └── controller │ │ │ │ ├── ImageController.java │ │ │ │ └── MyErrorController.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── javaspringrest │ │ └── JavaSpringRestApplicationTests.java ├── java-spring-rest-db │ ├── README.md │ ├── pom.xml │ ├── src │ │ ├── main │ │ │ ├── java │ │ │ │ └── be │ │ │ │ │ └── webtechie │ │ │ │ │ └── javaspringrestdb │ │ │ │ │ ├── JavaSpringRestDbApplication.java │ │ │ │ │ ├── configuration │ │ │ │ │ └── SwaggerConfig.java │ │ │ │ │ ├── controller │ │ │ │ │ └── MyErrorController.java │ │ │ │ │ ├── entity │ │ │ │ │ ├── MeasurementEntity.java │ │ │ │ │ └── SensorEntity.java │ │ │ │ │ ├── repository │ │ │ │ │ ├── MeasurementRepository.java │ │ │ │ │ └── SensorRepository.java │ │ │ │ │ └── resource │ │ │ │ │ ├── MeasurementResource.java │ │ │ │ │ └── SensorResource.java │ │ │ └── resources │ │ │ │ └── application.properties │ │ └── test │ │ │ └── java │ │ │ └── be │ │ │ └── webtechie │ │ │ └── javaspringrestdb │ │ │ └── JavaSpringRestDbApplicationTests.java │ └── target │ │ └── java-spring-rest-db-0.0.1-SNAPSHOT.jar ├── java-spring-rest-gpio │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── be │ │ │ └── webtechie │ │ │ └── javaspringrestgpio │ │ │ ├── JavaSpringRestGpioApplication.java │ │ │ ├── configuration │ │ │ └── SwaggerConfig.java │ │ │ ├── controller │ │ │ ├── GpioRestController.java │ │ │ └── InfoRestController.java │ │ │ └── manager │ │ │ └── GpioManager.java │ │ └── resources │ │ └── application.properties ├── java-spring-rest-original │ ├── .gitignore │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── be │ │ │ │ └── webtechie │ │ │ │ └── javaspringrest │ │ │ │ └── JavaSpringRestApplication.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── javaspringrest │ │ └── JavaSpringRestApplicationTests.java └── java-spring-stream │ ├── .gitignore │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── be │ │ └── webtechie │ │ └── javaspringstream │ │ ├── JavaSpringStreamApplication.java │ │ ├── controller │ │ └── DistanceController.java │ │ ├── dto │ │ └── DistanceMeasurement.java │ │ └── service │ │ └── DistanceService.java │ └── resources │ └── application.properties ├── Chapter_11_Queues ├── README.md ├── arduino-wifi-mosquitto │ ├── README.md │ └── WifiMosquittoListener │ │ ├── ConnectionHandler.ino │ │ ├── LedEffects.ino │ │ ├── MessageHandler.ino │ │ ├── SerialFunctions.ino │ │ └── WifiMosquittoListener.ino ├── java-string-compare │ └── StringCompare.java ├── javafx-led-controller │ ├── README.md │ ├── pom.xml │ ├── screenshots │ │ └── led-selection-screen.png │ └── src │ │ ├── main │ │ ├── java │ │ │ ├── be │ │ │ │ └── webtechie │ │ │ │ │ └── javafxspringledcontroller │ │ │ │ │ ├── LedControllerApplication.java │ │ │ │ │ ├── client │ │ │ │ │ ├── ClientCallback.java │ │ │ │ │ ├── QueueClient.java │ │ │ │ │ └── ReceivedMessage.java │ │ │ │ │ ├── event │ │ │ │ │ ├── EventListener.java │ │ │ │ │ └── EventManager.java │ │ │ │ │ ├── led │ │ │ │ │ ├── LedCommand.java │ │ │ │ │ └── LedEffect.java │ │ │ │ │ ├── server │ │ │ │ │ └── WebHandler.java │ │ │ │ │ └── ui │ │ │ │ │ ├── Home.java │ │ │ │ │ ├── LedControlPanel.java │ │ │ │ │ ├── MenuWindow.java │ │ │ │ │ └── QueueMessagesList.java │ │ │ └── eu │ │ │ │ └── hansolo │ │ │ │ └── fx │ │ │ │ └── colorselector │ │ │ │ ├── ColorSelector.java │ │ │ │ ├── ConicalGradient.java │ │ │ │ ├── GradientLookup.java │ │ │ │ └── Main.java │ │ └── resources │ │ │ └── styles │ │ │ └── style.css │ │ └── test │ │ └── java │ │ └── be │ │ └── webtechie │ │ └── javafxspringledcontroller │ │ └── led │ │ └── LedCommandTest.java ├── javafx-mosquitto │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ ├── be │ │ └── webtechie │ │ │ └── javafxmosquitto │ │ │ ├── App.java │ │ │ ├── client │ │ │ ├── ClientCallback.java │ │ │ └── QueueClient.java │ │ │ └── ui │ │ │ └── QueueMonitor.java │ │ └── module-info.java ├── schemes │ ├── arduino-ledstrip.fzz │ └── arduino-ledstrip.png └── wireshark-traces │ └── pi-receives-mosquitto-arduino-client.pcapng ├── FOOTNOTE_LINKS.md ├── LICENSE └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: FDelporte 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | */.idea/ 2 | */*/.idea/ 3 | */.settings/ 4 | */*/.settings/ 5 | */.vscode/ 6 | */*/.vscode/ 7 | */.mvn/ 8 | */*/.mvn/ 9 | *.classpath 10 | *.project 11 | *.iml 12 | *.lck 13 | */*/target/classes/* 14 | */*/target/maven-archiver/* 15 | */*/target/maven-status/* 16 | */*/target/test-classes/* 17 | */*/target/surefire-reports/* 18 | */*/target/*.original 19 | /.idea/ 20 | /Chapter_09_Pi4J/fxgl-game/logs/ 21 | /Chapter_09_Pi4J/fxgl-game/system/ 22 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | # Changes in the sources 2 | 3 | See [README](README.md). 4 | 5 | -------------------------------------------------------------------------------- /Chapter_01_Introduction/README.md: -------------------------------------------------------------------------------- 1 | # Chapter 1: Java 2 | Introduction for the book and sources 3 | 4 | ## README interesting links 5 | * [A good README template](https://gist.github.com/PurpleBooth/109311bb0361f32d87a2) 6 | * [Start every project with a README](https://open.nytimes.com/how-to-take-your-open-source-project-from-good-to-great-49c392175e5c) 7 | * [How to write good README and why should you care](https://thejunkland.com/blog/how-to-write-good-readme.html) 8 | * [Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) -------------------------------------------------------------------------------- /Chapter_02_Tools/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Read more 4 | 5 | ### Tools 6 | * [Raspberry Pi Bash Command Cheat Sheet](https://www.elektormagazine.com/news/bash-command-cheat-sheet) 7 | * [WireShark on Raspberry PI ](https://donsthinktank.blogspot.com/2015/07/wireshark-raspberry-pi.html) 8 | 9 | ### Level shifting 10 | * [](https://www.raspberrypi-spy.co.uk/2018/09/using-a-level-shifter-with-the-raspberry-pi-gpio/) 11 | 12 | ### LED (strips) 13 | * [The Light Emitting Diode](https://www.electronics-tutorials.ws/diode/diode_8.html) 14 | * [WS2812B vs WS2813 Addressable RGB LED Strips – How are they different?](https://www.seeedstudio.com/blog/2019/02/14/ws2812b-vs-ws2813-addressable-rgb-led-strips-how-are-they-different/) 15 | * [Guide for WS2812B Addressable RGB LED Strip with Arduino](https://randomnerdtutorials.com/guide-for-ws2812b-addressable-rgb-led-strip-with-arduino/) 16 | * [The Magic of NeoPixels](https://learn.adafruit.com/adafruit-neopixel-uberguide) 17 | * [Light_WS2812 library V2.0 – Part I: Understanding the WS2812](https://cpldcpu.wordpress.com/2014/01/14/light_ws2812-library-v2-0-part-i-understanding-the-ws2812/) 18 | * [LED Chips Explained – differences between 3528s, 5050s and other SMDs](https://www.instyleled.co.uk/support/what-are-the-differences-between-types-of-led-chip/) -------------------------------------------------------------------------------- /Chapter_02_Tools/javafx-resistors/README.md: -------------------------------------------------------------------------------- 1 | # Example application: visualize the Raspberry Pi pins with JavaFX 2 | Resistor values and calculator application. 3 | 4 | ## Screenshots 5 | 6 | ![Resistor color coding in a table view](screenshots/javafx-table.png) 7 | 8 | ![Calculating the resistor value with 4 colors](screenshots/javafx-resistor-value-330.png) 9 | 10 | ![Calculating the resistor value for a LED](screenshots/javafx-led-resistor-value.png) 11 | 12 | ## Maven project be.webtechie.resistor-calculator 13 | * [Sources on GitHub](https://github.com/FDelporte/ResistorCalculator) 14 | * [Maven repository](https://mvnrepository.com/artifact/be.webtechie/resistor-calculator) 15 | 16 | ## Build and run 17 | 18 | ``` 19 | $ mvn clean package 20 | $ java -jar target/resistors-0.0.1-jar-with-dependencies.jar 21 | ``` -------------------------------------------------------------------------------- /Chapter_02_Tools/javafx-resistors/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | be.webtechie 6 | resistors 7 | 0.0.1 8 | 9 | 10 | UTF-8 11 | 11 12 | 11 13 | 14 | 15 | 16 | 17 | org.openjfx 18 | javafx-controls 19 | 11.0.2 20 | 21 | 22 | 23 | be.webtechie 24 | resistor-calculator 25 | 0.1.4 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.apache.maven.plugins 33 | maven-compiler-plugin 34 | 3.8.0 35 | 36 | 11 37 | 38 | 39 | 40 | 41 | maven-assembly-plugin 42 | 2.2.1 43 | 44 | 45 | jar-with-dependencies 46 | 47 | 48 | 49 | true 50 | be.webtechie.resistors.App 51 | 52 | 53 | 54 | 55 | 56 | make-assembly 57 | package 58 | 59 | single 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Chapter_02_Tools/javafx-resistors/screenshots/javafx-led-resistor-value.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDelporte/JavaOnRaspberryPi/31e2c419c462521376089e4b89621c4e84b5b7d0/Chapter_02_Tools/javafx-resistors/screenshots/javafx-led-resistor-value.png -------------------------------------------------------------------------------- /Chapter_02_Tools/javafx-resistors/screenshots/javafx-resistor-value-330.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDelporte/JavaOnRaspberryPi/31e2c419c462521376089e4b89621c4e84b5b7d0/Chapter_02_Tools/javafx-resistors/screenshots/javafx-resistor-value-330.png -------------------------------------------------------------------------------- /Chapter_02_Tools/javafx-resistors/screenshots/javafx-table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDelporte/JavaOnRaspberryPi/31e2c419c462521376089e4b89621c4e84b5b7d0/Chapter_02_Tools/javafx-resistors/screenshots/javafx-table.png -------------------------------------------------------------------------------- /Chapter_02_Tools/javafx-resistors/src/main/java/be/webtechie/resistors/App.java: -------------------------------------------------------------------------------- 1 | package be.webtechie.resistors; 2 | 3 | import be.webtechie.resistors.views.BandCalculator; 4 | import be.webtechie.resistors.views.ColorsTableView; 5 | import be.webtechie.resistors.views.LedResistorCalculator; 6 | import javafx.application.Application; 7 | import javafx.scene.Scene; 8 | import javafx.scene.control.Separator; 9 | import javafx.scene.layout.HBox; 10 | import javafx.scene.layout.VBox; 11 | import javafx.stage.Stage; 12 | 13 | /** 14 | * JavaFX App 15 | */ 16 | public class App extends Application { 17 | 18 | @Override 19 | public void start(Stage stage) { 20 | HBox holder = new HBox(); 21 | holder.setSpacing(25); 22 | holder.getChildren().add(new ColorsTableView()); 23 | 24 | VBox calculators = new VBox(); 25 | calculators.setSpacing(10); 26 | holder.getChildren().add(calculators); 27 | 28 | calculators.getChildren().add(new BandCalculator()); 29 | calculators.getChildren().add(new Separator()); 30 | calculators.getChildren().add(new LedResistorCalculator()); 31 | 32 | var scene = new Scene(holder, 1500, 400); 33 | stage.setScene(scene); 34 | stage.setTitle("Resistor color coding"); 35 | stage.show(); 36 | } 37 | 38 | public static void main(String[] args) { 39 | launch(); 40 | } 41 | } -------------------------------------------------------------------------------- /Chapter_02_Tools/javafx-resistors/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module be.webtechie.resistors { 2 | requires javafx.controls; 3 | requires be.webtechie.resistorcalculator; 4 | opens be.webtechie.resistors to javafx.graphics; 5 | } -------------------------------------------------------------------------------- /Chapter_02_Tools/javafx-resistors/target/resistors-0.0.1-jar-with-dependencies.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDelporte/JavaOnRaspberryPi/31e2c419c462521376089e4b89621c4e84b5b7d0/Chapter_02_Tools/javafx-resistors/target/resistors-0.0.1-jar-with-dependencies.jar -------------------------------------------------------------------------------- /Chapter_02_Tools/javafx-resistors/target/resistors-0.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDelporte/JavaOnRaspberryPi/31e2c419c462521376089e4b89621c4e84b5b7d0/Chapter_02_Tools/javafx-resistors/target/resistors-0.0.1.jar -------------------------------------------------------------------------------- /Chapter_02_Tools/schemes/rgb-led.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDelporte/JavaOnRaspberryPi/31e2c419c462521376089e4b89621c4e84b5b7d0/Chapter_02_Tools/schemes/rgb-led.fzz -------------------------------------------------------------------------------- /Chapter_02_Tools/scripts/modify-waveshare-7inch-hdmi.config.txt: -------------------------------------------------------------------------------- 1 | max_usb_current=1 2 | hdmi_group=2 3 | hdmi_mode=1 4 | hdmi_mode=87 5 | hdmi_cvt 1024 600 60 6 0 0 0 -------------------------------------------------------------------------------- /Chapter_03_IDE/README.md: -------------------------------------------------------------------------------- 1 | # Chapter 4: Choosing an IDE 2 | Chapter describing the history and current state of Java and how to install on a Pi. 3 | 4 | ## IDE's 5 | 6 | ### IntelliJ IDEA 7 | * [IntelliJ IDEA shortcuts](https://www.jetbrains.com/help/idea/mastering-keyboard-shortcuts.html) 8 | 9 | ### Visual Studio Code 10 | * [VSC shortcuts](https://code.visualstudio.com/docs/getstarted/keybindings) 11 | * [Remote Development with VS Code](https://code.visualstudio.com/blogs/2019/05/02/remote-development) 12 | 13 | ### NetBeans 14 | https://www.youtube.com/watch?v=BIGgUZeTl4w&feature=youtu.be 15 | https://blog.idrsolutions.com/2014/08/using-netbeans-remotely-deploy-projects-raspberry-pi/ 16 | -------------------------------------------------------------------------------- /Chapter_04_Java/java-crash-course/EnumSwitch.java: -------------------------------------------------------------------------------- 1 | public class EnumSwitch { 2 | public static void main (String[] args) { 3 | // Compare integer value 4 | HEADER_VERSION piHeaderVersion = HEADER_VERSION.TYPE_2; 5 | 6 | switch(piHeaderVersion) { 7 | case TYPE_1: 8 | System.out.println("Header version 1 is used on original Model B"); 9 | break; 10 | case TYPE_2: 11 | System.out.println("Header version 2 is used on Model A and Model B (revision 2)"); 12 | break; 13 | case TYPE_3: 14 | System.out.println("Header version 3 is used on Model A+, B+, Pi Zero, Pi Zero W, Pi2B, Pi3B, Pi4B"); 15 | break; 16 | default: 17 | System.out.println("Sorry, header version " + piHeaderVersion + " is not known"); 18 | } 19 | } 20 | 21 | enum HEADER_VERSION { 22 | TYPE_1, TYPE_2, TYPE_3, UNKNOWN; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter_04_Java/java-crash-course/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | public static void main (String[] args) { 3 | String txt = "Hello World"; 4 | System.out.println(txt); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Chapter_04_Java/java-crash-course/IfThenElse.java: -------------------------------------------------------------------------------- 1 | public class IfThenElse { 2 | public static void main (String[] args) { 3 | // Compare integer value 4 | int piHeaderVersion = 1; 5 | 6 | if (piHeaderVersion == 1) { 7 | System.out.println("Header version 1 is used on original Model B"); 8 | } else if (piHeaderVersion == 2) { 9 | System.out.println("Header version 2 is used on Model A and Model B (revision 2)"); 10 | } else if (piHeaderVersion == 3) { 11 | System.out.println("Header version 3 is used on Model A+, B+, Pi Zero, Pi Zero W, Pi2B, Pi3B, Pi4B"); 12 | } else { 13 | System.out.println("Sorry, header version " + piHeaderVersion + " is not known"); 14 | } 15 | 16 | // Compare strings 17 | String string1 = "Hello world"; 18 | String string2 = "Hello" + " " + "world"; 19 | String string3 = "Hello World"; 20 | 21 | System.out.println("Are string1 and string2 equal? " + string1.equals(string2)); 22 | System.out.println("Are string1 and string3 equal? " + string1.equals(string3)); 23 | System.out.println("Are string1 and string3 equal ignoring the case? " + string1.equalsIgnoreCase(string3)); 24 | 25 | if (string1.equalsIgnoreCase(string3)) { 26 | System.out.println("string1 and string3 are equal ignoring the case"); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter_04_Java/java-crash-course/MainArguments.java: -------------------------------------------------------------------------------- 1 | public class MainArguments { 2 | public static void main (String[] args) { 3 | System.out.println("Number of arguments: " + args.length); 4 | 5 | if (args.length > 0) { 6 | System.out.println("First argument: " + args[0]); 7 | } 8 | 9 | for (int i = 0; i < args.length; i++) { 10 | System.out.println("Argument " + (i + 1) + ": " + args[i]); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_04_Java/java-crash-course/NumberValues.java: -------------------------------------------------------------------------------- 1 | public class NumberValues { 2 | public static void main (String[] args) { 3 | int intValue = 2; 4 | float floatValue = 1.12345678901234567890F; 5 | double doubleValue = 1.12345678901234567890D; 6 | 7 | System.out.println("Integer: " + intValue); 8 | System.out.println("Float: " + floatValue); 9 | System.out.println("Double: " + doubleValue); 10 | 11 | System.out.println("Multiply: " + (intValue * floatValue) + ", rounded: " + Math.round(intValue * floatValue)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_04_Java/java-crash-course/UsingMethod.java: -------------------------------------------------------------------------------- 1 | import java.text.SimpleDateFormat; 2 | import java.util.Date; 3 | 4 | public class UsingMethod { 5 | public static void main (String[] args) { 6 | System.out.println("2 x Raspberry Pi 4 4Gb, price: " + getTotal(2, 59.95F) + " Euro"); 7 | 8 | System.out.println("Current date and time is: " + getNow()); 9 | } 10 | 11 | public static float getTotal(int quantity, float price) { 12 | return quantity * price; 13 | } 14 | 15 | public static String getNow() { 16 | return new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(new Date()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_04_Java/java-crash-course/UsingObject.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | 4 | public class UsingObject { 5 | public static void main (String[] args) { 6 | List items = new ArrayList<>(); 7 | items.add(new ShoppingCartItem("Raspberry Pi 4, 4Gb", 1, 59.95F)); 8 | items.add(new ShoppingCartItem("Micro-HDMI cable", 2, 5.9F)); 9 | items.add(new ShoppingCartItem("Raspberry Pi 4 power supply", 1, 9.95F)); 10 | 11 | double total = 0D; 12 | for (ShoppingCartItem item : items) { 13 | System.out.println(item.getName()); 14 | System.out.println(" " + item.getQuantity() + "\tx\t" + item.getPrice() + "\t= " + item.getTotal() + " Euro"); 15 | total += item.getTotal(); 16 | } 17 | 18 | System.out.println("\nTotal for shopping cart:\n " + total + " Euro"); 19 | } 20 | 21 | public static class ShoppingCartItem { 22 | // These values are final as they should not be changed 23 | private final String name; 24 | private final int quantity; 25 | private final float price; 26 | 27 | public ShoppingCartItem(String name, int quantity, float price) { 28 | this.name = name; 29 | this.quantity = quantity; 30 | this.price = price; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public int getQuantity() { 38 | return quantity; 39 | } 40 | 41 | public float getPrice() { 42 | return price; 43 | } 44 | 45 | public float getTotal() { 46 | return quantity * price; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Chapter_04_Java/java-helloworld/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | public static void main (String[] args) { 3 | System.out.println("Hello World"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Chapter_04_Java/javafx-timeline/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Dates from 4 | * [Wikipedia Java programming language](https://en.wikipedia.org/wiki/Java_%28programming_language%29) 5 | * [Wikipedia Java version history](https://en.wikipedia.org/wiki/Java_version_history) 6 | * [Wikipedia JavaFX](https://en.wikipedia.org/wiki/JavaFX) 7 | * [Raspberry Pi](https://webtechie.be/2019/11/13/raspberry-pi-history-versions-pins-headers-as-a-java-maven-library) 8 | 9 | ## Inspired by 10 | * https://www.dummies.com/programming/java/how-to-create-lines-and-shapes-in-javafx/ 11 | * -------------------------------------------------------------------------------- /Chapter_04_Java/javafx-timeline/src/main/java/be/webtechie/timeline/App.java: -------------------------------------------------------------------------------- 1 | package be.webtechie.timeline; 2 | 3 | import javafx.application.Application; 4 | import javafx.scene.Scene; 5 | import javafx.scene.control.Label; 6 | import javafx.scene.layout.StackPane; 7 | import javafx.stage.Stage; 8 | 9 | /** 10 | * JavaFX App 11 | */ 12 | public class App extends Application { 13 | 14 | @Override 15 | public void start(Stage stage) { 16 | int width = 900; 17 | int height = 900; 18 | 19 | var scene = new Scene(new JavaTimeline(width, height, 10, DataSet.RASPBERRYPI_BOARDS), width + 50, height); 20 | stage.setScene(scene); 21 | stage.show(); 22 | } 23 | 24 | public static void main(String[] args) { 25 | launch(); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /Chapter_04_Java/javafx-timeline/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module be.webtechie.timeline { 2 | requires javafx.controls; 3 | requires com.pi4j; 4 | exports be.webtechie.timeline; 5 | opens be.webtechie.timeline to javafx.graphics; 6 | } -------------------------------------------------------------------------------- /Chapter_04_Java/scripts/install_liberica_11.0.2.sh: -------------------------------------------------------------------------------- 1 | cd /home/pi 2 | wget https://download.bell-sw.com/java/11.0.2/bellsoft-jdk11.0.2-linux-arm32-vfp-hflt.deb 3 | sudo apt-get install ./bellsoft-jdk11.0.2-linux-arm32-vfp-hflt.deb 4 | sudo update-alternatives --config javac 5 | sudo update-alternatives --config java -------------------------------------------------------------------------------- /Chapter_04_Java/scripts/install_liberica_11.0.4.sh: -------------------------------------------------------------------------------- 1 | cd /home/pi 2 | wget https://download.bell-sw.com/java/11.0.4/bellsoft-jdk11.0.4-linux-arm32-vfp-hflt.deb 3 | sudo apt-get install ./bellsoft-jdk11.0.4-linux-arm32-vfp-hflt.deb 4 | sudo update-alternatives --config javac 5 | sudo update-alternatives --config java -------------------------------------------------------------------------------- /Chapter_04_Java/scripts/install_liberica_12.0.2.sh: -------------------------------------------------------------------------------- 1 | cd /home/pi 2 | wget https://download.bell-sw.com/java/12.0.2/bellsoft-jdk12.0.2-linux-arm32-vfp-hflt.deb 3 | sudo apt-get install ./bellsoft-jdk12.0.2-linux-arm32-vfp-hflt.deb 4 | sudo update-alternatives --config javac 5 | sudo update-alternatives --config java -------------------------------------------------------------------------------- /Chapter_04_Java/scripts/install_liberica_13.sh: -------------------------------------------------------------------------------- 1 | cd /home/pi 2 | wget https://download.bell-sw.com/java/13/bellsoft-jdk13-linux-arm32-vfp-hflt.deb 3 | sudo apt-get install ./bellsoft-jdk13-linux-arm32-vfp-hflt.deb 4 | sudo update-alternatives --config javac 5 | sudo update-alternatives --config java -------------------------------------------------------------------------------- /Chapter_04_Java/scripts/install_liberica_14.sh: -------------------------------------------------------------------------------- 1 | cd /home/pi 2 | wget http://download.bell-sw.com/java/14+36/bellsoft-jdk14+36-linux-arm32-vfp-hflt-full.deb 3 | sudo apt-get install ./bellsoft-jdk14+36-linux-arm32-vfp-hflt-full.deb 4 | sudo update-alternatives --config javac 5 | sudo update-alternatives --config java 6 | -------------------------------------------------------------------------------- /Chapter_05_PiPinning/README.md: -------------------------------------------------------------------------------- 1 | # Chapter 5: Pinning 2 | Information about the pinning layout of a Raspberry Pi 4. 3 | 4 | ## Maven project be.webtechie.pi-headers 5 | * [Sources on GitHub](https://github.com/FDelporte/PiHeaders) 6 | * [Maven repository](https://mvnrepository.com/artifact/be.webtechie/pi-headers) 7 | 8 | ## Pin types 9 | * [GPIO](https://www.raspberrypi.org/documentation/usage/gpio/) 10 | * [Using PullUp and PullDown Resistors on the Raspberry Pi](https://grantwinney.com/using-pullup-and-pulldown-resistors-on-the-raspberry-pi/) 11 | * [Pull-up resistor](https://en.wikipedia.org/wiki/Pull-up_resistor) 12 | 13 | ## Pin functions 14 | * https://www.raspberrypi.org/documentation/usage/gpio/ 15 | * https://pinout.xyz/# 16 | * https://en.wikipedia.org/wiki/Raspberry_Pi#Connectors 17 | * http://wiringpi.com/pins/ 18 | * https://www.tomshardware.com/reviews/raspberry-pi-gpio-pinout,6122.html 19 | * [Serial Communication](https://learn.sparkfun.com/tutorials/serial-communication/all) 20 | * [The Raspberry Pi UARTs](https://www.raspberrypi.org/documentation/configuration/uart.md) 21 | * [Notes on the general-purpose clock on BCM2835](https://www.tablix.org/~avian/blog/archives/2018/02/notes_on_the_general_purpose_clock_on_bcm2835/) 22 | * [I²C](https://en.wikipedia.org/wiki/I%C2%B2C) 23 | * [Serial Peripheral Interface](https://en.wikipedia.org/wiki/Serial_Peripheral_Interface) 24 | * [Difference between I2C and SPI ( I2C vs SPI ), you should know.](https://aticleworld.com/difference-between-i2c-and-spi/) 25 | * [Arduino PWM Tutorial](https://create.arduino.cc/projecthub/muhammad-aqib/arduino-pwm-tutorial-ae9d71) 26 | * [Make Digital/truth Table Graphs in Excel](https://www.instructables.com/id/Make-Digital-Graphs-in-Excel/) 27 | 28 | ## Read more 29 | * [WiringPi](http://wiringpi.com/) 30 | * [WiringPi numbering explained](https://projects.drogon.net/wiringpi-pin-numbering/) 31 | * [What is the difference between BOARD and BCM for GPIO pin numbering?](https://raspberrypi.stackexchange.com/questions/12966/what-is-the-difference-between-board-and-bcm-for-gpio-pin-numbering) 32 | * [Pigpio library](http://abyz.me.uk/rpi/pigpio/index.html) 33 | -------------------------------------------------------------------------------- /Chapter_05_PiPinning/javafx-pinning-info/README.md: -------------------------------------------------------------------------------- 1 | # Example application: visualize the Raspberry Pi pins with JavaFX 2 | Information about the pinning layout of a Raspberry Pi. 3 | 4 | ![40-pin header view](screenshots/headerpins_in_header.png) 5 | 6 | ## Maven project be.webtechie.pi-headers 7 | * [Sources on GitHub](https://github.com/FDelporte/PiHeaders) 8 | * [Maven repository](https://mvnrepository.com/artifact/be.webtechie/pi-headers) 9 | 10 | ## Build and run 11 | 12 | ``` 13 | $ mvn clean package 14 | $ java -jar target/pinning-info-0.0.1-jar-with-dependencies.jar 15 | ``` -------------------------------------------------------------------------------- /Chapter_05_PiPinning/javafx-pinning-info/screenshots/headerpins_in_header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDelporte/JavaOnRaspberryPi/31e2c419c462521376089e4b89621c4e84b5b7d0/Chapter_05_PiPinning/javafx-pinning-info/screenshots/headerpins_in_header.png -------------------------------------------------------------------------------- /Chapter_05_PiPinning/javafx-pinning-info/src/main/java/be/webtechie/App.java: -------------------------------------------------------------------------------- 1 | package be.webtechie; 2 | 3 | import be.webtechie.pinninginfo.views.HeaderPinView; 4 | import be.webtechie.pinninginfo.views.HeaderTableView; 5 | import com.pi4j.boardinfo.definition.HeaderPins; 6 | import javafx.application.Application; 7 | import javafx.event.ActionEvent; 8 | import javafx.geometry.Insets; 9 | import javafx.scene.Scene; 10 | import javafx.scene.control.ComboBox; 11 | import javafx.scene.control.Label; 12 | import javafx.scene.layout.HBox; 13 | import javafx.scene.layout.VBox; 14 | import javafx.stage.Stage; 15 | 16 | /** 17 | * JavaFX App 18 | */ 19 | public class App extends Application { 20 | 21 | private HBox headerHolder; 22 | private HBox tableholder; 23 | private ComboBox headerSelection; 24 | 25 | @Override 26 | public void start(Stage stage) { 27 | HBox holder = new HBox(); 28 | holder.setSpacing(25); 29 | 30 | VBox leftColumn = new VBox(); 31 | leftColumn.setSpacing(25); 32 | holder.getChildren().add(leftColumn); 33 | 34 | HBox selection = new HBox(); 35 | selection.setSpacing(25); 36 | selection.setPadding(new Insets(5)); 37 | leftColumn.getChildren().add(selection); 38 | 39 | Label select = new Label("Select the header"); 40 | select.setStyle("-fx-font: 18px Tahoma; -fx-font-weight: bold; -fx-alignment: TOP-CENTER;"); 41 | selection.getChildren().add(select); 42 | 43 | this.headerSelection = new ComboBox<>(); 44 | this.headerSelection.getItems().setAll(HeaderPins.values()); 45 | this.headerSelection.setOnAction(this::drawHeaders); 46 | selection.getChildren().add(this.headerSelection); 47 | 48 | this.headerHolder = new HBox(); 49 | leftColumn.getChildren().add(this.headerHolder); 50 | 51 | this.tableholder = new HBox(); 52 | holder.getChildren().add(this.tableholder); 53 | 54 | var scene = new Scene(holder, 1800, 800); 55 | stage.setScene(scene); 56 | stage.setTitle("Raspberry Pi headers"); 57 | stage.show(); 58 | } 59 | 60 | private void drawHeaders(ActionEvent actionEvent) { 61 | HeaderPins headerPins = this.headerSelection.getValue(); 62 | 63 | this.headerHolder.getChildren().clear(); 64 | this.headerHolder.getChildren().add(new HeaderPinView(headerPins)); 65 | 66 | this.tableholder.getChildren().clear(); 67 | this.tableholder.getChildren().add(new HeaderTableView(headerPins)); 68 | } 69 | 70 | public static void main(String[] args) { 71 | launch(); 72 | } 73 | } -------------------------------------------------------------------------------- /Chapter_05_PiPinning/javafx-pinning-info/src/main/java/be/webtechie/pinninginfo/util/Converter.java: -------------------------------------------------------------------------------- 1 | package be.webtechie.pinninginfo.util; 2 | 3 | import javafx.scene.paint.Color; 4 | 5 | public class Converter { 6 | 7 | private Converter() { 8 | // NOP 9 | } 10 | 11 | public static Color intToColor(int value) { 12 | return Color.rgb( 13 | (value & 0xFF0000) >> 16, 14 | (value & 0x00FF00) >> 8, 15 | (value & 0x0000FF)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_05_PiPinning/javafx-pinning-info/src/main/java/be/webtechie/pinninginfo/views/BooleanTableCell.java: -------------------------------------------------------------------------------- 1 | package be.webtechie.pinninginfo.views; 2 | 3 | import javafx.scene.control.TableCell; 4 | import javafx.scene.control.TableRow; 5 | import javafx.scene.paint.Color; 6 | 7 | /** 8 | * View helper function to colorize a table cell green (true) or red (false) depending on the value of its cell. 9 | */ 10 | public class BooleanTableCell extends TableCell { 11 | @Override 12 | protected void updateItem(Boolean value, boolean empty) { 13 | super.updateItem(value, empty); 14 | 15 | if (empty) { 16 | this.setText(""); 17 | this.setStyle("-fx-font-weight: bold; -fx-background-color: none; -fx-alignment: TOP-CENTER;"); 18 | } else { 19 | this.setText(String.valueOf(value).toUpperCase()); 20 | 21 | if (value) { 22 | this.setTextFill(Color.BLACK); 23 | this.setStyle("-fx-font-weight: bold; -fx-background-color: lightgreen; -fx-alignment: TOP-CENTER;"); 24 | } else { 25 | this.setTextFill(Color.BLACK); 26 | this.setStyle("-fx-font-weight: normal; -fx-background-color: orangered; -fx-alignment: TOP-CENTER;"); 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Chapter_05_PiPinning/javafx-pinning-info/src/main/java/be/webtechie/pinninginfo/views/HeaderPinView.java: -------------------------------------------------------------------------------- 1 | package be.webtechie.pinninginfo.views; 2 | 3 | import java.util.List; 4 | 5 | import com.pi4j.boardinfo.definition.HeaderPins; 6 | import com.pi4j.boardinfo.definition.PinType; 7 | import com.pi4j.boardinfo.model.HeaderPin; 8 | import javafx.geometry.Insets; 9 | import javafx.scene.layout.HBox; 10 | import javafx.scene.layout.VBox; 11 | 12 | /** 13 | * Visualizes the header in two columns, as it looks on the board. 14 | */ 15 | public class HeaderPinView extends VBox { 16 | 17 | /** 18 | * Constructor to create the pin visualization of the header. 19 | * 20 | * @param headerPins {@link HeaderPins} to be visualized. 21 | */ 22 | public HeaderPinView(HeaderPins headerPins) { 23 | this.setSpacing(25); 24 | 25 | HBox rows = new HBox(); 26 | rows.getChildren().add(this.getRow(headerPins.getPins(), true)); 27 | rows.getChildren().add(this.getRow(headerPins.getPins(), false)); 28 | this.getChildren().add(rows); 29 | 30 | this.getChildren().add(this.getLegend()); 31 | } 32 | 33 | /** 34 | * Visualizes the legend for the header. 35 | * 36 | * @return {@link VBox} with the pin types. 37 | */ 38 | private VBox getLegend() { 39 | VBox vBox = new VBox(); 40 | vBox.setSpacing(1); 41 | vBox.setPadding(new Insets(1, 1, 1, 1)); 42 | vBox.setMaxWidth(200); 43 | 44 | for (PinType pinType : PinType.values()) { 45 | vBox.getChildren().add(new PinTypeView(pinType)); 46 | } 47 | 48 | return vBox; 49 | } 50 | 51 | /** 52 | * Visualizes one side of the header. 53 | * 54 | * @param pins {@link List} of {@link HeaderPin} for which the header must be visualized. 55 | * @param firstRow True for first row, false for second. 56 | * 57 | * @return {@link VBox} with the pins of the header row. 58 | */ 59 | private VBox getRow(List pins, boolean firstRow) { 60 | VBox vBox = new VBox(); 61 | vBox.setSpacing(1); 62 | vBox.setPadding(new Insets(1, 1, 1, 1)); 63 | 64 | for (int i = (firstRow ? 0 : 1); i < pins.size(); i += 2) { 65 | vBox.getChildren().add(new PinView(pins.get(i), !firstRow)); 66 | } 67 | 68 | return vBox; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Chapter_05_PiPinning/javafx-pinning-info/src/main/java/be/webtechie/pinninginfo/views/PinTypeView.java: -------------------------------------------------------------------------------- 1 | package be.webtechie.pinninginfo.views; 2 | 3 | import be.webtechie.pinninginfo.util.Converter; 4 | import com.pi4j.boardinfo.definition.PinType; 5 | import javafx.geometry.Insets; 6 | import javafx.scene.control.Label; 7 | import javafx.scene.layout.Background; 8 | import javafx.scene.layout.BackgroundFill; 9 | import javafx.scene.layout.CornerRadii; 10 | import javafx.scene.layout.HBox; 11 | import javafx.scene.layout.VBox; 12 | 13 | /** 14 | * Visualizes the {@link PinType}. 15 | */ 16 | class PinTypeView extends HBox { 17 | /** 18 | * Constructor to create a legend field for a {@link PinType}. 19 | * 20 | * @param pinType The {@link PinType} to be visualized. 21 | */ 22 | PinTypeView(final PinType pinType) { 23 | this.setStyle("-fx-border-color: black; -fx-border-width: 2; -fx-border-style: solid;"); 24 | this.setPadding(new Insets(1, 1, 1, 1)); 25 | this.setSpacing(10); 26 | this.setPrefHeight(20); 27 | 28 | VBox color = new VBox(); 29 | color.setPrefWidth(25); 30 | color.setPrefHeight(25); 31 | color.setBackground(new Background(new BackgroundFill(Converter.intToColor(pinType.getColor()), CornerRadii.EMPTY, Insets.EMPTY))); 32 | this.getChildren().add(color); 33 | 34 | Label name = new Label(pinType.getLabel()); 35 | name.setStyle("-fx-font: 12px Tahoma; -fx-font-weight: bold;"); 36 | this.getChildren().add(name); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter_05_PiPinning/javafx-pinning-info/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module be.webtechie { 2 | requires javafx.controls; 3 | requires com.pi4j; 4 | opens be.webtechie to javafx.graphics; 5 | } -------------------------------------------------------------------------------- /Chapter_05_PiPinning/javafx-pinning-info/target/pinning-info-0.0.1-jar-with-dependencies.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDelporte/JavaOnRaspberryPi/31e2c419c462521376089e4b89621c4e84b5b7d0/Chapter_05_PiPinning/javafx-pinning-info/target/pinning-info-0.0.1-jar-with-dependencies.jar -------------------------------------------------------------------------------- /Chapter_05_PiPinning/javafx-pinning-info/target/pinning-info-0.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDelporte/JavaOnRaspberryPi/31e2c419c462521376089e4b89621c4e84b5b7d0/Chapter_05_PiPinning/javafx-pinning-info/target/pinning-info-0.0.1.jar -------------------------------------------------------------------------------- /Chapter_06_Maven/README.md: -------------------------------------------------------------------------------- 1 | # Chapter 3: Maven 2 | 3 | ## Running Java unit tests in Visual Studio Code 4 | https://code.visualstudio.com/docs/java/java-testing 5 | 6 | ## Read more 7 | https://blogs.oracle.com/javamagazine/the-largest-survey-ever-of-java-developers#anchor_3 8 | 9 | https://twitter.com/johanvos/status/1161594152867549185 10 | * [System.out.println vs Loggers](https://www.baeldung.com/java-system-out-println-vs-loggers) 11 | * [Free course: Maven Quick Start: A Fast Introduction to Maven by Example](https://www.udemy.com/course/maven-quick-start/) -------------------------------------------------------------------------------- /Chapter_06_Maven/java-maven-logging/demoApplication.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDelporte/JavaOnRaspberryPi/31e2c419c462521376089e4b89621c4e84b5b7d0/Chapter_06_Maven/java-maven-logging/demoApplication.log -------------------------------------------------------------------------------- /Chapter_06_Maven/java-maven-logging/logs/app.log: -------------------------------------------------------------------------------- 1 | 20200220 08:40:51,611 | INFO | [App] | Info message 2 | 20200220 08:40:51,611 | WARN | [App] | Warn message 3 | 20200220 08:40:51,611 | ERROR | [App] | Error message 4 | -------------------------------------------------------------------------------- /Chapter_06_Maven/java-maven-logging/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | be.webtechie 5 | java-maven-logging 6 | jar 7 | 1.0-SNAPSHOT 8 | java-maven-logging 9 | http://maven.apache.org 10 | 11 | 12 | 13 | org.apache.logging.log4j 14 | log4j-core 15 | 2.17.1 16 | 17 | 18 | 19 | 20 | 21 | 22 | org.apache.maven.plugins 23 | maven-compiler-plugin 24 | 3.8.0 25 | 26 | 11 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Chapter_06_Maven/java-maven-logging/src/main/java/be/webtechie/App.java: -------------------------------------------------------------------------------- 1 | package be.webtechie; 2 | 3 | import org.apache.logging.log4j.Level; 4 | import org.apache.logging.log4j.LogManager; 5 | import org.apache.logging.log4j.Logger; 6 | import org.apache.logging.log4j.core.appender.ConsoleAppender; 7 | import org.apache.logging.log4j.core.appender.RollingFileAppender; 8 | import org.apache.logging.log4j.core.layout.PatternLayout; 9 | 10 | /** 11 | * Hello world! 12 | * 13 | */ 14 | public class App { 15 | private static Logger logger = LogManager.getLogger(App.class); 16 | 17 | public static void main( String[] args ) { 18 | //Logger.getRootLogger().getLoggerRepository().resetConfiguration(); 19 | initLog(); 20 | 21 | logger.debug("Debug message"); 22 | logger.info("Info message"); 23 | logger.warn("Warn message"); 24 | logger.error("Error message"); 25 | } 26 | 27 | private static void initLog() { 28 | PatternLayout logPattern = PatternLayout.newBuilder() 29 | .withPattern("%d{yyyyMMdd HH:mm:ss,SSS} | %-5p | [%c{1}] | %m%n") 30 | .build(); 31 | 32 | // Log to the console, similar to System.out 33 | ConsoleAppender console = ConsoleAppender.newBuilder() 34 | .setName("ConsoleLogger") 35 | .setLayout(logPattern) 36 | .build(); 37 | logger.get 38 | Logger.getRootLogger().addAppender(console); 39 | 40 | // Log to a file to store it for later reference, creating max 5 files of 10MB 41 | RollingFileAppender file = RollingFileAppender.newBuilder() 42 | .setName("FileLogger") 43 | .setConfiguration(new ) 44 | .setFile("logs/app.log") 45 | .setl 46 | file.setLayout(logPattern); 47 | file.setThreshold(Level.INFO); 48 | file.setAppend(true); 49 | file.activateOptions(); 50 | file.setMaxFileSize("10MB"); 51 | file.setMaxBackupIndex(5); 52 | Logger.getRootLogger().addAppender(file); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Chapter_06_Maven/java-maven-logging/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter_06_Maven/java-maven-minimal/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | be.webtechie 5 | java-maven-minimal 6 | jar 7 | 1.0-SNAPSHOT 8 | java-maven-minimal 9 | http://maven.apache.org 10 | 11 | 12 | junit 13 | junit 14 | 4.13.1 15 | test 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Chapter_06_Maven/java-maven-minimal/src/main/java/be/webtechie/App.java: -------------------------------------------------------------------------------- 1 | package be.webtechie; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World!" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_06_Maven/java-maven-minimal/src/test/java/be/webtechie/AppTest.java: -------------------------------------------------------------------------------- 1 | package be.webtechie; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest extends TestCase 11 | { 12 | /** 13 | * Create the test case 14 | * 15 | * @param testName name of the test case 16 | */ 17 | public AppTest( String testName ) 18 | { 19 | super( testName ); 20 | } 21 | 22 | /** 23 | * @return the suite of tests being tested 24 | */ 25 | public static Test suite() 26 | { 27 | return new TestSuite( AppTest.class ); 28 | } 29 | 30 | /** 31 | * Rigourous Test :-) 32 | */ 33 | public void testApp() 34 | { 35 | assertTrue( true ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter_06_Maven/scripts/start-new-maven-project.sh: -------------------------------------------------------------------------------- 1 | mvn archetype:generate -DgroupId=be.webtechie -DartifactId=java-maven-minimal -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -------------------------------------------------------------------------------- /Chapter_07_JavaFX/README.md: -------------------------------------------------------------------------------- 1 | # Chapter 7: JavaFX 2 | 3 | ## Content 4 | 5 | ### Scripts 6 | The scripts directory contains the scripts as described in the book 7 | 8 | * To run them on Windows, you can just double click on them. 9 | * To execute on Linux, go to terminal and follow these steps: 10 | 11 | ``` 12 | $ cd scripts/ 13 | $ chmod +x {SCRIPT_NAME}.sh 14 | $ ./{SCRIPT_NAME}.sh 15 | ``` 16 | 17 | ### Java projects 18 | 19 | #### javafx-minimal 20 | Automatically generated minimal JavaFX application with the tools provided by GluonHQ. 21 | 22 | #### RGB led controller 23 | https://tutorials-raspberrypi.com/how-to-control-a-raspberry-pi-ws2801-rgb-led-strip/ 24 | https://learn.adafruit.com/neopixels-on-raspberry-pi 25 | https://www.admfactory.com/rgb-led-on-raspberry-pi-using-java/ 26 | https://tutorials-raspberrypi.com/connect-control-raspberry-pi-ws2812-rgb-led-strips/ 27 | https://dordnung.de/raspberrypi-ledstrip/ 28 | 29 | ### 30 | 31 | ## Read more 32 | * https://twitter.com/dlemmermann/status/1173753969652273152 33 | * https://twitter.com/carldea/status/1173807359178739712 34 | * https://jaxenter.com/javafx-13-release-interview-johan-vos-161947.html 35 | * https://github.com/JonathanGiles/scenic-view 36 | * https://code.makery.ch/library/javafx-tutorial/ 37 | * http://tutorials.jenkov.com/javafx/index.html 38 | * https://openjfx.io/openjfx-docs/ 39 | * [OpenJFX examples for multiple IDE's](https://github.com/openjfx/samples ) 40 | * [JavaFX Programming Tutorials](https://o7planning.org/en/11009/javafx) 41 | * https://github.com/openjfx/javafx-maven-archetypes/tree/master/javafx-archetype-fxml 42 | -------------------------------------------------------------------------------- /Chapter_07_JavaFX/java-hellogpio/HelloGpio.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | 3 | public class HelloGpio { 4 | public static void main (String[] args) { 5 | System.out.println("Hello Gpio"); 6 | 7 | try { 8 | Runtime.getRuntime().exec("gpio mode 3 out"); 9 | 10 | var loopCounter = 0; 11 | var on = true; 12 | 13 | while (loopCounter < 10) { 14 | System.out.println("Changing LED to " + (on ? "on" : "off")); 15 | Runtime.getRuntime().exec("gpio write 3 " + (on ? "1" : "0")); 16 | 17 | on = !on; 18 | 19 | Thread.sleep(500); 20 | 21 | loopCounter++; 22 | } 23 | } catch (IOException ex) { 24 | System.err.println("IOException from Runtim: " + ex.getMessage()); 25 | } catch (InterruptedException ex) { 26 | System.err.println("InterruptedException from Thread: " + ex.getMessage()); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-dashboard/src/main/java/be/webtechie/App.java: -------------------------------------------------------------------------------- 1 | package be.webtechie; 2 | 3 | import javafx.application.Application; 4 | import javafx.application.Platform; 5 | import javafx.scene.Scene; 6 | import javafx.stage.Stage; 7 | 8 | /** 9 | * JavaFX App 10 | */ 11 | public class App extends Application { 12 | 13 | @Override 14 | public void start(Stage stage) { 15 | Platform.setImplicitExit(true); 16 | 17 | var scene = new Scene(new FxScreen(), 640, 480); 18 | stage.setScene(scene); 19 | stage.show(); 20 | 21 | // Make sure the application quits completely on close 22 | stage.setOnCloseRequest(t -> { 23 | Platform.exit(); 24 | System.exit(0); 25 | }); 26 | } 27 | 28 | public static void main(String[] args) { 29 | launch(); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-dashboard/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module be.webtechie { 2 | requires javafx.controls; 3 | requires eu.hansolo.tilesfx; 4 | exports be.webtechie; 5 | } -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-i2c-relay/README.md: -------------------------------------------------------------------------------- 1 | # JavaFX application to control two relay boards 2 | 3 | Controls the relays with I²C with terminal command "i2cset -y 1" using ToggleSwitches from the ControlsFX library. 4 | 5 | ## Screenshot 6 | 7 | ![Raspberry Pi with two relay boards](pictures/relay-enabled.jpg) 8 | 9 | ![Running JavaFX application with logging in terminal](pictures/relay-app-on-pi.png) 10 | 11 | ## Read more 12 | * [ControlsFX on GitHub](https://github.com/controlsfx/controlsfx) 13 | * [GeeekPi Raspberry Pi Expansion Board 4 Channel Relay Board Module](https://www.amazon.com/gp/product/B07Q2P9D7K/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1) 14 | * [DockerPi 4 Channel Relay SKU: EP-0099](https://wiki.52pi.com/index.php/DockerPi_4_Channel_Relay_SKU:_EP-0099) -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-i2c-relay/pictures/relay-app-on-pi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDelporte/JavaOnRaspberryPi/31e2c419c462521376089e4b89621c4e84b5b7d0/Chapter_07_JavaFX/javafx-i2c-relay/pictures/relay-app-on-pi.png -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-i2c-relay/pictures/relay-enabled.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDelporte/JavaOnRaspberryPi/31e2c419c462521376089e4b89621c4e84b5b7d0/Chapter_07_JavaFX/javafx-i2c-relay/pictures/relay-enabled.jpg -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-i2c-relay/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | be.webtechie 5 | javafx-pi4j-i2c-relay 6 | 0.0.1 7 | 8 | 9 | UTF-8 10 | 11 11 | 11 12 | 13 | 14 | 15 | 16 | org.openjfx 17 | javafx-controls 18 | 11.0.2 19 | 20 | 21 | 22 | org.controlsfx 23 | controlsfx 24 | 11.0.1 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.apache.maven.plugins 32 | maven-compiler-plugin 33 | 3.8.0 34 | 35 | 11 36 | 37 | 38 | 39 | 40 | maven-assembly-plugin 41 | 2.2.1 42 | 43 | 44 | jar-with-dependencies 45 | 46 | 47 | 48 | true 49 | be.webtechie.App 50 | 51 | 52 | 53 | 54 | 55 | make-assembly 56 | package 57 | 58 | single 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-i2c-relay/src/main/java/be/webtechie/App.java: -------------------------------------------------------------------------------- 1 | package be.webtechie; 2 | 3 | import be.webtechie.i2c.RelayController; 4 | import be.webtechie.i2c.definition.Board; 5 | import be.webtechie.i2c.definition.Relay; 6 | import be.webtechie.i2c.definition.State; 7 | import be.webtechie.ui.ToggleSwitchScreen; 8 | import java.util.Arrays; 9 | import javafx.application.Application; 10 | import javafx.scene.Scene; 11 | import javafx.stage.Stage; 12 | 13 | public class App extends Application { 14 | 15 | @Override 16 | public void start(Stage stage) { 17 | System.out.println("Starting application"); 18 | 19 | // Set all relays out 20 | RelayController.setRelays( 21 | Arrays.asList(Board.BOARD_1, Board.BOARD_2), 22 | Arrays.asList(Relay.RELAY_1, Relay.RELAY_2, Relay.RELAY_3, Relay.RELAY_4), 23 | State.STATE_OFF); 24 | System.out.println("All relays turned off"); 25 | 26 | var scene = new Scene(new ToggleSwitchScreen(), 640, 480); 27 | stage.setScene(scene); 28 | stage.setTitle("I²C Relay controller"); 29 | stage.show(); 30 | } 31 | 32 | public static void main(String[] args) { 33 | launch(); 34 | } 35 | } -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-i2c-relay/src/main/java/be/webtechie/i2c/definition/Board.java: -------------------------------------------------------------------------------- 1 | package be.webtechie.i2c.definition; 2 | 3 | public enum Board { 4 | BOARD_1(0x10), 5 | BOARD_2(0x11); 6 | 7 | private final int address; 8 | 9 | Board(int address) { 10 | this.address = address; 11 | } 12 | 13 | public int getAddress() { 14 | return this.address; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-i2c-relay/src/main/java/be/webtechie/i2c/definition/Relay.java: -------------------------------------------------------------------------------- 1 | package be.webtechie.i2c.definition; 2 | 3 | public enum Relay { 4 | RELAY_1((byte) 0x01), 5 | RELAY_2((byte) 0x02), 6 | RELAY_3((byte) 0x03), 7 | RELAY_4((byte) 0x04); 8 | 9 | private final byte channel; 10 | 11 | Relay(byte channel) { 12 | this.channel = channel; 13 | } 14 | 15 | public byte getChannel() { 16 | return this.channel; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-i2c-relay/src/main/java/be/webtechie/i2c/definition/State.java: -------------------------------------------------------------------------------- 1 | package be.webtechie.i2c.definition; 2 | 3 | public enum State { 4 | STATE_ON((byte) 0xFF), 5 | STATE_OFF((byte) 0x00); 6 | 7 | private final byte value; 8 | 9 | State(byte value) { 10 | this.value = value; 11 | } 12 | 13 | public byte getValue() { 14 | return this.value; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-i2c-relay/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module be.webtechie { 2 | requires javafx.controls; 3 | requires org.controlsfx.controls; 4 | exports be.webtechie; 5 | } -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-minimal-fxml/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | be.webtechie 5 | javafx-fxml-minimal 6 | 0.0.1 7 | 8 | UTF-8 9 | 11 10 | 11 11 | 12 | 13 | 14 | org.openjfx 15 | javafx-controls 16 | 11.0.2 17 | 18 | 19 | org.openjfx 20 | javafx-fxml 21 | 11.0.2 22 | 23 | 24 | 25 | 26 | 27 | org.apache.maven.plugins 28 | maven-compiler-plugin 29 | 3.8.0 30 | 31 | 11 32 | 33 | 34 | 35 | org.openjfx 36 | javafx-maven-plugin 37 | 0.0.1 38 | 39 | be.webtechie.App 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-minimal-fxml/src/main/java/be/webtechie/App.java: -------------------------------------------------------------------------------- 1 | package be.webtechie; 2 | 3 | import javafx.application.Application; 4 | import javafx.fxml.FXMLLoader; 5 | import javafx.scene.Parent; 6 | import javafx.scene.Scene; 7 | import javafx.stage.Stage; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * JavaFX App 13 | */ 14 | public class App extends Application { 15 | 16 | private static Scene scene; 17 | 18 | @Override 19 | public void start(Stage stage) throws IOException { 20 | scene = new Scene(loadFXML("primary")); 21 | stage.setScene(scene); 22 | stage.show(); 23 | } 24 | 25 | static void setRoot(String fxml) throws IOException { 26 | scene.setRoot(loadFXML(fxml)); 27 | } 28 | 29 | private static Parent loadFXML(String fxml) throws IOException { 30 | FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml")); 31 | return fxmlLoader.load(); 32 | } 33 | 34 | public static void main(String[] args) { 35 | launch(); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-minimal-fxml/src/main/java/be/webtechie/PrimaryController.java: -------------------------------------------------------------------------------- 1 | package be.webtechie; 2 | 3 | import java.io.IOException; 4 | import javafx.fxml.FXML; 5 | 6 | public class PrimaryController { 7 | 8 | @FXML 9 | private void switchToSecondary() throws IOException { 10 | App.setRoot("secondary"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-minimal-fxml/src/main/java/be/webtechie/SecondaryController.java: -------------------------------------------------------------------------------- 1 | package be.webtechie; 2 | 3 | import java.io.IOException; 4 | import javafx.fxml.FXML; 5 | 6 | public class SecondaryController { 7 | 8 | @FXML 9 | private void switchToPrimary() throws IOException { 10 | App.setRoot("primary"); 11 | } 12 | } -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-minimal-fxml/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module be.webtechie { 2 | requires javafx.controls; 3 | requires javafx.fxml; 4 | 5 | opens be.webtechie to javafx.fxml; 6 | exports be.webtechie; 7 | } -------------------------------------------------------------------------------- /Chapter_07_JavaFX/javafx-minimal-fxml/src/main/resources/be/webtechie/primary.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |