我可是從文本框獲取整數。我爲我的GUI創建了一個基於SWT的外殼佈局。我在GUI中有一個文本框。用作GUI時,我想從文本框中獲取整數值。我發現文本框只有選項才能獲得對象或文本。有沒有選擇從文本框中獲取Integer?如果是這樣,我該怎麼做?使用的WindowBuilder建立GUI我的應用程序的WindowBuilder
我從的WindowBuilder的源擁有的代碼如下:
import org.eclipse.swt.SWT;
import otf.EnterLeaveHandler;
public class test {
protected Shell shell;
private Text text;
private final FormToolkit formToolkit = new FormToolkit(
Display.getDefault());
public static void main(String[] args) {
try {
test window = new test();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected void createContents() {
shell = new Shell();
shell.setSize(545, 419);
shell.setText("SWT Application");
shell.setLayout(null);
Button btnNewButton = new Button(shell, SWT.NONE);
btnNewButton.setBounds(213, 243, 75, 25);
btnNewButton.setText("Ok");
Label lblNewLabel = new Label(shell, SWT.NONE);
lblNewLabel.setBounds(190, 87, 137, 15);
lblNewLabel.setText("Enter function name");
text = new Text(shell, SWT.BORDER);
text.setBounds(213, 129, 76, 21);
final Label lblNewLabel_1 = formToolkit.createLabel(shell, "New Label", SWT.NONE);
lblNewLabel_1.setBounds(72, 184, 55, 15);
final EnterLeaveHandler ne = new EnterLeaveHandler();
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
Integer getvalue = Integer.parseInt(text.getText());
ne.cpuid_filter(getvalue);
}
});
}
}
爲什麼土特產品不只是分析文本,以「整」? – mabbas