How to use Java Swing to create a button

PHOTO EMBED

Wed Jan 01 2020 19:00:00 GMT+0000 (Coordinated Universal Time)

Saved by @price_the_ice #java #howto #interviewquestions #mobile

import javax.swing.*;  
public class FirstSwingExample {  
public static void main(String[] args) {  
JFrame f=new JFrame();//creating instance of JFrame  
          
JButton b=new JButton("click");//creating instance of JButton  
b.setBounds(130,100,100, 40);//x axis, y axis, width, height  
          
f.add(b);//adding button in JFrame  
          
f.setSize(400,500);//400 width and 500 height  
f.setLayout(null);//using no layout managers  
f.setVisible(true);//making the frame visible  
}  
}  
content_copyCOPY

The button is created by adding it on the JFrame object inside the main() method.

https://www.javatpoint.com/java-swing