Friday, 1 January 2016

How to display a JFrame with button

To display a JFrame with JButton you must use following code.

Code:

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.*;

public class myButton
{

  public static void main(String[] args)
  {
    JFrame f1 = new JFrame("Welcome");
    JButton b1 = new JButton("OK");

    f1.add(b1);
    f1.setVisible(true);
    f1.setSize(200,200);
    f1.setLayout(new FlowLayout(FlowLayout.LEFT));

   }
}

output


No comments:

Post a Comment