10.2.3. An Example: Dynamic Java Code Generation
In the JSP technology for dynamic web pages, you can mix HTML with snippets of Java code, such as
<p>The current date and time is <b><%= new java.util.Date() %></b>.</p>
The JSP engine dynamically compiles the Java code into a servlet. In our sample application, we use a simpler example and generate dynamic Swing code instead. The idea is that you use a GUI builder to lay out the components in a frame and specify the behavior of the components in an external file. Listing 10.5 shows a very simple example of a frame class, and Listing 10.6 shows the code for the button actions. Note that the constructor of the frame class calls an abstract method
addEventHandlers. Our code generator will produce ...