0

在绘制图形之前,如何放置在 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 对象相对便宜。任何帮助,将不胜感激!

4

1 回答 1

2

在一张卡片中使用CardLayout带有 JProgressBar(或动画“加载”图标)的 a,在另一张卡片中使用图表。默认为“加载”卡,然后在SwingWorker. 返回结果后,准备图表,将其添加到另一张卡片并翻转到该卡片。

于 2012-06-10T05:46:21.280 回答