This is simple code to create a button. There is one thing that I don't understand: why are we using SwingUtilities.InvokeLater(new Runnable())
.
Please make the answer as simple as possible so that I can grasp it easily.
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilies;
public class button {
public static void main(String args[]) {
SwingUtilies.InvokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame();
JButton button = new JButton("ok");
frame.add(button);
frame.setDefault.CloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.Pack();
frame.setVisible(true);
}
});
}
}