Posted By:
20 Feb, 2014 11:40 am PST

How to create a back button using Java

Write a program to create Frame2 with Back button, such that when the user clicks Back button, Frame2 is closed.

//This is frame2

import java.awt.*;

import java.awt.event.*;

class Mybuttons extends Frame implements ActionListener{

//create a button

       Button b;

       Mybuttons()

       {

              //setlayout to flowlayout

              setLayout(new FlowLayout());

              //create the button

              b=new Button("Back");

              //add it to frame

              add(b);

              //add actionlistener to button

              b.addActionListener(this);

                     }

       public void actionPerformed(ActionEvent ae)

       {

              //REMOVE THIS FRAME FROM MEMORY

              this.dispose();

       }

       public static void main(String args[])

       {

              Mybuttons b=new Mybuttons();

              b.setTitle("Graphics");

              b.setSize(400,400);

              b.setVisible(true);

       }

       }

OUTPUT:  

 

Attachment: workspace.zip


Video is posted for better understanding of the object.

Was it useful?  




Please login to reply to this problem.



Related Problems on Fixoncloud