【问题标题】:JApplet loading screen while drawing绘图时JApplet加载屏幕
【发布时间】:2012-06-10 19:50:39
【问题描述】:

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

【问题讨论】:

  • 任何需要很长时间才能完成的事情都应该在后台线程中完成,例如 SwingWorker 对象。
  • 顺便问一下,你在哪里“画图”?上面哪些代码行需要很长时间才能处理?此外,你将字符串解析为某种图形对我来说很有趣。这是一个 XML 字符串吗?
  • 不,是点语言,用来描述图。

标签: java swing loading graphviz japplet


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-25
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    相关资源
    最近更新 更多