JAVA之GUI编程ACTION事件

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事件

上一篇:iOS开发UI篇—UITabBarController生命周期(使用storyoard搭建)


下一篇:iOS开发网络篇—网络编程基础