如何响应文本行的事件? 让JTextField响应一个onChanged事件 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给JTextField加个ActionListener 分析该代码!!!!import javax.swing.*;import java.awt.*;import java.awt.event.*;public class FlowLayoutTest extends JFrame implements TextListener{ public static final int WIDTh =300; public static final int HEIGHT = 200; private JTextArea theText; public JTextField name; public FlowLayoutTest() { setSize(480,200); addWindowListener(new WindowDestroyer()); setTitle("测试"); Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); JPanel firstLine1 = new JPanel(); JLabel nameLabel = new JLabel("输入姓名:"); JLabel passportLabel = new JLabel("输入密码:"); name = new JTextField(12); name.addTextListener(this);/*该句有错*/ JTextField passport = new JTextField(12); JTextArea theText = new JTextArea(80,40); theText.setEditable(true); JScrollPane scrolledText = new JScrollPane(theText); scrolledText.setVerticalScrollBarPoli(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); contentPane.add(nameLabel); contentPane.add(name); contentPane.add(passportLabel); contentPane.add(passport); contentPane.add(scrolledText); } public void textValueChanged(TextEvent e) { theText.setText("你好,"+name.getText()+",欢迎你!"); } public static void main(String[]args) { FlowLayoutTest flow = new FlowLayoutTest(); flow.setVisible(true); }} 可以给它加入ActionListener, 一回车就会响应 我已经解决了,问题的关键在于把JTextArea的对象的误定义为局部变量,之后actionPerformde()中就不能访问它了!! 关于导出jar运行的问题 怎样可以记录第二个窗体的分数和把分数的记录设置在第一个窗体 图片转为视频流 java如何执行db2 import语句 如何实现ID生成方法 看看这个程序哪里错了。 求教:关于JDBC打包成JAR的问题!! 关于JAVA的类的定义格式解释? 求助:怎样做一个状态栏控件? 启动JBuilder6时出显错误:Unknown license file format,然后就不能启动。该怎么办? 为什么会这样? 如何把字符串转换为浮点型?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FlowLayoutTest extends JFrame implements TextListener
{
public static final int WIDTh =300;
public static final int HEIGHT = 200;
private JTextArea theText;
public JTextField name;
public FlowLayoutTest()
{
setSize(480,200);
addWindowListener(new WindowDestroyer());
setTitle("测试");
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout()); JPanel firstLine1 = new JPanel();
JLabel nameLabel = new JLabel("输入姓名:");
JLabel passportLabel = new JLabel("输入密码:");
name = new JTextField(12);
name.addTextListener(this);/*该句有错*/ JTextField passport = new JTextField(12); JTextArea theText = new JTextArea(80,40);
theText.setEditable(true);
JScrollPane scrolledText = new JScrollPane(theText);
scrolledText.setVerticalScrollBarPoli(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
contentPane.add(nameLabel);
contentPane.add(name);
contentPane.add(passportLabel);
contentPane.add(passport); contentPane.add(scrolledText);
} public void textValueChanged(TextEvent e)
{
theText.setText("你好,"+name.getText()+",欢迎你!");
}
public static void main(String[]args)
{
FlowLayoutTest flow = new FlowLayoutTest();
flow.setVisible(true);
}}