Victoria University of Wellington
School of Mathematics, Statistics and Computer ScienceSWEN221: Software DevelopmentLab HandoutThe purpose of this Lab is to give you hands on practice using Java reflection. Before the end of thelab, you should submit your solutions via the online submission system which will automatically markit. You may submit as many times as you like in order to improve your mark and the final deadlinewill be Friday @ 23:59. Please be aware that it is a mandatory requirement to submit 8/10labs in SWEN221.1 A Widget SystemThe program provided with this lab implements a very primitive widget system which is inspired bymodern windowing systems. In this system widgets occupy areas on the screen and can respond tomouse clicks. Widgets have internal state which they can use to control how they look. The followingillustrates a simple widget system:Here we see a very simple widget systems constructed from five widgets. The four visible squares eachconstitute one widget, whilst the background itself constitutes another widget. The two widgets onthe top row are toggles — when clicked on, they will change to either the on or off state. The twowidgets on the bottom row are counters — when clicked on, they will increment an internal counterand set their counter according to this.12 What to doThe key challenge in this lab lies in interacting with widgets through reflection. In particular, youwill be unable to see the source code for one of the widgets. This means that reflection provides theonly way in which you can interact with this widget. The Inspector provides the skeleton for a suiteof methods for creating widgets and reading/writing their attributes. Some notes:• Inspector.newWidget(String name, Rectangle dimensions). This instantiates a new in-stance of the class given by name. To do this, you will need to first find the appropriate construc-tor in the widget’s class, and then instantiate a new object using Constructor.newInstance().• Inspector.getAttribute(Widget widget, String name). This reads the value of field namein the given widget. To do this, it must call the corresponding “getter” method. For example,for a field called color the corresponding getter would be getColor().• Inspector.setAttribute(Widget widget, String name, Object value). This writes a givenvalue into field name in the given widget. To do this, it must call the corresponding “setter”method. For example, for a field named color of type Color the corresponding setter would besetColor(Color).Your goal in this lab is to complete the above methods in the Inspector class.SubmissionYour lab solution should be submitted electronically via the online submission system, linked fromthe course homepage. The required files are:swen221/lab8/core/Canvas.javaswen221/lab8/core/Inspector.javaswen221/lab8/core/Widget.javaswen221/lab8/Main.javaswen221/lab8/tests/WidgetTests.javaswen221/lab8/util/AbstractWidget.javaswen221/lab8/util/Point.javaswen221/lab8/util/Rectangle.javaswen221/lab8/views/WidgetViewer.javaswen221/lab8/widgets/Background.javaswen221/lab8/widgets/Counter.javaswen221/lab8/widgets/Toggle.javaYou must ensure your submission meets the following requirements (which are needed for theautomatic marking script):1. Your submission is packaged into a jar file, including the source code. Note, the jarfile does not need to be executable. See the following Eclipse tutorials for more on this:http://ecs.victoria.ac.nz/Support/TechNoteEclipseTutorials2. The names of all classes, methods and packages remain unchanged. That is, youmay add new classes and/or new methods and you may modify the body of existing methods.However, you may not change the name of any existing class, method or package. This is toensure the automatic marking script can test your code.23. All JUnit test files supplied for the assignment remain unchanged. Specifically, youcannot alter the way in which your code is tested as the marking script relies on this. This doesnot prohibit you from adding new tests, as you can still create additional JUnit test files. Thisis to ensure the automatic marking script can test your code.4. You have removed any debugging code that produces output, or otherwise affectsthe computation. This ensures the output seen by the automatic marking script does notinclude spurious information.Note: Failure to meet these requirements could result in your submission being reject by the submis-sion system and/or zero marks being awarded.3