鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 网站制作教程 > JSP > >

Java按钮事件绑定

来源:互联网 作者:佚名 时间:2016-06-19 09:55
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 v
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");
    }
}

}

 


网友评论
<