1.处理东、南、西、北四个按钮,以及文本框的actionevent事件。当事件发生,,监视器计算字符的长度,并在命令行窗体显示按钮的文本内容或文本框的文本内容。


代码:
package 实验4;
public class test {
public static void main(String args[]){
WindowActionEvent win= new WindowActionEvent();
win.setTitle("处理ActionEvent事件");
win.setBounds(100,100,310,260);
}
}
package 实验4;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class WindowActionEvent extends JFrame{
JTextField text;
ActionListener listener;
JButton a1,a2,a3,a4;
public WindowActionEvent(){
setLayout(new BorderLayout());
text = new JTextField("JAVA的事件响应",10);
a1=new JButton("我是北按键");
a2=new

本文介绍如何处理Java中的ActionEvent,特别是针对按钮和文本框。当事件触发时,程序会计算字符长度并在控制台展示按钮文本或文本框内容。
最低0.47元/天 解锁文章
481

被折叠的 条评论
为什么被折叠?



