您的位置:首页 > 编程语言 > Java开发

Java 中的JButton按钮事件

2017-08-23 16:52 447 查看
package com.Swing;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;
public class ButtonExample {
public static void main(String[] args) {
JFrame f = new JFrame("Demo");
final JTextField tf = new JTextField();
tf.setBounds(50, 50, 150, 20);
JButton b = new JButton("点击");
b.setBounds(100, 100, 65, 30);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tf.setText("按钮事件如此简单");
tf.setBackground(Color.cyan);
}
});
f.add(b);
f.add(tf);
f.setSize(300, 250);
f.setLocationRelativeTo(null);
f.setLayout(null);
f.setVisible(true);
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: