加载生成的词云时,空白JFrame

时间:2019-02-20 15:43:58

标签: java word-cloud

目前,我正在尝试在GUI上使用一个按钮,以从kumo生成文字云png。

这些是在我的GUI按钮中为wordcloud生成png的代码。

    JButton wordCloud = new JButton("Generate WordCloud");
    wordCloud.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            final Random RANDOM = new Random();
            final FrequencyAnalyzer frequencyAnalyzer = new FrequencyAnalyzer();
            final List<WordFrequency> wordFrequencies = frequencyAnalyzer.load(data.get_data());
            final Dimension dimension = new Dimension(600, 600);
            final WordCloud wordCloud = new WordCloud(dimension, CollisionMode.PIXEL_PERFECT);
            wordCloud.setPadding(2);
            wordCloud.setBackground(new CircleBackground(300));
            wordCloud.setColorPalette(new ColorPalette(new Color(0x4055F1), new Color(0x408DF1), new Color(0x40AAF1), new Color(0x40C5F1), new Color(0x40D3F1), new Color(0xFFFFFF)));
            wordCloud.setFontScalar(new SqrtFontScalar(10, 40));
            wordCloud.build(wordFrequencies);
            wordCloud.writeToFile("bin/gui/wordcloud_circle.png");

这些是我单击按钮时用来显示PNG文件的代码

            JFrame b = new JFrame("Word Cloud");
            b.add(new JLabel(new ImageIcon("wordcloud_circle.png")));
            b.setSize(700,700);
            b.setVisible(true);

代码本身似乎可以单独工作,但是当我像这样将它们组合在一起时

    JButton wordCloud = new JButton("Generate WordCloud");
    wordCloud.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            final Random RANDOM = new Random();
            final FrequencyAnalyzer frequencyAnalyzer = new FrequencyAnalyzer();
            final List<WordFrequency> wordFrequencies = frequencyAnalyzer.load(data.get_data());
            final Dimension dimension = new Dimension(600, 600);
            final WordCloud wordCloud = new WordCloud(dimension, CollisionMode.PIXEL_PERFECT);
            wordCloud.setPadding(2);
            wordCloud.setBackground(new CircleBackground(300));
            wordCloud.setColorPalette(new ColorPalette(new Color(0x4055F1), new Color(0x408DF1), new Color(0x40AAF1), new Color(0x40C5F1), new Color(0x40D3F1), new Color(0xFFFFFF)));
            wordCloud.setFontScalar(new SqrtFontScalar(10, 40));
            wordCloud.build(wordFrequencies);
            wordCloud.writeToFile("bin/gui/wordcloud_circle.png");

            JFrame b = new JFrame("Word Cloud");
            b.add(new JLabel(new ImageIcon("wordcloud_circle.png")));
            b.setSize(700,700);
            b.setVisible(true);

当我将它们组合在一起时,这些代码似乎不起作用,并且框架只会显示一个空白的空白框架。

有人知道解决这个问题的方法吗?

我想让按钮既生成png,又显示png以同时进行构图。

非常感谢您。

0 个答案:

没有答案