Note, that this recipe is not updated long time and could be outdated!
Got it.

16. GUI Application

Tasks

Implement color slider GUI application

  1. Review presentation Java Graphical Frameworks

    Practical exercise

  2. Install WindowBuilder plugin for eclipse.
  3. Investigate jtm.activity16 package
  4. Implement class ColorSlider to make color sliders changing test area background color

Export application in executable *.jar file

  1. Export ColorSlider class as executable jar file. In Eclipse, do following:
    1. Right click on ColoSlider.java file in Package explorer, and select Export...
    2. Select Java — Runnable JAR file, and press Next,
    3. In Launch configuration select ColorSlider - Aaaaaa (where Aaaaaa is your project),
    4. In Export destination enter Aaaaaa/src/main/java/jtm/activity16/color-slider.jar (where Aaaaaa is your project)
    5. In Library handling select Package required libraries into generated JAR
    6. Press Finish,
    7. If errors/warnings are reported, press OK (you may ignore warnings, but have to fix errors).
  2. Open terminal and check, execution of jar file from command line:

    cd ~/Aaaaaa/src/main/java/jtm/activity16/
    java -jar color-slider.jar 
  3. 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.

  1. Install ant building system:

    sudo apt install ant
  2. Right click on ColoSlider.java file in Package explorer, and select Export...
  3. Select Java — Runnable JAR file, and press Next,
    1. In Export destination enter Aaaaaa/src/main/java/jtm/activity16/color-slider.jar (where Aaaaaa is your project)
    2. In Library handling select Package required libraries into generated JAR
    3. Also select Save as ANT script and set some location of it (e.g. export.xml in your project) and finish export.
  4. 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"/>

    Do not delete <fileset dir="${dir.buildfile}/target/classes"/> entry, which is easy to lose between zipfileset dir="... entries!

  5. Right click on export.xml and select Run as — Ant build.
  6. Check that now color-slider.jar is few hundred kilobytes in size.

You can use design of ColorSliderTest.java class as a template for GUI test for your teamwork project.

More info


  

Created by Valdis Vītoliņš on 2021-01-27 15:09
Last modified by Valdis Vītoliņš on 2021-08-11 12:45
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License