Pages

Put JButton into JFrame

Source code below will show you, how to add a JButton into JFrame. In java, we will use JButton to create button.

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


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

public class AddJButtonIntoJFrame
{
public static void main(String[]args)
{
//Create a JButton with text CLICK ME
JButton button=new JButton("CLICK ME");

//Create a JFrame that will be a window
//It's title is, Put JButton into JFrame
JFrame frame=new JFrame("Put JButton into JFrame");

//Add JButton into JFrame
frame.add(button);

//Set close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size with :
//Width : 400 pixels
//Height : 100 pixels
frame.setSize(400,100);

//Make JFrame visible. So we can see it.
frame.setVisible(true);
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************
Related Posts Plugin for WordPress, Blogger...