Colours – Java Basics #33

setPaint method from Graphics2D class sets the colour of drawn figures and strings:

Geometric figures can be painted with fill method (instead of draw).

colored block gui

To define colours you can use java.awt.Color class. There are 13 constants stand for colours:

You can create your own colors as well:

You can also set the background of your component:

Imagy by Julian Burgess –