Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to add Window Listener

843807Feb 1 2006 — edited Feb 2 2006
Basically, I have created a simple window. I am having trouble adding a window listener so that when the user clicks the x to exit the program, it exits. Here is the code I have.
package javagraphics;

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

public class DispGraphics
{
    public static void main(String args[])
    {
        Frame myFrame = new Frame("My Window");
        myFrame.setLayout(new BorderLayout());
        
        Label myLabel = new Label("Hello World!");
        myFrame.add(myLabel, BorderLayout.CENTER);
        
        myFrame.setSize(200, 200);
        
        myFrame.show();       
        
    }
    
}
What do I need to add to it so that I can exit program with x on top right of window? Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 2 2006
Added on Feb 1 2006
7 comments
297 views