For those not interested in the py5 Python version and no regard for backward compatibility, the following is my Processing 4 version of DotView:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
javax.swing.JFrame frame;
java.awt.Canvas canvas;
int diameter = 150;
Color dotColor = Color.GREEN;
int _wndW = 700;
int _wndH = 600;
void colorBtn(int x, int y, int w, int h) {
JButton btn = new JButton("Color");
btn.setBounds(x, y, w, h);
frame.add(btn);
btn.addActionListener( new ActionListener() {
void actionPerformed(ActionEvent actionEvent) {
dotColor = JColorChooser.showDialog(null, "Choose color", Color.GREEN);
}
}
);
}
void sizeSlider(int x, int y, int w, int h) {
// orientation, min, max, value
JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 450, 150);
slider.setBounds(x, y, w, h);
frame.add(slider);
slider.addChangeListener(new ChangeListener() {
void stateChanged(ChangeEvent changeEvent) {
diameter = slider.getValue();
}
}
);
}
void buildWnd() {
sizeSlider(180, 20, 200, 24);
colorBtn(390, 20, 80, 24);
frame.setVisible(true);
}
void setup() {
size(_wndW, _wndH); // Makes it possible to use draw();
frame = (javax.swing.JFrame) ((processing.awt.PSurfaceAWT.SmoothCanvas) surface.getNative()).getFrame();
canvas = (processing.awt.PSurfaceAWT.SmoothCanvas) ((processing.awt.PSurfaceAWT)surface).getNative();
frame.setBounds(900, 300, _wndW, _wndH); // Makes it possible to add swing components
frame.setLayout(null);
canvas.setBounds(0, 60, _wndW, _wndH-60); // For use with draw()
javax.swing.SwingUtilities.invokeLater(()-> {
buildWnd(); // Builds components on EventDispatchThread
}
);
}
void draw() {
background(209);
fill(dotColor.getRed(),dotColor.getGreen(),dotColor.getBlue());
stroke(0);
strokeWeight(2.0);
circle(_wndW/2, _wndH/2 - 50, diameter);
}
Addendum:
I note that you did not use a separate EventDispatchThread in your demo. There’s only two components so it might not be an issue. I have no idea what behaviour is seen if it is an issue.