美文网首页
2018-04-26

2018-04-26

作者: jhcbin | 来源:发表于2018-04-26 15:52 被阅读0次

package cn.jhc;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

public class ClickListernerDemo extends JFrame implements ActionListener {

JPanel p;

JButton b;

JLabel l;

int count = 0;

public ClickListernerDemo() {

p = new JPanel();

b = new JButton("点击");

l = new JLabel(count + "次");

b.addActionListener(this);

p.add(l);

p.add(b);

this.add(p);

this.setSize(300, 100);

this.setLocation(300, 300);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

ClickListernerDemo a = new ClickListernerDemo();

a.setVisible(true);

}

public void addActionListener() {

count++;

l.setText(count + "次");

}

@Override

public void actionPerformed(ActionEvent e) {

count++;

l.setText(count + "次");

}

}

相关文章

网友评论

      本文标题:2018-04-26

      本文链接:https://www.haomeiwen.com/subject/nccmlftx.html