16. GUI Application
Main steps
- Implement color slider GUI application
- Export application in executable *.jar file
- Make jar file smaller
Implement color slider GUI application
- Install WindowBuilder plugin for eclipse.
- Investigate jtm.activity16 package
- Implement class ColorSlider to make color sliders changing test area background color
Export application in executable *.jar file
- Export ColorSlider class as executable jar file. In Eclipse, do following:
- Right click on ColoSlider.java file in Package explorer, and select Export...
- Select Java — Runnable JAR file, and press Next,
- In Launch configuration select ColorSlider - Aaaaaa (where Aaaaaa is your project),
- In Export destination enter Aaaaaa/src/main/java/jtm/activity16/color-slider.jar (where Aaaaaa is your project)
- In Library handling select Package required libraries into generated JAR
- Press Finish,
- If errors/warnings are reported, press OK (you may ignore warnings, but have to fix errors).
Open terminal and check, execution of jar file from command line:
cd ~/Aaaaaa/src/main/java/jtm/activity16/
java -jar color-slider.jar- Check that tests in ColorSliderTestSuite test suite are passing.
Make jar file smaller
When done as simple export in Eclipse, jar file contains all libraries listed as project dependencies included, which are not necessary just for Swing application. You can make *.jar file much smaller by including only required libraries.
Install ant building system:
sudo apt install ant- Right click on ColoSlider.java file in Package explorer, and select Export...
- Select Java — Runnable JAR file, and press Next,
- In Export destination enter Aaaaaa/src/main/java/jtm/activity16/color-slider.jar (where Aaaaaa is your project)
- In Library handling select Package required libraries into generated JAR
- Also select Save as ANT script and set some location of it (e.g. export.xml in your project) and finish export.
Open export.xml file and delete all zipfileset dir="... like entries, except:
<zipfileset dir="/home/student/.m2/repository/com/miglayout/miglayout/3.5.5" includes="miglayout-3.5.5.jar"/>- Right click on export.xml and select Run as — Ant build.
- Check that now color-slider.jar is few hundred kilobytes in size.
More info