Top
Previous Next
Interfaces, GUIs, and Applets CS 161 - Java

Java GUI Programs

In Java applications that use a graphical user interface (GUI) or other event driven styles you see lots of:
   ...
   Something s = new Something();
   ...
   UserInterfaceComponent c = new UserInterfaceComponent();
   c.addSomethingListener(s);
   ...
and, in the implementation of the Something.java class source, you would see
public class Something
    implements SomethingListener {
   ...
   public void somethingDone() {
   ...
   }
...
}
where SomethingListener is one of a number of interfaces and somethingDone is a method that the somethingListener interface defines.

The SomethingListener interface is a contract that classes agree to abide by by saying they implement the interface.

The UserInterfaceComponents don't have code that refers to the SomeThing class (or any other application specific class that you write); they simply treat all such classes as SomethingListener objects.

This allows the UserInterfaceComponent classes to be independent of application specific classes.


Top
Previous Next
jwd