And for completenessā sake, also a Python Mode (Jython) for Processing 3: ![]()
"""
* Processing Python Mode Swing Demo (v1.0.2)
* GoToLoop (2024/Jun/03)
*
* https://Discourse.Processing.org/t/
* swing-components-in-default-processing-window-py5/10
"""
from java.awt.Color import GREEN
from javax.swing import JSlider, JLabel, JButton, JColorChooser
DIAM = 'Diameter: %d'
c = GREEN
def setup():
size(600, 660)
noLoop()
fill(c.RGB)
global cx, cy, slider, label
w, h = width, height
cx, cy = w >> 1, h >> 1
slider = JSlider(0, w - 60, cx, bounds = (180, 20, 200, 24))
slider.addChangeListener(slideChange)
slider.toolTipText = 'circle diameter'
label = JLabel(DIAM % cx, bounds = (75, 20, 80, 24))
btn = JButton('Color', bounds = (400, 20, 80, 24))
btn.addActionListener(btnAction)
window = this.surface
window.title = 'Processing Python Mode Swing Demo'
canvas = window.native
canvas.bounds = 0, 60, w, h - 60
frame = canvas.frame
frame.add(slider); frame.add(label); frame.add(btn)
slider.repaint(); label.repaint(); btn.repaint()
def draw(): background(0320); circle(cx, cy, slider.value)
def mouseWheel(e): slider.value -= e.count * 10
def slideChange(_): label.text = DIAM % slider.value; redraw()
def btnAction(_, TITLE = 'Choose color:'):
global c
c = JColorChooser.showDialog(None, TITLE, c) or c
fill(c.RGB); redraw()