设置一个触发响应事件?

比如消息框.....

 package hello;
import javax.swing.*;
import project.readerListen;
import java.awt.*;
import java.awt.event.*;
class WindGrid extends JFrame{ JTextField text;
ActionListener listener; public WindGrid(String title)
{
setTitle(title);
init();
setBounds(,,,);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} void init()
{
text = new JTextField();
listener = new ReaderListen(); //自定义的 那个类
setLayout(new FlowLayout());
text.addActionListener(listener);
add(new Label("输入蚊子 "));
add(text);
} }
public class test {
public static void main(String args[])
{
new WindGrid("第一个窗口");
}
}
 package hello;

 import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ReaderListen extends JFrame implements ActionListener
{ public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
JFrame myjframe;
myjframe = new JFrame();
JTextArea mytest;
mytest =new JTextArea(e.getActionCommand(),,);
myjframe.add(mytest);
myjframe.setBounds(, , , );
myjframe.setVisible(true); }
}

初学java之触发响应事件举例子-LMLPHP

05-06 04:23