java--事件处理程序

 1 package LHB.inherit;
 2 import javax.swing.*;
 3 import java.awt.*;
 4 import java.awt.event.ActionEvent;
 5 import java.awt.event.ActionListener;
 6 public class Windows implements ActionListener
 7 {
 8     JFrame f;
 9     JPanel p;
10     JLabel a1,a2;
11     JTextField c1,c2;
12     JButton b1,b2;
13     public Windows()
14     {
15         f=new JFrame("登陆");
16         p=new JPanel();
17         a1=new JLabel("用户名:");
18         a2=new JLabel("   口令:");
19         b1=new JButton("确定");
20         b2=new JButton("取消");
21         c1=new JTextField(5);
22         c2=new JTextField(5);
23         f.setVisible(true);
24         f.setSize(180,150);
25         b1.addActionListener((ActionListener) this);
26         p.add(a1);
27         p.add(c1);
28         p.add(a2);
29         p.add(c2);
30         p.add(b1);
31         p.add(b2);
32         f.add(p);
33     }
34     public void actionPerformed(ActionEvent e) 
35     {
36             p.setBackground(Color.blue);
37         }
38     public static void main(String[] args) 
39     {
40         new Windows();
41     }
42 
43 }

 

 

 

转载于:https://www.cnblogs.com/sky666666/p/10875088.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值