如何在绘制图形之前放置一个在Java applet中可见的加载屏幕? 我的代码:
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(){
...
}
}
在applet中绘制图形占用了加载时间的最大部分。获取表示图形并将其解析为Graph对象的字符串相对便宜。任何帮助将不胜感激!
答案 0 :(得分:2)
在一张卡片中使用CardLayout
JProgressBar
(或动画“加载”图标),在另一张卡片中使用图表。首先默认为“加载”卡,然后在SwingWorker
中执行长时间运行的任务。返回结果后,准备图表,将其添加到另一张卡片&翻到那张卡片。