import java.awt.Color;
private void btncolorActionPerformed(java.awt.event.ActionEvent evt) {
// Generate random color
int r = (int)(Math.random() * 256);
int g = (int)(Math.random() * 256);
int b = (int)(Math.random() * 256);
Color randomColor = new Color(r, g, b);
// Change background color of the JFrame content pane
this.getContentPane().setBackground(randomColor);
}
Result:
Watch the video:
Ebook: https://softkhpc.blogspot.com/2025/05/java-programming-ebooks.html

