






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Docsity.com
Previously we used JLabels to hold text We can also use JLabel to hold an image:
To do some more advanced drawing, we will have to extend JFrame (to override methods): Then we need to override the paint() method: DrawCircle is just an example name Docsity.com
Java normally updates your GUI automatically Sometimes you need to update manually: repaint - redraw the whole window pack - resize the window revalidate - layout is redone (in case you removed any objects) If your window seems to not be correct (or not updating) try running one/all of theseDocsity.com
We have seen how to detect when you click the mouse, so let's use that to draw! To do this we need to make a MouseListener:
The JColorChooser is a pre-built class that allows you to choose a color (from a GUI) To run the GUI, use showDialog() (returns Color): (See: RainbowMouseDraw.java) associated window title of color GUI initial color selected Docsity.com
You can also use the Graphics class to draw a more customizable String than JLabel To do need to simply call drawString(): Can also change Font with: (See: DrawStringExample.java) starting x pixel starting y pixel point size Docsity.com