事件处理程序

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

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);
        
    }

}

 

posted @ 2019-05-08 20:22  廖文龙  阅读(179)  评论(0编辑  收藏  举报