SLIDE 2 2 Solutions to Chapter 13 Exercises
The second approach is to define the main method to the applet it- self, instead of defining a separate main class. This technique of making an instantiable class also the the main class is described in the Special Topics No. 3 document. Here’s how such applet can be implemented.
import java.applet.Applet; import java.awt.*; class AppletApp extends Applet
{ //applet methods here public static void main(String[] args) { Frame f = new Frame("AppletFrame"); f.setSize(300, 300); f.add(new AppletApp()); f.setVisible(true); } } 13.3.
One of the GUI objects in the java.awt package that we did not cover in this chapter is List. Look up this class in a Java reference manual and re- view the ListBox class from the javabook package. Do you see the simi- larities between the two? Identify the GUI components used in the
- ListBox. Read the definition of ListBox. Do you understand the code?
ListBox is a dialog (it is a subclass of JavaBookDialog) and contains a List and two Button objects. ListBox provides addItem and deleteItem
methods that correspond to the addItem and delItem methods of List. Both objects have getSelectedItem and getSelectedIndex methods. The
getItemFromIndex corresponds to the getItem method of List. We can
view ListBox as a simple container of a List functionalities.
13.4.
One of the GUI objects in the java.awt package that we did not cover in this chapter is TextArea. Look up this class in a Java reference manual and review the OutputBox class from the javabook package. Identify the GUI components used in the OutputBox. Read the definition of Output-
- Box. Do you understand the code?