Exercise 2: An Image Display

Now that you know everything about Java, you should be able to transform my ideas into classes and implementation of these classes (two different steps).

For that second exercise, I will still give you some directions by suggesting organisation and interface of the classes, but you do not need to follow strictly that organisation as long as you get the good result.

Main Idea

I would like to get a program that will open an window and show a jpeg, PNG or GIF picture in the middle of the frame.

The area of the frame should be four times the area of the picture as long as it remains equal to or less than half the area of your screen display. The dimension of the frame should be kept homothetic(*) to the one of the picture.

If the picture is to big regarding these restrictions, it should be uniformly scaled down in order to fit in that restrictions.

What restriction of that sort should be added here to be sure that nothing bad could happen running the program ?

Of course, the image will be initially drawn in the middle of the frame.

More about the interface

You could have a object ShowImage, with three constructors :

Tips

Image.getImage

AffineTransform.scale

Graphics2D g2 = (Graphics2D) g;

Graphics2D.drawImage

JFileChooser

BufferedImage

some more tips online...

Next Step

Eventually, the aim of the program will be to be able to move the image into the JPanel by a click and move of the mouse.

Various

As well as showing...

There should be a text output of the screen, frame and image dimensions, area and Width/Height ratios.

Exercise 2 second part

Write a little program that will get an integer as an argument and that will use recursion to compute factorial value of that integer. Try to find a graphical way to explain recursivity

Example, display :

Input  : 4
Output :
4!	= 4 x 3!
	= 4 x 3 x 2!
	= 4 x 3 x 2 x 1! recursion stop here because detection of the trivial case 1!
	= 4 x 3 x 2
	= 4 x 6
	= 24

(*) Uniform Scaling possible from one to the other : go from one the other trough a homothetie transformation. A homothetic map preserves within a global scaling factor relative distances and angles.