LAB 9 - Introduction to Programming (part 4 – working with Media)

Lab Exercises

Topics

n      To create and manipulate media like pictures and sounds

 

Exercises

3.6 Working with Media

3.6.1 Creating a Picture Object

 

Type in the following code in the Interactions window:

> Picture picture1;

> picture1 = new Picture();

> picture1.show();

 

What was displayed?

 

3.6.2 Showing a Picture

3.6.3 Variable Substitution

 

Now type in the following code in the Interactions window:
> String fileName;

> fileName = FileChooser.pickAFile();             // note that this pops up a window to select a jpg file

 

> Picture picture2;

> picture2 = new Picture(fileName);

> picture2.show();

 

What was displayed?

 

Now type:

>  System.out.println(picture2);

 

3.6.4 Object References

3.6.5 Playing a Sound

 

> String fileName2;

> fileName2 = FileChooser.pickAFile();                       // note that this pops up a window to select a wav file

 

> Sound soundClip;

> soundClip = new Sound(fileName2);

> soundClip.play();

 

What was displayed?

 

Now type:

>  System.out.println(soundClip);

 

 

 

QUESTIONS:

Write a program that displays a picture with your name written on it. [HINT: You will need to look up drawstring in the API for the Picture class]

 

Submit the .java file through the DropBox in WebCT.