如何在我的扫描仪之前调用GUI代码?

如何在我的扫描仪之前调用GUI代码?,第1张

如何在我的扫描仪之前调用GUI代码?

使用

invokeLater()
启动GUI
后, 你得到的输入。

    final String response = in.nextLine();    EventQueue.invokeLater(new Runnable() {        @Override        public void run() { new Client(response);        }    });

请注意,由于时序差异,您的示例在我的平台上运行良好。还可以考虑使用

args
数组传递参数,或询问实现方法,如
FullScreenTest

附录:仔细阅读其他线程,可以使用以下方法

Namedframe
在单独的JVM
中启动。

package cli;import java.awt.EventQueue;import java.io.IOException;import java.util.Scanner;import javax.swing.Jframe;public class CommandLineClient {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        System.out.print("Give me a name for the screen: ");        final String response = in.nextLine();        try { ProcessBuilder pb = new ProcessBuilder(     "java", "-cp", "build/classes", "cli.Namedframe", response); Process proc = pb.start();        } catch (IOException ex) { ex.printStackTrace(System.err);        }    }}class Namedframe extends Jframe {    public Namedframe(String title) {        super(title);        setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);        setLocationByPlatform(true);        setVisible(true);    }    public static void main(final String[] args) {        EventQueue.invokeLater(new Runnable() { @Override public void run() {     Jframe f = new Namedframe(args[0]); }        });    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5052129.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存