when i run Frame program, it display output in supparate
window.i try to close using "X" it not close.min'-' &
max'+' are working.pls what is problem? i run in editplus.
folowing program i given.
import java.awt.*;
class Form1
{

Frame f1=new Frame("loginpage");
Label l1=new Label("username");
Label l2=new Label("password");
TextField tf1=new TextField();
TextField tf2=new TextField();
Button b1=new Button("submit");
Form1()
{
f1.setLayout(new FlowLayout());
f1.add(l1);
f1.add(tf1);
f1.add(l2);
f1.add(tf2);
f1.add(b1);
f1.setSize(437,440);
f1.setVisible(true);


//f1.dispose();
}
public static void main(String[] args)
{
Form1 f=new Form1();
}
}

Answer Posted / raj

By default the close button of the frame is not in working
state.The close button of the frame has to be set for the
desired operation (i.e. closing the frame).
Set the close button functionality to close the frame or
window. This is done using the addWindowListener() method
of the Frame class which passes the new instance of the
WindowAdapter class that uses the windowClosing() method
for receiving the WindowEvent and close the frame or window.
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the function of lightweight components used in swing?

554


What is frame in java swing?

538


Is there any heavyweight component in swings?

513


What is the difference between swing and applet?

544


What are the different components that are used to show a container?

539






What is swing control in java?

544


What is swing in java javatpoint?

534


Why are swing components called lightweight?

542


What is swing in java with example?

506


Which swing methods are thread-safe?

640


What are the benefits if Swing over AWT?

593


How to create image slideshow in java swing?

609


When we should go for codebase in applet?

617


Where is java swing used?

580


Why do we use swing in java?

510