❮ Previous Next ❯

JButton Class

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:

  1. JButton(): creates a button with no text and icon.
  2. JButton(String str): creates a button with the specified text.
  3. JButton(Icon i): creates a button with the specified icon object.
  4. `

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(); } }

Output


JButton

❮ Previous Next ❯



  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved