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

代码

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
 1 package Person;
 2 import java.awt.*;
 3 import javax.swing.*;
 4 
 5 class Example extends JFrame{
 6     public void CrFrame(String title){
 7         JFrame f=new JFrame(title);
 8         Container container=f.getContentPane();        //容器
 9         
10         JLabel l=new JLabel("这是一个居中的标签 :)");        //标签
11         l.setHorizontalAlignment(SwingConstants.CENTER);    //标签居中
12         container.add(l);
13         container.setBackground(Color.pink);
14         f.setVisible(true);
15         f.setSize(500,500);
16         f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
17     }
18 }
19 
20 public class Button {
21     public static void main(String[] args) {
22         new Example().CrFrame("来创建一个窗口");
23     }
24         
25 }

运行界面

 Java事件处理程序 随笔

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄