The graphic components used in this
part are a JFrame containing a JComponent.
Here are the steps to follow :
- Create a class GraphFrame extending JFrame and a class
GraphComponent extending JComponent. A GraphFrame will
contain a GraphComponent. Instances of GraphComponent will
have a default size of 500x500.
- Make instances of GraphComponent also instances of
MouseInputListener. Trace on the standard output the
listening of the mouse events on a GraphComponent.
- Draw in the GraphComponent a plain circle with radius 5
and modify the management of the events in such a way that,
each time you click inside the circle, the word "win" is
written on the standard output.
- Modify the management of the events in such a way that, if
the circle does not yet exist, it is created when you
pressed the button of the mouse, and moved if you drag
before releasing the button.
- Manage the existence of more than one circle.
Part 2
- Write a new version of GraphComponent using the API
Java2D. You will use instances of Ellipse2D
for the circles.
- Add scrollbars to the GraphComponent.
- Add a menu allowing to open and close new windows, and
quit the program. Use a dialog to confirm before quit.
- Add a toolbar on the left side. Put in the toolbar buttons
allowing to create different shapes : circle, square ... Use
a GridLayout
to organize buttons in the toolbar.
Part 3
- The design pattern "Prototype" consists to instantiate new
objects by cloning a yet existing one. Use this model to add
easily new shapes like "small square", "big circle" ... in
the tool bar.
- Modify the management of the events in such a way that, if
the key "alt" is down when you press the mouse button, an
edge (line segment) is added between the two shapes. If
there is no shape at the point where you release the button,
a new shape will be added.
- Modify the management of the events in such a way that, if
you push the space bar during the creation of an edge, it
will add a joint point. Joint points will be showed as small
red circles that you may move.
Part 4
- Use the right button to delete elements: shapes, edges,
joint point.
- Label the vertices (shapes) with numbers.
- Add labels and arrows to edges.