By Tony Bevis on Wednesday, 25 October 2023
Category: Java

Java programming course: 20.2 Graphics

Graphics

There are facilities to draw graphics by overriding the paint() method of the component classes. Create a new class in virtualzoo.ui called PenguinPicture:


To see how the above looks you can put it inside a new tab in AdministratorFrame:

Which should look as follows:

It is possible to create much better graphics than the rather unconvincing penguin generated above.

Suppose you have a graphics file (such as a JPG) that you want to show in a panel. Create a class PenguinImage as follows:

The technique is similar to how you displayed a toolbar icon, although the drawImage() method of Graphics requires an object of type Image.

Next lesson: 20.3 JavaBeans

Related Posts

Leave Comments