黑马程序员技术交流社区
标题:
转型问题?
[打印本页]
作者:
騛鹏
时间:
2013-3-30 23:46
标题:
转型问题?
本帖最后由 騛鹏 于 2013-3-31 01:44 编辑
import java.awt.*;
import java.awt.event.*;
class FrameDemo
{
public static void main(String[] args)
{
Frame f = new Frame("it zi xun wang");
//f.add(new Button("an niu"));
f.setSize(500,600);
f.setVisible(true);
f.addWindowListener(new MyWindowListener());
}
}
class MyWindowListener implements WindowListener
{
public void windowClosing(WindowEvent e)
{
e.getWindow().setVisible(true);
try
{
Thread.sleep(3000);
}
catch (Exception ex)
{
ex.printStackTrace();
}
((Window)e.getComponent()).dispose();
System.exit(0);
}
public void windowActivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowOpened(WindowEvent e){}
}
复制代码
((Window)e.getComponent()).dispose();
e.getComponent() 是如何用window转型的? 查API 也没有查明白?
作者:
lucy198921
时间:
2013-3-31 00:24
e.getComponent() instanceof Window
所以才能把e.getComponent()强转为Window
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2