首页 > 其他 > 详细

事件处理程序

时间:2019-05-12 22:36:47      阅读:120      评论:0      收藏:0      [点我收藏+]

完成一个按钮的事件处理程序

package 事件处理程序;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyFrame extends Frame implements ActionListener{
    //初始化窗体基本属性
    public MyFrame() {
        this.setSize(600, 400);
        this.setTitle("我的第一个GUI窗体");
        //创建一个窗口
        String label;
        Button button = new Button("点我一下吧!");
        //给按钮添加单击事件
        button.addActionListener(this);
        //创建一个线性布局
        FlowLayout flowLayout =new FlowLayout();
        //把布局应用到窗体上
        this.setLayout(flowLayout);
        //把按钮添加到窗体上
        this.add(button);
        this.setVisible(true);
    }
    //单击事件处理的方法
    public void actionPerformed(ActionEvent e) {
        System.out.print("就叫我大狼狗吧");
    }
 public static void main(String[] args) {
     new MyFrame();
 }
}

 

事件处理程序

原文:https://www.cnblogs.com/Mxuan0303/p/10853964.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!