当窗体关闭时退出程序的示例,窗体退出示例,package cn.o
分享于 点击 26120 次 点评:213
当窗体关闭时退出程序的示例,窗体退出示例,package cn.o
package cn.outofmemory.snippets.desktop;import java.awt.Frame;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;public class FrameCloseEventListener { public static void main(String[] args) { // Create the frame Frame frame = new Frame(); // Add a listener for the close event frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { // Exit the application System.exit(0); } }); // Display the frame int frameWidth = 300; int frameHeight = 300; frame.setSize(frameWidth, frameHeight); frame.setVisible(true); }}
用户点评