CSE 1030: Implementing GUI Mark Shtern
Summary Implementation of Inheritance Custom Exceptions
Introduction to Abstract Classes In order to postpone the definition of a method, Java allows an abstract method to be declared An abstract method has a heading, but no method body The body of the method is defined in the derived classes The class that contains an abstract method is called an abstract class
Abstract Classes Use to declare common characteristics of subclasses Cannot be instantiated Declare with the abstract keyword Use as a superclass for other classes that extend the abstract class Abstract classes let you define some behaviours; they force your subclasses to provide others
Interfaces An interface is something like an extreme case of an abstract class However, an interface is not a class It is a type that can be satisfied by any class that implements the interface Examples: List, Set, Comparable The syntax for defining an interface is similar to that of defining a class Except the word interface is used in place of class An interface specifies a set of methods that any class that implements the interface must have It contains method headings and constant definitions only It contains no instance variables nor any complete method definitions
Interfaces An interface and all of its method headings should be declared public They cannot be given private When a class implements an interface, it must make all the methods in the interface public Because an interface is a type, a method may be written with a parameter of an interface type That parameter will accept as an argument any class that implements the interface Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Interfaces An interface serves a function similar to a base class, though it is not a base class A class may implement several interfaces
GUI
MVC
Our goal
High-Level Design
View
View
JMenuBar
Implementation Model View Controller Store titles Set title Load menu from model Controller
Implementation GUI Configure menu Create Model Create View Configure view Set size Set default close operation Make view visible
Dynamic Menu Print Selection
Controller
Implementation Controller Model View Event Handler Add menu selection method View Register controller for receiving menu selection event
Shuffle
Implementation View Controller Model Add button Register controller to receive click event from button Controller Modify handler to process button and menu events Model Add method for shuffling menu
Custom Shape