简体   繁体   English

如何验证来自SWT Text小部件的输入并分配给变量?

[英]How to verifying input from SWT Text widget and assign to variable?

This SWT program has a Group called mBuy, which includes Text Field to enter a stock's buy price. 该SWT程序有一个名为mBuy的组,其中包括输入股票买入价格的文本字段。 Once the calculate button is pressed and event listener is activated, I want to assign whatever content is inside this text field to a variable, which I have initialized here. 按下计算按钮并激活事件监听器后,我想将此文本字段内的任何内容分配给变量,我已在此处初始化。

final Text tmp0 = new Text(mBuy, SWT.SINGLE);
tmp0.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

// Calculate Button
Button tmp3 = new Button(mBuy, SWT.PUSH);
tmp3.setText("Calculate");
tmp3.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));

// if calculate button is pressed
tmp3.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent e) {
        //take the decimal value inside textbox 
        bPrice=Double.parseDouble(tmp0.getText());
        // don't show buy menu anymore
        mBuy.dispose();

    }
});

It's just tmp0.getText() . 它只是tmp0.getText() You should look at the Javadocs for SWT . 你应该看一下SWTJavadocs

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

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