gpt4 book ai didi

java - invokeAndWait Java

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:52:55 28 4
gpt4 key购买 nike

<分区>

谁能告诉我这两个代码之间的实际区别是什么,因为它们都产生相同的结果?

代码1:

public class JLabelDemo extends JApplet {
public void init() {
this.setSize(400, 400);
ImageIcon ii = new ImageIcon("Flock_icon.png");
JLabel jl = new JLabel("<<--- Flock_icon", ii, JLabel.CENTER);
add(jl);
}
}

代码2:

public class JLabelDemo extends JApplet {
private static final long serialVersionUID = 1L;

public void init() {
this.setSize(400, 400);
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
makeGUI();
}
});
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

private void makeGUI() {
ImageIcon ii = new ImageIcon("Flock_icon.png");
JLabel jl = new JLabel("<<--- Flock_icon", ii, JLabel.CENTER);
add(jl);
}
}

我真的没有发现生成的输出之间有任何区别。但是我看不懂代码。

So can anyone give me the real world example of invokeAndWait method??

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com