* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download GUIs - DCU School of Computing
Survey
Document related concepts
Scala (programming language) wikipedia , lookup
Falcon (programming language) wikipedia , lookup
Abstraction (computer science) wikipedia , lookup
Java syntax wikipedia , lookup
Go (programming language) wikipedia , lookup
Name mangling wikipedia , lookup
Library (computing) wikipedia , lookup
Java (programming language) wikipedia , lookup
Design Patterns wikipedia , lookup
Object-oriented programming wikipedia , lookup
Java performance wikipedia , lookup
Class (computer programming) wikipedia , lookup
Transcript
GUI programming Interfaces, subclasses, and abstract classes not only facilitate re-use of code we write ourselves, but also facilitate code re-use on a large scale by making it easier to write libraries of related and interacting classes. Two important examples are libraries for (i) collections, and (ii) GUIs (graphical user interfaces). Collection classes (such as ArrayList, LinkedList etc.) make it easy for the programmer to manage collections of objects. GUI classes allow the user to write graphical user interfaces. Java’s GUI classes are located in two packages called the AWT and Swing packages (it is usual to see import java.awt.*; and import java.swing.*; in programs that use GUIs). AWT and Swing make huge use of inheritance, interfaces, and abstract classes. Abstract classes are used where it is possible to include most of the underlying code for some concept (such as a visible window) in the library, but the final details must be supplied by the user to suit the context (such as the action to be taken when a mouse-click is made on the window). Interfaces are used where a method in the library requires that an object passed as a parameter has certain features. For example, a library method to sort an array of objects will need to insist that the objects can be compared with one another by belonging to a class that implements Comparable. As an example of GUI programming, consider the well-known 15-puzzle with the user interface shown. The outline shape of the program is: import java.awt.*; import javax.swing.*; import java.awt.event.*; class Puzzle15 extends JFrame { private JButton[] pb = ...// numbered buttons ... Puzzle15() { super(" ... } ... The 15 Puzzle"); class Standard implements ActionListener { // for click of a standard-of-play button ... } class PlayButton implements ActionListener { // for click of a numbered button ... GUIs 1 } class WindowHandler extends WindowAdapter { // for window closing click ... } public static void main(String[] s) { new Puzzle15(); } } . See the complete code on the module web page. As an example of the class hierarchy in the Java library, class JFrame used above extends another library class Frame, which in turn extends Window, which extends Container, which extends Component (and which, of course, extends Object). On the other hand, WindowAdapter used above is an abstract class, and the purpose of WindowHandler introduced in the program as an extension is to supply the missing details appropriate to the context of the 15-puzzle. Finally, ActionListener is an interface You know all the Java you need to write GUIs. Study how to do so with the help of any Java textbook, and experiment on some small programs. GUI programming is not examinable. GUIs 2