Home Java Example Java Awt How to Create Button on Frame
Questions:Ask|Latest


 
 

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:

Advertisement

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

Ask Questions?    Discuss: How to Create Button on Frame   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
kroch heourng
August 12, 2011
student at setec university

java learning
kroch heourng
August 12, 2011
student at setec university

Create Bottun
sushma
February 2, 2013
how to create button on frame

how to create a button
yatin juneja
November 14, 2011
button

gud example to understand..........
iLoveJaVa
December 15, 2011
nice topic

nice explanation. i'm very new about java.u made me clear "thank you"
Subhamoy Guha
December 17, 2011
Create a Button in Specific Location

I like to know How I can draw a button in a desired location. Button simple or radio buttons.
Dipesh
January 6, 2012
java

help for java project .
Anant
January 27, 2012
How to write code about button in java.

Dear Sir/Mam, I want to perform a action on a new Button , So Which API is use for That ? Thanks, Anant B.
Zero Kazami
March 21, 2012
awesome

Thanks bro. because of this code i just passed my AP computer science course.
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