gpt4 book ai didi

java - 绘图时的 JApplet 加载屏幕

转载 作者:行者123 更新时间:2023-12-02 07:45:19 27 4
gpt4 key购买 nike

如何放置一个在绘制图形之前在 Java 小程序中可见的加载屏幕?我的代码:

public class Test extends JApplet 
{
GrappaPanel gp = null;
JPanel jpanel = null;
JEditorPane dataDisplayer = null;
Graph graph = null;
JProgressBar progressBar = null;

public void init() {
Parser program =null;
InputStream input;
String sgraph = getGraph();
try {
input = new ByteArrayInputStream(sgraph.getBytes("UTF-8"));
program = new Parser(input);
program.parse();
} catch (Exception e) {
e.printStackTrace();
}
graph = program.getGraph();
gp = new GrappaPanel(graph);
JScrollPane jspg = new JScrollPane(gp,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
GridBagLayout gb = new GridBagLayout();
jpanel = new JPanel(gb);
setContentPane(jpanel);
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gb.setConstraints(jspg,gbc);
jpanel.add(jspg);
}

private String getGraph(){
...
}

}

在小程序中绘制图表占用了加载时间的最大部分。获取表示图的字符串并将其解析为 Graph 对象相对便宜。任何帮助将不胜感激!

最佳答案

在一张卡中使用 CardLayoutJProgressBar(或动画“加载”图标),在另一张卡中使用图表。默认首先使用“加载”卡,然后在 SwingWorker 中执行长时间运行的任务。返回结果后,准备图表,将其添加到另一张卡并翻转到该卡。

关于java - 绘图时的 JApplet 加载屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10964255/

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