The JButton class which extends AbstractButton class that is used to create a button. JButton supports ActionEvent, that means when a button is clicked, an ActionEvent is generated.
JButton class having three commonly used Constructors, such as:
Let's see an example for displaying an image on the button.
import javax.swing.*; import java.awt.event.*; import java.awt.*; public class JButtonDemo extends JFrame { JButtonDemo() { JButton b1 = new JButton("save"); //Creating a save Button. JButton b2 = new JButton("delete"); //Creating a delete Button. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout()); //setting layout using FlowLayout object setSize(300, 300); //setting size of Jframe add(b1); //adding save button to frame. add(b2); //adding delete button to frame. setVisible(true); } public static void main(String[] args) { new JButtonDemo(); } }
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc