
498
|
Chapter 12, Miscellany
#98 Add Velocity for Dynamic HTML
HACK
Sunny Outside?
Finally, take WeatherPanel for a spin. It’s a pretty straightforward simulator,
creating a display frame and a collection of Weather objects, and connect-
ing the two. Notice that the
WeatherPanel
is created and configured with the
Weather
objects:
public WeatherPanelSimulator( ) {
JFrame frame = new JFrame("Weather Panel Simulator");
frame.setBounds(200,200, 500, 350);
Weather weather1 = new Weather(
new BigDecimal("82"),
new BigDecimal("40.0"),
new BigDecimal(1),
"Monday");
Weather weather2 = new Weather(
new BigDecimal("75"),
new BigDecimal("65.0"),
new BigDecimal(1),
"Tuesday");
Weather weather3 = new Weather(
new BigDecimal("85"),
new BigDecimal("43.0"),
new BigDecimal(1),
"Wednesday");
ArrayList list = new ArrayList( );
list.add(weather1);
list.add(weather2);
list.add(weather3);
WeatherPanel weatherPanel = new WeatherPanel( );
weatherPanel.displayWeatherByFile("html/today.html", list);
frame.getContentPane().setLayout(new BorderLayout( ));
frame.getContentPane( ).add(
weatherPanel.getComponent( ),
BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show( );
}
This technique is really useful for simple dynamic variable replacement. It
lets you change the interface at runtime without code changes by changing
the HTML, and you can have your graphics designers implement parts of ...