A JButton in Java is a component from the Swing library used to create clickable buttons in a graphical user interface (GUI). It is part of the javax.swing package and provides a simple way to allow users to trigger an action when the button is clicked.
JButton can display text, an icon, or both. It supports adding an ActionListener to define the behavior that should occur when the button is clicked. For example:
java
JButton button = new JButton(“Click Me”);
button.addActionListener(e -> System.out.println(“Button clicked!”));
JButton also supports customization, such as setting colors, fonts, and sizes, making it versatile for building interactive Java applications.