zoukankan      html  css  js  c++  java
  • java事件

     1 package Action;
     2 
     3 import java.awt.*;
     4 import java.awt.event.*;
     5 import javax.swing.*;
     6 
     7 class JButtonEventEx implements ActionListener {
     8 
     9     JFrame frame;
    10     JLabel label;
    11     JButton[] button;
    12     public JButtonEventEx()
    13     {
    14         frame=new JFrame("按钮事件处理");
    15         frame.setContentPane(createContentPane());
    16         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    17         frame.setLocation(400,250);
    18         frame.pack();
    19         frame.setVisible(true);
    20     }
    21     
    22     public void actionPerformed(ActionEvent e)
    23     {
    24         JButton b=(JButton)e.getSource();
    25         label.setText(b.getText());
    26     }
    27     
    28     public Container createContentPane()
    29     {
    30         label=new JLabel("Button ?");
    31         button =new JButton[3];
    32         Container contentPane=frame.getContentPane();
    33         contentPane.setLayout(new FlowLayout(FlowLayout.RIGHT,5,10));
    34         contentPane.add(label);
    35         for(int i=0;i<button.length;i++)
    36         {
    37             button[i]=new JButton("button"+i);
    38             button[i].addActionListener(this);
    39             contentPane.add(button[i]);            
    40         }
    41         return contentPane;
    42     }
    43     
    44     public static void main(String[] args) {
    45         new JButtonEventEx();
    46     }
    47 
    48 }
  • 相关阅读:
    手机测试移动端项目
    事件绑定与事件委托
    jq中attr()和prop() 属性的区别
    jq 加载的几种方法
    $(document).height 与$(window).height的区别
    js动画之缓冲运动
    js动画之简单运动二
    js动画之简单运动一
    css浏览器窗口大小
    编程每一天
  • 原文地址:https://www.cnblogs.com/delphione/p/3080005.html
Copyright © 2011-2022 走看看