19. Java graphical application
Review the presentation Java Graphical Frameworks
Tasks
- Install the Eclipse WindowBuilder plugin.
- Explore the jtm.activity19 package
- Implement the ColorSlider class so that the color sliders change the background color of the test area
Export the application to an executable *.jar file
- Export the ColorSlider class as an executable jar file. In Eclipse, do the following:
- Right-click the ColoSlider.java file in the Package Explorer and select Export...
- Select Java — Runnable JAR file and click Next,
- In the Launch configuration section, select ColorSlider - Aaaaaa (where Aaaaaa is your project),
- In the Export destination section, enter Aaaaaa/src/main/java/jtm/activity19/color-slider.jar (where Aaaaaa is your project).
- Under Library handling, select Package required libraries into generated JAR
- Click Finish,
- If errors/warnings are reported, click OK (you can ignore the warnings, but the errors must be fixed).
Open a terminal and test the jar file from the command line:
cd ~/Aaaaaa/src/main/java/jtm/activity19/
java -jar color-slider.jar- Test the ColorSliderTestSuite test suite tests to pass.
Minimize the jar file
If this is done as a simple export in Eclipse, the jar file contains all the libraries listed as project dependencies that are not required only for the Swing application. You can make the *.jar file much smaller by including only the required libraries.
Install the ant build tool:
sudo apt install ant- In the Package Explorer, right-click on the ColoSlider.java file and select Export...
- Select Java — Runnable JAR file and click Next,
- In the Export destination section, enter Aaaaaa/src/main/java/jtm/activity19/color-slider.jar (where Aaaaaa is your project).
- In the Library handling section, select Package required libraries into generated JAR
- Check Save as ANT script and set its location (e.g. export.xml in your project) and finish exporting.
Open the export.xml file and delete all entries similar to zipfileset dir="... except:
<zipfileset dir="/home/student/.m2/repository/com/miglayout/miglayout/3.5.5" includes="miglayout-3.5.5.jar"/>- Right-click export.xml and select Run as — Ant build.
- Verify that color-slider.jar is now a few hundred kilobytes in size.
Additional information