| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2078 人关注过本帖
标题:最后一个方法public void windowClosing(WindowEvent e){}起什么作用?
只看楼主 加入收藏
琢石成器
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:36
专家分:160
注 册:2013-11-10
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:2 
最后一个方法public void windowClosing(WindowEvent e){}起什么作用?
import java.awt.*;
import java.awt.event.*;
import *;

public class WinAdapter extends WindowAdapter implements ActionListener{

    Frame fr;
    Panel p1,p2,p3;
    Label lb1,lb2,lsp1,lsp2;
    TextField tf1,tf2;
    Button bClear,bCopy,bClose;
   
    public void go(){
        
        fr=new Frame("MyFrame");
        fr.setSize(350, 250);
        fr.setLayout(new GridLayout(6,1,0,8));
        p1=new Panel();
        p2=new Panel();
        p3=new Panel();
        lb1=new Label("Source");
        lb2=new Label("Target");
        lsp1=new Label();
        lsp2=new Label();
        tf1=new TextField(15);
        tf2=new TextField(15);
        bClear=new Button("Clear");
        bCopy=new Button("Copy");
        bClose=new Button("Close");
        bClear.addActionListener(this);
        bCopy.addActionListener(this);
        bClose.addActionListener(this);
        
        p1.add(lb1);
        p1.add(tf1);
        p2.add(lb2);
        p2.add(tf2);
        p3.setLayout(new FlowLayout(FlowLayout.CENTER,40,0));
        p3.add(bClear);
        p3.add(bCopy);
        p3.add(bClose);
        fr.add(lsp1);
        fr.add(p1);
        fr.add(p2);
        fr.add(lsp2);
        fr.add(p3);
        fr.setVisible(true);
        
    }
   
    public void actionPerformed(ActionEvent e){
        
        if(e.getSource()==bClear){
            tf1.setText("");
            tf2.setText("");
        }
        if(e.getSource()==bCopy){
            tf2.setText(tf1.getText());
        }
        if(e.getSource()==bClose){
            System.exit(0);
        }
    }
   
   
   
    public static void main(String[] args){
        
        WinAdapter wa=new WinAdapter();
        wa.go();
        
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Press enter key to exit");
        try{
            bf.readLine();
        }catch(IOException e){
            System.out.print("IOException");
        }finally{
            System.exit(0);
        }
    }
   
    public void windowClosing(WindowEvent e){
        System.exit(0);
    }

}
搜索更多相关主题的帖子: import public 
2013-11-11 12:38
丶弱水彡千
Rank: 5Rank: 5
来 自:地狱十九层
等 级:职业侠客
威 望:2
帖 子:203
专家分:369
注 册:2013-6-16
收藏
得分:4 
没看整个程序  最后一个方法 应该是个关闭窗口的

这个怎么玩
2013-11-12 15:35
ghjsmzy
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:187
专家分:573
注 册:2009-6-17
收藏
得分:6 
它是从WindowAdapter父类继承的方法,当一个窗口正被关闭时执行的方法。
API解释:Invoked when a window is in the process of being closed.
2013-11-12 18:49
快速回复:最后一个方法public void windowClosing(WindowEvent e){}起什么作用 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011907 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved