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

 

package ccc;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class window implements ActionListener{
JFrame f;
JButton s;
JLabel p;
JPanel a;
public window() {
f=new JFrame();
s=new JButton("点击");
p=new JLabel();
a=new JPanel();
s.addActionListener(this);
f.setSize(800,600);
f.setVisible(true);
f.add(a); 
a.add(s);
a.add(p);
}
public static void main(String[]arge){
new window();
}
public void actionPerformed(ActionEvent e) {
a.setBackground(Color.yellow);
}
}

 

事件处理

相关文章:

  • 2022-02-25
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2022-02-18
  • 2021-07-14
猜你喜欢
  • 2021-11-08
相关资源
相似解决方案