Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Example Java Awt How to Create Button on Frame

Related Tutorials


 
 

Share on Google+Share on Google+

How to Create Button on Frame

Advertisement
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.add(button)
  frame.setLayout(new FlowLayout());
  frame.setSize(200,100);
  frame.setVisible(true);
  frame.addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent e){
  System.exit(0);
  }
  });
  }
}

Output this program:

  

Download this Example:

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 17, 2007

Related Tutorials

Discuss: How to Create Button on Frame   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:18
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
ihtisham
May 12, 2012
compilation

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

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) "
Hailu
September 28, 2012
WZrKMkiFlgcCfZliKX

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

Thank you.
anusha
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
http://www.npeducations.com

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
DMCA.com