33.4. Scrollable and Updateable Result Set

 
[Page 1014 ( continued )]

30.3. MVC Variations

A variation of the model-view-controller architecture combines the controller with the view. In this case, a view not only presents the data, but is also used as an interface to interact with the user and accept user input, as shown in Figure 30.5.

Figure 30.5. The view can interact with the user as well as display data.


For example, you can modify the view in the preceding example to enable the user to change the circle's radius using the mouse. When the left mouse button is clicked, the radius is increased by 5 pixels. When the right mouse button is clicked, the radius is decreased by 5 pixels. The new view, named ViewController , can be implemented by extending CircleView , as follows :

   public class   ViewController   extends   CircleView {   public   ViewController() {  // Register mouse listener  addMouseListener(   new   java.awt.event.MouseAdapter() {   public void   mousePressed(java.awt.event.MouseEvent e) {  CircleModel model = getModel();   // Get model  

[Page 1015]
   if   (model ==   null   )   return   ;   if   (e.isMetaDown())  model.setRadius(model.getRadius() -   5   );   // Right button    else    model.setRadius(model.getRadius() +   5   );   // Left button  } }); } } 

Another variation of the model-view-controller architecture adds some of the data from the model to the view so that frequently used data can be accessed directly from the view. Swing components are designed using the MVC architecture. Each Swing GUI component is a view that uses a model to store data. A Swing GUI component contains some data in the model so that it can be accessed directly from the component.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net