The purpose of this Lab is to give you hands on practice using Java reflection.
1 A Widget System
The program provided with this lab implements a very primitive widget system which is inspired by modern windowing systems. In this system widgets occupy areas on the screen and can respond to mouse clicks. Widgets have internal state which they can use to control how they look. The following illustrates a simple widget system:
Here we see a very simple widget systems constructed from five widgets. The four visible squares each constitute one widget, whilst the background itself constitutes another widget. The two widgets on the top row are toggles when clicked on, they will change to either the on or o state. The two widgets on the bottom row are counters when clicked on, they will increment an internal counter and set their counter according to this.
2 What to do
The key challenge in this lab lies in interacting with widgets through reflection. In particular, you will be unable to see the source code for one of the widgets. This means that reflection provides the only way in which you can interact with this widget. The Inspector provides the skeleton for a suite of methods for creating widgets and reading/writing their attributes. Some notes:
- newWidget(String name, Rectangle dimensions). This instantiates a new instance of the class given by name. To do this, you will need to first find the appropriate constructor in the widgets class, and then instantiate a new object using Constructor.newInstance().
- getAttribute(Widget widget, String name). This reads the value of field name in 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().
- setAttribute(Widget widget, String name, Object value). This writes a given value 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 be setColor(Color).
Your goal in this lab is to complete the above methods in the Inspector class.

![[Solved] SWEN221 Lab 7- Java reflection](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] SWEN221 Assignment 4- The Card Game](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.