Presentation is loading. Please wait.

Presentation is loading. Please wait.

School of Computer Science & Information Technology G6DICP - Lecture 17 GUI (Graphical User Interface) Programming.

Similar presentations


Presentation on theme: "School of Computer Science & Information Technology G6DICP - Lecture 17 GUI (Graphical User Interface) Programming."— Presentation transcript:

1 School of Computer Science & Information Technology G6DICP - Lecture 17 GUI (Graphical User Interface) Programming

2 2 Java GUI Class Libraries AWT – Abstract Windows Toolkit AWT – Abstract Windows Toolkit Small and relatively simple GUI library Small and relatively simple GUI library Bundled with JDK 1.0 Bundled with JDK 1.0 Major revisions in JDK 1.1 (not compatible with 1.0) Major revisions in JDK 1.1 (not compatible with 1.0) No fundamental changes since JDK 1.2 (Java 2) No fundamental changes since JDK 1.2 (Java 2) Swing – Java Foundation Classes Swing – Java Foundation Classes Large GUI library – essentially a superset of AWT Large GUI library – essentially a superset of AWT The “Swing Set” The “Swing Set” Compatible with JDK 1.1 (not included) Compatible with JDK 1.1 (not included) Bundled with Java 2 Bundled with Java 2 Swing and AWT are similar in principle, but Swing is very much larger – both in terms of number of classes and methods. Swing and AWT are similar in principle, but Swing is very much larger – both in terms of number of classes and methods.

3 3 Major GUI concepts Windows Windows Containers Containers Components Components Events Events

4 4 The Java Frame class java.awt.Frame java.awt.Frame Frame objects represent windows Frame objects represent windows Graphical programs (almost) always have at least one Frame Graphical programs (almost) always have at least one Frame Rarely used directly usually subclassed Rarely used directly usually subclassed Invoking the show() method causes window to be displayed Invoking the show() method causes window to be displayed The constructor of a Frame is usually where initialisation code is placed (and often most of the layout/UI of a graphical program) The constructor of a Frame is usually where initialisation code is placed (and often most of the layout/UI of a graphical program)

5 5 The Paint Method java.awt.Frame.paint(Graphic g) java.awt.Frame.paint(Graphic g) Executed automatically whenever the screen is redrawn Executed automatically whenever the screen is redrawn Overriden to contain code that writes to the screen Overriden to contain code that writes to the screen Be careful Be careful Avoid accidental recursion Avoid accidental recursion The paint method should never be invoked directly The paint method should never be invoked directly Since paint is executed every time the screen is redrawn – do not do anything time consuming in it, e.g. Since paint is executed every time the screen is redrawn – do not do anything time consuming in it, e.g. File i/o File i/o Large loops or recursion Large loops or recursion Complex calculations Complex calculations

6 6 The Graphic Class java.awt.Graphic java.awt.Graphic Abstract class containing various drawing methods Abstract class containing various drawing methods Never instantiated in code Never instantiated in code Instantiated by the VM, and an instance passed into the paint() method Instantiated by the VM, and an instance passed into the paint() method Methods of this instance are used to write onto the screen Methods of this instance are used to write onto the screen


Download ppt "School of Computer Science & Information Technology G6DICP - Lecture 17 GUI (Graphical User Interface) Programming."

Similar presentations


Ads by Google