guis for applets [email protected] introduction applets and swing/jfc alternatives to swing...

12
GUIs for Applets [email protected] Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces How do I build a GUI? Conclusion

Upload: barnard-kevin-ford

Post on 16-Jan-2016

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GUIs for Applets N.A.Shulver@staffs.ac.uk Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces

GUIs for Applets

[email protected]

IntroductionApplets and Swing/JFC

Alternatives to Swing

Look-and-Feel issues

Example applet graphical user interfaces

How do I build a GUI?

Conclusion

Page 2: GUIs for Applets N.A.Shulver@staffs.ac.uk Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces

GUIs for Applets

[email protected]

Applets and Swing/JFC

Swing is a kit of GUI “widgets” - it provides a simple way to create, position and interact with standard interface components

It is a major part of the Java Foundation Classes (c.f. MFC, Microsoft Foundation Classes)

It is a “lightweight” component library, uses the MVC (model-view-controller) architecture design pattern

Applets may use most Swing componentsFor security reasons some are restricted (which ones?)

Page 3: GUIs for Applets N.A.Shulver@staffs.ac.uk Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces

GUIs for Applets

[email protected]

Alternatives to Swing

The original GUI system for Java was called the “Abstract Windowing Toolkit” or AWT

NB Swing is based on many of the AWT components, either through compatible methods or through inheritance

AWT is a “heavyweight” component library, uses the widgets built into the underlying OS architecture

It has some OS-specific behaviour and thus some portability problems

Page 4: GUIs for Applets N.A.Shulver@staffs.ac.uk Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces

GUIs for Applets

[email protected]

Alternatives to Swing

SWT is the Standard Widget Toolkit originally developed by IBM as part of the Eclipse project (see http://www.developer.com/java/other/article.php/2179061)

It is seen a “thin wrapper” over the native GUI of the host OS – it is a “heavyweight” library

It is not OS-specific but was originally designed to run in MS Windows

SWT attempts to use the strengths of the Swing and AWT approaches while staying simple and quick

Page 5: GUIs for Applets N.A.Shulver@staffs.ac.uk Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces

GUIs for Applets

[email protected]

Examples

Simple visual applet with mouse-sensitive image-based components

Note that the title bar is not settable

This is a Swing-based Japplet running in Win XP

Page 6: GUIs for Applets N.A.Shulver@staffs.ac.uk Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces

GUIs for Applets

[email protected]

Swing Example

Quite a lot of components in this simple applet

JLabel, JCheckBox, JTextArea, JComboBox, JButton, JRadioButton

This applet will look very similar in any graphical OS

Page 7: GUIs for Applets N.A.Shulver@staffs.ac.uk Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces

GUIs for Applets

[email protected]

Swing Example

This example shows most of the simple Swing components

The GUI is X-Windows

http://commons.wikimedia.org/ wiki/Image:Gui-widgets.png

Page 8: GUIs for Applets N.A.Shulver@staffs.ac.uk Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces

GUIs for Applets

[email protected]

SWT platform-specific examples

The Standard Widget Toolkit (SWT) library uses heavyweight components

Tied to the look-and-feel of the host OS

Page 9: GUIs for Applets N.A.Shulver@staffs.ac.uk Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces

GUIs for Applets

[email protected]

SWT – a familiar example

Eclipse has one of the best-known examples of SWT in action

Looks good and works well

Page 10: GUIs for Applets N.A.Shulver@staffs.ac.uk Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces

GUIs for Applets

[email protected]

Building a GUI

Choose AWT, Swing (recommended) or SWT

Learn about component types, event handlers and layout options – documentation and examples

Design a user interface and critically evaluate it

Revise and repeat!

For background on development in AWT, with reference to Swing, see “Graphical User Interface (GUI) Fundamentals” (old article)[http://www.wirelessdevnet.com/channels/java/training/javagui.html]

Page 11: GUIs for Applets N.A.Shulver@staffs.ac.uk Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces

GUIs for Applets

[email protected]

ConclusionThere are varied ways to build GUI applications in

Java AppletsDifferent approaches have different strengths and

weaknessesSwing is often a good choice (widely supported,

flexible, elegant but quite complex)Predefined widgets/components are available for

most tasksDesigning a good interface is hard

Page 12: GUIs for Applets N.A.Shulver@staffs.ac.uk Introduction Applets and Swing/JFC Alternatives to Swing Look-and-Feel issues Example applet graphical user interfaces

GUIs for Applets

[email protected]

Optional Further Reading

Swing article on Wikipedia [http://en.wikipedia.org/wiki/Java_Swing]

Applet article on Wikipedia[http://en.wikipedia.org/wiki/Java_applet]

Standard Widget Toolkit article on Wikipedia[http://en.wikipedia.org/wiki/Standard_Widget_Toolkit]

Swing documentation (Sun)[http://java.sun.com/javase/6/docs/api/index.html]

How to make Applets (Sun)[http://java.sun.com/docs/books/tutorial/uiswing/components/applet.html]