码迷,mamicode.com
首页 > 编程语言 > 详细

Java按钮事件绑定

时间:2015-12-09 17:21:19      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

package present;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Main  {
    JButton lable;
    JButton font;
    public static void main(String[] args) {
        new Main().go();
    }

    public void go() {
        JFrame frame = new JFrame();
        lable = new JButton("click lable");
        lable.addActionListener(new LableButton());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(BorderLayout.EAST,lable);
        font = new JButton("click font");
        font.addActionListener(new FontButton());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(BorderLayout.WEST,font);
        frame.setSize(300, 300);
        frame.setVisible(true);
    }

class LableButton implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        lable.setText("lable");
    }
}
class FontButton implements ActionListener{
    
    @Override
    public void actionPerformed(ActionEvent e) {
        font.setText("font");
    }
}

}

 

Java按钮事件绑定

标签:

原文地址:http://www.cnblogs.com/liunlls/p/ActionListener.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!