| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 407 人关注过本帖
标题:实现窗口关闭怎么实现不了?
只看楼主 加入收藏
左手拉拉
Rank: 1
等 级:新手上路
帖 子:40
专家分:2
注 册:2012-3-3
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:2 
实现窗口关闭怎么实现不了?
package zdkj.wzq.java11;

import java.awt.Button;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

public class WindowApp1 extends JFrame
   implements WindowListener{

    Button close=new Button("退出程序");
    public WindowApp1(){
        
        
     
        super("窗体事件");
        this.add(close);
        //方法二:对窗口实现监听
        this.addWindowListener(this);
        
        Container c=this.getContentPane();
        this.setLayout(new FlowLayout());
        c.add(close);
        this.setSize(200,250);
        c.setBackground(Color.green);
        
   
        this.setVisible(true);
   
        
        
        
    }
   
   

        
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new WindowApp1();
        
        

    }




    @Override
    public void windowOpened(WindowEvent e) {
        // TODO Auto-generated method stub
        
    }




    @Override
    public void windowClosing(WindowEvent e) {
        // TODO Auto-generated method stub
        

        System.exit(0);
   
    }




    @Override
    public void windowClosed(WindowEvent e) {
        // TODO Auto-generated method stub
        
    }




    @Override
    public void windowIconified(WindowEvent e) {
        // TODO Auto-generated method stub
        
    }




    @Override
    public void windowDeiconified(WindowEvent e) {
        // TODO Auto-generated method stub
        
    }




    @Override
    public void windowActivated(WindowEvent e) {
        // TODO Auto-generated method stub
        
    }




    @Override
    public void windowDeactivated(WindowEvent e) {
        // TODO Auto-generated method stub
        
    }

   
 
   
        
   
   

   

}
搜索更多相关主题的帖子: super package public import close 
2012-05-21 19:01
Abiosis
Rank: 2
等 级:论坛游民
帖 子:13
专家分:33
注 册:2012-1-12
收藏
得分:10 
程序代码:
package org.testproject;

import java.awt.Button;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

public class window extends JFrame implements WindowListener {

    Button close = new Button("退出程序");

    public window() {

        super("窗体事件");
        this.add(close);
        // 方法二:对窗口实现监听
        this.addWindowListener(this);

        Container c = this.getContentPane();
        this.setLayout(new FlowLayout());
        c.add(close);
        this.setSize(200, 250);
        c.setBackground(Color.green);

        this.setVisible(true);
       
        close.addMouseListener(new MouseAdapter(){
            public void mouseClicked(MouseEvent e) {
                System.exit(0);
            }
        });
       
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new window();

    }

    @Override
    public void windowActivated(WindowEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void windowClosed(WindowEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void windowClosing(WindowEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void windowDeactivated(WindowEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void windowDeiconified(WindowEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void windowIconified(WindowEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void windowOpened(WindowEvent e) {
        // TODO Auto-generated method stub

    }

}
帮你重新写了下
2012-05-22 10:00
ab1034982749
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:215
专家分:1185
注 册:2012-4-14
收藏
得分:10 
应该写成这样:
import java.awt.Button;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

public class WindowApp1 extends JFrame implements ActionListener
{
    Button close=new Button("退出程序");
    public WindowApp1(){
        
        super("窗体事件");
        close.addActionListener(this);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container c=getContentPane();
        setLayout(new FlowLayout());
        c.add(close);
        setSize(200,250);
        c.setBackground(Color.green);
        setVisible(true);
    }
   
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new WindowApp1();
        
        

    }
    public void actionPerformed(ActionEvent e)
    {
        System.exit(0);
        
    }

}

2012-05-22 23:12
快速回复:实现窗口关闭怎么实现不了?
数据加载中...
 
   



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

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