Slide 1
Slide 2
Slide 3

Button in java programming (V76)

No Comments

 

JButton

JButton is a control component that has a label and generates an event when it is clicked. The Button class is used to create labeled buttons that are platform-independent.

Example:

Source Code:

Copied! 
    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

back to top