码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA之GUI编程ACTION事件

时间:2014-07-18 21:13:56      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:style   java   color   os   io   for   

package GUI;

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class StudyAction {
private Frame f;
private Button but;

StudyAction(){
    init();
}

private void init() {
    f=new Frame("Window ------by Von");
    f.setBounds(300, 100, 600, 500);
    f.setLayout(new FlowLayout());
   
    but=new Button("Click me to close");
    f.add(but);
    dealwithEvent();
    f.setVisible(true);
}

private void dealwithEvent() {
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e){  //区分大小写,WindowClosing则不可
            System.exit(0);
        }
    });
   
    but.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
           
        }
    });
}
public static void main(String[] args) {
    new StudyAction();
}
}

JAVA之GUI编程ACTION事件,布布扣,bubuko.com

JAVA之GUI编程ACTION事件

标签:style   java   color   os   io   for   

原文地址:http://www.cnblogs.com/vonk/p/3850231.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!