java gui building approaches aleksandar kartelj faculty of mathematics, belgrade...
TRANSCRIPT
![Page 1: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/1.jpg)
Java GUI building approaches
Aleksandar Kartelj
Faculty of Mathematics, Belgrade
11th Workshop “Software Engineering Education and Reverse Engineering”Ohrid, 22nd August – 27th August 2011
![Page 2: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/2.jpg)
Presentation overview
Java GUI API Java GUI builders Manual vs WYSIWYG vs Metadata based
approaches Conclusions
![Page 3: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/3.jpg)
Brief history of Java GUI APIs
AWT, host dependent Internet Foundation Classes (IFC) by Netscape Sun, Netscape and IBM combined technologies
like AWT and IFC to form Java Foundation Classes
JFC later consisted of AWT, Java 2D, Swing…
![Page 4: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/4.jpg)
AWT (Abstract Window Toolkit)
Low level of abstraction over underlying user interface
Control presentation depends on the op. system
Two APIs: Interfaces between Java and native system
for windowing, events, layouts…GUI widgets: buttons, text boxes…
![Page 5: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/5.jpg)
Swing
Written in Java, (doesn’t call native routines of the host, rather its own Java 2D and other)
Consequence: unified but also pluggable look and feel
Model-View-Controller architecture
![Page 6: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/6.jpg)
![Page 7: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/7.jpg)
MVC architecture in Swing
![Page 8: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/8.jpg)
SWT (Standard Widget Toolkit)
Graphical widget toolkit to use with Java platform
Developed originally by IBM, maintained by the Eclipse Foundation
Written in Java, but implementation of toolkit is unique for each platform
Programs that call SWT are portable
![Page 9: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/9.jpg)
SWT design and performance
Referred as “light” Java wrapper around a “heavy” native object
Compromise between low level performance of AWT and high level ease of use of Swing
Too simple and to hard to port to new platforms Not using enough design patterns, especially
MVC as Swing does
![Page 10: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/10.jpg)
GUI Builders
![Page 11: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/11.jpg)
GUI Builders
Most usual approaches: WYSIWYG Metadata (usually XML)
BAD: Mix logic and interface. This is a typical style for small student programs. The code to perform the action of a button is in the button's action listener. This does NOT scale well as programs get bigger.
GOOD: Separate GUI from logic. As programs grow larger, it's essential to separate the GUI interface processing from the logic. This is easy to do by putting the interface and logic in separate classes. Some GUI generators below help accomplish this.
![Page 12: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/12.jpg)
GUI Builders – other problems
Parts of the code are not readable Parts of the code are not editable It will be harder to edit the code later No one can assure that the tool will be
available and supported in the future
![Page 13: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/13.jpg)
Generated code
![Page 14: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/14.jpg)
Manually coded
![Page 15: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/15.jpg)
Difference in code
In this example:≈150 lines of code generated vs ≈100
manually codedNetbeans used GroupLayout, whereas
manual used BorderLayout and FlowLayoutManual code is more readable
![Page 16: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/16.jpg)
XML builders - SwiXml
![Page 17: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/17.jpg)
Merits and drawbacks+ -
GUI by hand Clean, sustainable development. Smaller code. High need for design patterns.
Slow start up, can require longer planning.
WYSIWYG Quick start. Separates GUI from logic. Intuitive for beginners, they can learn from generated code. Two-ways editors are ok.
Low level of code reusability. Doesn’t separate logic from interface
Metadata based
Doesn’t require code recompilation. Very clean MVC approach. Easiest to unify over diff. languages.
XML can get complex and confusing.
![Page 18: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/18.jpg)
Conclusion
Hand coding recommended for professionals, working on complex apps
WYSIWYG is not bad choice for smaller apps and total beginners
Metadata based – probably the future of GUI building
For thinking: WYSIWYG + Metadata?
![Page 19: Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade kartelj@matf.bg.ac.rs 11 th Workshop “Software Engineering Education and](https://reader035.vdocuments.us/reader035/viewer/2022062217/56649f325503460f94c4d8cc/html5/thumbnails/19.jpg)
Thank you for your time.