Pin It

How to add a Button to a Frame using Swing API in Java ?

Program to demonstrate adding of Button to a Frame

package com.hubberspot.awtSwing.example;

import java.awt.FlowLayout;
import javax.swing.*;

public class AddButtonToFrame
{
  JFrame frame;
  JButton button;
 
  AddButtonToFrame()
  {
 frame = new JFrame("Welcome to HubberSpot Frame");
 button = new JButton("Click Me!");
 frame.setSize(200,100);
 frame.setLayout(new FlowLayout());
 frame.add(button);
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 frame.setVisible(true);
  }
  
  public static void main(String[] args)
 {
 new AddButtonToFrame();
 }
}
Output of the program :


Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot