In Studio 1, you developed a slider that
can control a model that represents percentages, from 0 to 100%. In this
lab, you attach three such sliders to control the percent of an image's
red, green, and blue components that are copied from one panel to another.
You should try to use firefox, so that the .java
open in their own window, instead of launching visual studios.
- Work in pairs if you like, but upload your solution to each person's
CMS account (see below).
- Try signing into the CMS (Course Management System). You'll use
this system to submit your work when you are done. But try opening
the page now, so we can see if it works.
- Open this page.
- Log in using your CEC firstname.lastname@example.org (for
example, I use email@example.com) and
- Look at the CSE132 materials posted there (all you should see is
the Lab 1 assignment).
- Open eclipse and go to the CSE132 project you started
in Studio 1. You should see a percent
package already there.
- You will need to import yops and some pictures:
- Download the yops zip file to your desktop.
- In eclipse, right click CSE132 and import the zip file
as a general archive file.
- Put RGB.java into your
The easiest way to do this is to save the
file (right-click and save the link) to your desktop; right-click on the
file icon and copy it, and then paste it into the
- You should already have the following classes in the percent
package. If you don't, get them from another student or the instructor.
- Controller and the supporting
classes it needs for the slider and text field.
- PercentModel should also be there.
- This RGB code won't compile until you initialize the green and
blue instance variables. Each needs to be an instance
of Controller, and each should be added to the
RGB (as was done with red).
- If necessary, add the accessor
public PercentModel getModel() to your Controller class so
that you can get its PercentModel, as needed by RGB.
- Modify your Controller so it has just the components you
want (only one slider is necessary per Controller).
- Run the RGB as a Java application, and use the sliders to
change the colors. You can move the sliders as you wish, and when you want
to see the resulting picture, click the "go" button.
Pick one of the following
(Do two of them in your lab session by the time you demo to earn 10 extra lab credit points and the admiration of your TAs)
In whatever you pick, keep in mind that it is the model you should
be affecting and examining.
Do not change the sliders or text field from your program; let them
react on their own to changes you make to the model.
- React when the sliders move: do not wait for the "go" button to
Hint: You can see how an ActionListener is added to the "go"
button. This uses an
anonymous inner class, which I'll explain in more detail
in upcoming lectures.
Try the same kind of thing with the model of
each Controller, but use the ChangeListener instead.
It reacts when the model's value is changed.
Eclipse is pretty good about suggesting what you'll need to implement
the ChangeListener interface. Click on the yellow light bulbs
to get that kind of help
Get some help from TAs or other students if you need it.
- Add a "lock" button that causes the value set by moving one slider
to be set in the other sliders' models as well.
Try this one slider at a time
to be sure you have the right idea. Address your method calls to
the underlying model and not the slider directly.
For example, if the red model value changes, then set the same value in
the green and blue models. You'll need the ChangeListener
methodology described above.
If possible, make your lock button toggle between locked mode and
- The sliders currently cause the color to be reduced, from 100% to 0%.
100% is the color's actual value. At 0%, the color intensity value is 0.
Devise a way for a color to be increased instead of decreased, from its
actual value to a maximum of 255.
Demo your lab
Grab a grade sheet, fill it out, and show what you did to a TA.
Get him or her to sign the sheet.
Submit your project
- Generate a zip file to submit your work by exporting your percent package as a zip file.
- From your CMS page, figure out how to upload the zip file and submit your
work. I (RKC) have no idea how to do this, nor am I even sure that it is
possible. I can't see the view you see. Let's see if we can get this to
Last modified 20:10:42 CST 11 January 2010
by Ron K. Cytron