ComponentEvent
ComponentEvent is an event that occurs when a component (such as a JFrame, JPanel, JButton, etc.) is moved, resized, shown, or hidden.
Example:
Source Code:
import java.awt.Color;
import java.awt.Dimension;
private void colorPanelComponentResized(java.awt.event.ComponentEvent evt) {
Dimension size = colorPanel.getSize();
int width = size.width;
if (width < 200) {
colorPanel.setBackground(Color.PINK);
} else if (width < 300) {
colorPanel.setBackground(Color.ORANGE);
} else {
colorPanel.setBackground(Color.GREEN);
}
}
Result:
Watch the video:
Ebook: https://softkhpc.blogspot.com/2025/05/java-programming-ebooks.html

