java 如何从 netbeans RCP 应用程序中的文本字段获取输入?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1383676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get the input from a textfield in a netbeans RCP app?
提问by Pierre
I am making a text based game in Java. I have a text field, enter button, and a label.
我正在用 Java 制作一个基于文本的游戏。我有一个文本字段、输入按钮和一个标签。
What code do i use to scan the text field once the button is clicked and respond?
单击按钮并响应后,我使用什么代码来扫描文本字段?
So that if I type in (launch missile) the label should say (missile launched).
因此,如果我输入(发射导弹),标签应显示(发射导弹)。
I will be listening to a button actionperformedor maybe a mouseclick event . Something like this
我会听一个按钮actionperformed或者一个 mouseclick 事件。像这样的东西
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if (Text field says: launch missile)
{print on label:Missile launched}
or
或者
if (text field says: invade)
{Print on label: Invasion started}
回答by Aziz
回答by Pierre
try
尝试
JButton launch=new JButton(new AbstractAction("Launch")
{
@Override
public void actionPerformed(ActionEvent e)
{
yourLabel.setText("Missile Launched");
}
});

