Demo.awt.Colors.py Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jython-standalone Show documentation
Show all versions of jython-standalone Show documentation
Jython is an implementation of the high-level, dynamic, object-oriented
language Python written in 100% Pure Java, and seamlessly integrated with
the Java platform. It thus allows you to run Python on any Java platform.
"""\
Create a panel showing all of the colors defined in the pawt.colors module
Display the names of bright colors in black and of dark colors in white
"""
from java import awt
from pawt import colors, test
from math import sqrt
p = awt.Panel()
for name in dir(colors):
color = getattr(colors, name)
if isinstance(color, awt.Color):
l = awt.Label(name, awt.Label.CENTER, background=color)
intensity = sqrt(color.red**2 + color.green**2 + color.blue**2)/3
if intensity < 90:
l.foreground = colors.white
p.add(l)
test(p, size=(700, 500))