Get JButton text

Source code below will show you how to get text from JButton.

************************************************************************
COMPLETE SOURCE CODE FOR : GetJButtonText.java
************************************************************************


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import java.awt.FlowLayout;

public class GetJButtonText
{
public static void main(String[]args)
{
//Create a button with text ( Click me )
JButton button=new JButton("Click me");

JFrame frame=new JFrame("Get JButton text");
frame.setLayout(new FlowLayout());
frame.add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setVisible(true);

//Method getText() will get text from JButton
JOptionPane.showMessageDialog(frame,"JButton text is : "+button.getText());
}
}


************************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************************

RELAXING NATURE VIDEO