如果我使用 GUI 文本字段,我还需要使用扫描仪吗?
I have this in my GUI class to get the users input
JButton startButton = new JButton("Start");
startButton.setBounds(75, 94, 210, 32);
getContentPane().add(startButton);
targetInput = new JTextField();
targetInput.setBounds(75, 50, 210, 33);
targetInput.setHorizontalAlignment(SwingConstants.CENTER);
targetInput.setToolTipText("");
getContentPane().add(targetInput);
targetInput.setColumns(1);
我在我的主类中如何调用它?
如果我从控制台调用,我只需导入扫描仪并调用输入即可。然而,由于它是在 GUI 中,我不确定如何继续。
最佳答案
你只需要做
字符串输入 = targetInput.getText();
关于java - 通过 GUI 获取用户输入的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32615166/