How to Create Button on Frame

In this section, you will learn how to create Button on frame the topic of Java AWT package.

How to Create Button on Frame


In this section, you will learn how to create Button on  frame the topic of Java AWT package. In the section, from the generated output of the following program, complete window or frame is created in the ButtonText class that is the main class where the main() method lies. This part of the topic will show a simple command button labeled with the text "Submit" when the program will be executed.

Here, you will learn simply the procedure of creation a command button on the Java Awt Frame. There is a program for the best illustration the topic has been given ahead.

Description of Program

The following program has used simply the Button class for creating a command button on the frame object.

FlowLayout(): This is the constructor of FlowLayout class. This class is used for arranging the component from left to right. Here this is used for creating the object of the class to set the layout by passing the created object from the setLayout() method of the Frame class.

Here is the code of  this program:

import java.awt.*; 
import java.awt.event.*;

public class ButtonText 
  public static void main(String[] args) {
  Frame frame=new Frame("Button Frame");
  Button button = new Button("Submit")
  frame.setLayout(new FlowLayout());
  frame.addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent e){

Output this program:


Download this Example:

Share on Google+Share on Google+

How to Create Button on Frame

Posted on: April 17, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: How to Create Button on Frame   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
satyendra kumar
March 29, 2012
java coding

sir, i want to know about applet coding for new button and save button please you help me thank you
May 12, 2012

plz aslo show method of runing the above program through notepad
August 16, 2012

your website is very good i love it if can i helpe u about c++ programming i can do it
Manoj T
September 12, 2012
is that work corrct?

What is the use of Submit button here? and a function "frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0) "
September 28, 2012

Well put, sir, well put. I'll cretaliny make note of that.
March 27, 2013

Thank you.
July 29, 2013
can you send me.....

pls can u send me how to create buttons,label,frames,checkbox,radio buttons coding in java script.
kiranvarma - npeducations
October 1, 2013

Thank for the code! its really helpful. very clean and neat explanation
poonam sandhu
January 13, 2014
internet concept and web design

web page with frame and button