Review studio procedures before
Some guidelines for this week's studio:
- Form groups of 3-4 people. No more than 4 people, really!
- The code from this morning's class is
available in your studio workspace.
- Be sure you are signed in with a TA and that you are cleared before
On Thursday we will use the work of this studio to
control picture color using some Swing components. For today, focus on
- Get the name for your group's studi workspace from a TA.
- Organize yourselves around one keyboard/mouse/display. Use the large
displays on the walls to make things easier to work as a group.
If the font is too small on the wall display, follow these
simple :-) instructions:
- In the editor window of a Java file, right-click and choose Preferences
- Near the top of what you next see, click on Text Editors
- Near the bottom of what you next see, click on Colors and Fonts
- Expand Java (not Structured Text Editors!)
- Click Java Editor Text Font
- Click Change
- Pick a juicy font size like 18 or 20 or whatever you like, and OK
- One of you should log in and open eclipse (if you're new to this stuff, ask somebody to help you).
- Access the studio as follows:
- Open the SVN Repository Exploring perspective:
Window...Open Perspective...Other...SVN Repository Exploring
- Click on the New Repository Location icon (looks like a
gold battery with a green plus sign).
- Copy the following URL using your mouse:
- Change XXXXX to your username that you use to log into cec computers. For example, jdl2.
- Be sure the directory after spring10 is studios and
- Change ZZZZZZ to the word on your sticker.
For example, animal.
- If prompted, type in your name and password.
- If the repository is validated, keep going; otherwise get help.
- Right-click on the project name and Check Out the workspace.
- Return to the Java perspective.
- You will take turns using the keyboard but your
work will be done in one workspace.
- You should see a
percent package (where we will do our work) and
a lecture package with the code from lecture.
- Open the Controller class in
your percent package
- Run Controller as an application. You should see
a frame pop up with the label in it.
- Add some more JLabel instances just to get used to doing
this kind of thing. Run the application and make sure you see what you expect.
In class, you were shown an OpinionModel that managed an integer
in the range of 0 to 10. Take a look at that class in your studio's
a similar Java class PercentModel that works like
OpinionModel but allows integers from 0 to 100.
value represents a percentage, whose
initial value should be 100 percent.
You will have to use eclipse to create thie PercentModel
as a new Java class in the
- The class you define should extend
DefaultBoundedRangeModel, just as OpinionModel does.
- If you mouse-over the super constructor call in OpinionModel,
the Java API should tell you what the parameters mean.
Your PercentModel class must have the following method:
public int computePercentOf(int n)
The method takes in n and returns this.getValue() percent of n.
In your group, discuss how to write computePercentOf so that
it performs arithmetic using the appropriate types.
- Run the JUnit PercentTest to make sure things are working.
- You were shown in class how to extend JSlider (we called the
extension ViewAsSlider) and hook
an instance of the extension to a model. Do the same
for yourself in your Controller,
and configure it so it looks and works
the way you wish.
Instantiate a couple of sliders hooked to the same model and watch them
work in concert.
Show this to a TA and to other groups as needed.
- You were shown the ViewAsText text field associated with a
model in class.
Do the same for yourself and arrange for the slider
and the text field to show up in your demo. When one changes, so should
Show this to a TA and to other students as needed.
- Add a String parameter to the Controller constructor
and arrange for it to show up as the label in the Swing JPanel
instead of the Controller label.
- Next, investigate some other Swing component that will
have some effect on your Controller. You can use any one you want,
but it should be used for some reasonable purpose. For example, a
JButton might be used to reset the percentage to 0 or 100 percent.
- Let's take JButton as an example. You will want to add
one or two JButtons to the Controller JPanel.
To discover when one has been pushed, start with the following code and
let eclipse help you fill in what's missing:
JButton reset = new JButton("reset");
It's the last line above that will cause eclipse to suggest some
things to you. Get help as you need it.
There is a description of JButton
here, but you only need the bold stuff. You can see how the action events
are handled there at least.
- Add at least two things to the panel (they can both be JButtons)
and make them do something useful. Show the TAs this when you check out.
- Fill out the feedback.txt file and be sure to commit your
- Remember the group name you had for today so you can
use this for a simple lab exercise Thursday.
Submitting your work (read carefully)
- Complete the feedback.txt file and be sure to list
your group members' names and ID last-3-digits.
- Answer the other questions in the feedback.txt file.
- You must commit all of your work to your repository. It's best to do this
from the top-most level of your repository, which bears your studio name.
- You must have the TA clear you by signing your studio group sheet.
Be sure your names and IDs are written
clearly on the TA's demo sheet.
Last modified 08:59:25 CDT 03 June 2010
by Ron K. Cytron