⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 windowevent1.java

📁 学习java编程的好程序
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
///创建一个窗口事件类
///在这个窗口事件类中,除了单击关闭按钮后方法被实现,其他的都是以空方法被实现
///单击关闭按钮后,会出现一个确认的对话框
public class windowevent1 extends Frame 
{
    public windowevent1()
    {
        WindowListener wh=new windowhandler();
        addWindowListener(wh);
    }
    public static void main(String[] args)
    {
        windowevent1 me=new windowevent1();
        me.setSize(400,300);
        me.setVisible(true);
    }
class windowhandler implements WindowListener 
{
    public void windowActivated(WindowEvent e)
    {}
    public void windowClosed(WindowEvent e)
    {}
    public void windowClosing(WindowEvent e)
    {
	       Button b1=new Button("确定");
         Button b2=new Button("取消");
         Label l=new Label("你能确定关闭系统了吗?");
         Dialog d=new Dialog((Frame)e.getSource(),"系统出错了!",true);
         d.setSize(200,100);
         d.setLocation(0,0);
         Panel p=new Panel();
         p.setLayout(new GridLayout(1,2));
         d.add(p,"South");
         d.add(l,"Center");
         p.add(b1);
         p.add(b2);  
         d.setVisible(true);
         b1.setVisible(true);
         b2.setVisible(true);
         l.setVisible(true);
    }
    public void windowDeactivated(WindowEvent e){}
    public void windowIconified(WindowEvent e){}
    public void windowDeiconified(WindowEvent e){}
    public void windowOpened(WindowEvent e){}
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -