A button, also known as push button, is an active control that has a 3-dimensional appearance. It triggers an event when it is clicked or activated. Swing also provides an ability to associate an icon, a string, or both with the buttons. A push button is an object of JButton class.
Some of the constructors defined by JButton class are as follows.
string represents the string used for the button
icon represents the icon used for the button
Note: All the buttons are derived .from Abstract Button class
public class JLocationJavaExample extends JFrame implements ActionListener
JButton ClckBtn = new JButton("Click Here");
int x = 0, y = 0;
final int GP = 40;
setTitle("Change Component Location While Clicking Button In Java Swing");
public void actionPerformed(ActionEvent e)
x += GP;
y += GP;
public static void main(String aa)
JLocationJavaExample frm = new JLocationJavaExample();