java - JButton运行主方法

标签 java swing text-mining

我正在做一些文本挖掘应用程序。它由 TextRazor API Java Swing 组成。如何使用 JButton 运行 main() 类?单击按钮后,必须触发 main() 类中的代码。下面是代码,请帮帮我。

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {   
    //I want the main class to be called here** 
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {         
    JOptionPane.showMessageDialog(null, "Completed Analysis!","Alert", 1);
    jButton5.setEnabled(false);
    jTextArea2.setEditable(false);
    jTextArea3.setEditable(false);
}   
    /**
     * @param args
     * @throws NetworkException 
     */
public static void main(String[] args) throws NetworkException, AnalysisException {

    // Sample request, showcasing a couple of TextRazor features
    String API_KEY = "7d5066bec76cb47f4eb4e557c60e9b979f9a748aacbdc5a44ef9375a";

    TextRazor client = new TextRazor(API_KEY);

    client.addExtractor("words");
    client.addExtractor("entities");
    client.addExtractor("entailments");
    client.addExtractor("senses");
    client.addExtractor("entity_companies");

    String rules = "entity_companies(CompanyEntity) :- entity_type(CompanyEntity, 'Company').";

    client.setRules(rules);

    AnalyzedText response = client.analyze("Barclays misled shareholders and the public RBS about one of the biggest investments in the bank's history, a BBC Panorama investigation has found.");

    for (Sentence sentence : response.getResponse().getSentences()) {
        for (Word word : sentence.getWords()) {
            System.out.println("----------------");
            System.out.println("Word: " + word.getLemma());

            for (Entity entity : word.getEntities()) {
                System.out.println("Matched Entity: " + entity.getEntityId());
            }
            for (Sense sense: word.getSenses()) {
                System.out.println("Word sense: " + sense.getSynset() + " has score: " + sense.getScore());
            }                
        }
    }

    // Use a custom rule to match 'Company' type entities

    for (Custom custom : response.getResponse().getCustomAnnotations()) {
        for (Custom.BoundVariable variable : custom.getContents()) {
            if (null != variable.getEntityValue()) {
                for (Entity entity : variable.getEntityValue()) {
                    System.out.println("Variable: " + variable.getKey() + " Value:" + entity.getEntityId());
                }
            }
        }
    }           
}

最佳答案

Class中的Main方法也是一个普通方法,它的目的是让JVM启动java应用程序。但是,您也可以在您的方法中调用它

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {         
    JOptionPane.showMessageDialog(null, "Completed Analysis!","Alert", 1);
    jButton5.setEnabled(false);
    jTextArea2.setEditable(false);
    jTextArea3.setEditable(false);
    ClassName.main(new String[]{"arg1","arg2"}); 
}  

添加了虚拟参数以仅调用 main 方法

关于java - JButton运行主方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20853830/

相关文章:

java - 在 AWT 事件模型中冒泡?

java - 我可以创建 "complex"渐变来实现 swing(x) 组件上的阴影吗

java - 找不到在对象类中定义的符号(方法)

java - Spring 启动 : Cors policy missing 'access-control-allow-origin'

java - 如何在 Java 中创建一个 zip 文件

java - 如何在任务栏上制作 Windows 7 加载栏

java - 使用netbeans在java中添加jTextfields值

machine-learning - 比较文本文档含义的最佳方法?

apache-spark - 基于 Apache Spark 朴素贝叶斯的文本分类

r - 如何在 R 中的 DTM 中查找词频?