zoukankan      html  css  js  c++  java
  • 事件处理程序

    完成一个按钮的事件处理程序,实现功能自拟,例如:改变窗口的背景颜色,改变按钮的位置等等。

    package day35;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    public  class windows implements ActionListener{
        JFrame windows1;
        JButton jb;
        JPanel jp;
        JLabel jl;
        public windows() {
            windows1=new JFrame("窗体");
            jb=new JButton("确定");
            jb.addActionListener(this);
            jp=new JPanel(null);
            jl=new JLabel();
            windows1.setBounds(450,200,800,400);
            jl.setBounds(500,300,80,40);
            jb.setBounds(500,30,80,40);
            jp.add(jb);
            jp.add(jl);
            windows1.add(jp);
            windows1.setVisible(true);
            
        }
        public static void main(String[] args) {
                 new windows();
    
        }
        public void actionPerformed(ActionEvent e) {
            jp.setBackground(Color.yellow);
            jl.setText("您好!");
            jb.setBounds(50,50,80,40);
            
        }
    
    }

  • 相关阅读:
    多态
    封装,继承,多态
    基本类型和引用类型的区别
    第七天 面向对象
    什么是Java线程池
    游戏内核架构
    放松
    静不下来心写代码
    速度和正确率
    理顺思路
  • 原文地址:https://www.cnblogs.com/Lwl2019/p/10834420.html
Copyright © 2011-2022 走看看