原标题:Java的按钮点击案例
我们建立一个项目去开始今天的测试。项目结构如下:
demo很简单,点击button按钮,修改button上显示的文字:
package com.huhx.frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
/**
* writer: huhx
*/
public class Jframe extends JFrame {
private JButton button;
public Jframe() {
button = new JButton("text");
add(button);
setVisible(true);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
button.setText("world");
}
});
}
public static void main(String[] args) {
new Jframe();
}
}
责任编辑: