简体   繁体   English

从Java JTextarea收集输入

[英]Collect Input from a Java JTextarea

I'm working on one of my first java applets and I want to start of fairly simple (though I have a good understanding of how code works I dont know much in terms of what methods I all have at my disposal when using java) 我正在研究我的第一个Java小程序,我想开始相当简单(尽管我对代码的工作方式有很好的了解,但是我对使用Java时可以使用的方法知之甚少)

I have created a Jframe window that has a JTextarea in it. 我创建了一个Jframe窗口,其中包含JTextarea。 I would like to execute certain lines of code when certain things are typed into this box. 当在此框中键入某些内容时,我想执行某些代码行。 In essence, its a simple text input system. 从本质上讲,它是一个简单的文本输入系统。 How would I go about doing this or is there a better component to use for this? 我将如何执行此操作,或者有更好的组件用于此操作?

in addition to getText() , for JTextField some prefer the getDocument() method. 除了getText() ,对于JTextField有些人更喜欢getDocument()方法。 In Java, Listener s are used to capture events, such as "what was typed to the text area". 在Java中, Listener用于捕获事件,例如“在文本区域中键入了什么”。 This tutorial will get you started, if you have trouble implementing you can come back with a more specfic question and some code :) 教程将帮助您入门,如果您在实施时遇到困难,可以返回一个更具体的问题和一些代码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM