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

 

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

 

事件处理

相关文章:

  • 2021-06-22
  • 2021-09-28
  • 2021-12-14
  • 2022-01-17
  • 2021-12-05
  • 2022-01-18
  • 2021-09-17
  • 2021-06-17
猜你喜欢
  • 2022-02-25
  • 2021-11-08
  • 2022-02-18
相关资源
相似解决方案