jython awt demo

 

jython awt demo :

"""\
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))

截图:

posted on 2014-08-22 16:27  rojas  阅读(185)  评论(0编辑  收藏  举报