|
|
FB 4
Internationale Media and Computing
MeSoII: Media Software II
Sommersemester 2003
|
Exercise 5: Model/View/Controller
You started to do SWING with Prof. Fortenbacher in Programming 2. We want to be looking at a software architecture that is increasingly popular and very useful, called the Model/View/Controller architecture. In this exercise you will have a look at how components that are on the screen can hear about
- The
Swing tutorial is to be found at http://developer.java.sun.com/developer/onlineTraining/GUI/Swing2/index.html.
It can be downloaded as .pdf or read on-line. Just glance over the overview.
This just lists the Listener interfaces available. The main thing is to understand
the MVC architecture. MVC is a design pattern (Model-View-Controller) that separates
the interface of an application from the intelligence behind the screen. This
intelligence is also split into a model of what is going on, and a controller that
understands how the application is to behave. There can be different views that
latch on to the same models and controllers. What this means, is that you can
switch out the entire GUI ("Look and feel") without disturbing the logic
of the system. If you want to get deeper into look and feel, look at the Swing1 tutorial.
Pages 15 and 16 have
a simple Swing GUI example (SimpleEvents). Copy the code, compile and run it.
Pushing the button *changes* the contents of the window. Try and add another button
that sets the contents of the window to a default value such as "I feel great!!". - Page
17-20 have an example that uses a simple, AWT style of making a UI. Every time
you enter something in the TextField it will be added to the TextArea. Copy this,
compile it and run it. Read through the problems discussed after the example.
Do you understand this? Summarize in your own words in your
report. A central problem is that you have no guarantee that actions will
be performed in any order. Try and
implement a window that has one TextField that takes numbers, adds them to a List
in a TextArea, and at the same time calculates the current average of the numbers.
- Read
on and then meditate on the structure on page 22.You need a ListView in order
to have this work. You need the three classes ListView, IntVectorModel, and FirstMVC
in order to make it work. This means, of course, that you will need to put each
of these classes in their own file!! Copy the code, compile it, and see that it
works! Now add a field that displays the current maximum and current minimum value
of the sequence of numbers!
The URL to your report,
which will describe what you did during the exercise and include links to your
code, is due in my email box by the start of exercise 4. This means Tuesday at
8.00 for Group 1 and Thursday at 12.00 for Group 2. Do not forget to put your
names on the report! When you send the URL to me, include your partner in the
CC. That way I don't get either 2 emails or none, while each thought the other
was doing it. And when I answer you, I can immediately answer both of you without
having to look up your preferred email account.
Copyright 2003,
Debora Weber-Wulff
(weberwu@fhtw-berlin.de)