当前位置: 代码迷 >> Java相关 >> Java旋钮事件绑定
  详细解决方案

Java旋钮事件绑定

热度:62   发布时间:2016-04-22 19:26:24.0
Java按钮事件绑定
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");    }}}

 

  相关解决方案