HWW#5 Solutions




1) Choose differences between a JApplet and an Applet (choose as many as apply).

    a) Applet is not available in Swing
    b) JApplet is not available on AWT.
    c) Applet is subclass of JApplet in Java 1.2.
    d) none of the above.

Solution : D

2) Answer True/False for the following:
    Since Swing is more recent, it does away with AWT (ie. you can do without AWT).

Solution : False

3)  Explain the difference between a layout manager and a container.

Solution: A layout manager is responsible for arranging the components in a container.  A container simply holds the components, it is not responsible for how they are arranged.

4) Figure 1-BoxLayout

5) Figure 2-FlowLayout

6) Figure 3-BorderLayout

7) If you have an interface with several methods, what is the advantage of adding an adapter class to wrap around that interface? What is an adapter class used for?

Solution:

If you have an adaptor class around an interface you can simply write an implementation for the method that you need rather than implementing all
of the methods since the adaptor class provides trivial implementations of  all of the methods in the interface. So it would be a good idea to use an  adaptor class when you only want to implement a couple of the methods in an interface and not have to worry about writing all of the  methods in the interface.

9) A true statement about inner class I inside outer class O is:
    a) I can see all of O's instance variables and private methods.
    b) O can see all of I's instance variables and private methods.
    c) Every inner class has to be in its own file just as is true with outer classes.
    d) None of the above.

Solution : A

10) Arrange the following Event classes in order of inheritance(parent to child).
    java.awt.AWTEvent, java.awt.event.MouseEvent, java.awt.event.ComponentEvent , java.awt.event.InputEvent

Solution:

java.awt.AWTEvent
java.awt.event.ComponentEvent
java.awt.event.InputEvent
java.awt.event.MouseEvent