0

我有 2 个 java 文件。一个是inside.java,另一个是editor.java(这是一个applet)。我有一个JTextArea存档inside.java。当用户点击“编辑”按钮时,它应该运行一个并且所有来自的applet文本都应该被复制到。JTextAreainside.javaJTextAreaapplet

我该怎么做?

目前我正在使用desktop.open()调用editor.jnlp文件。还有其他方法可以运行applet和访问变量吗?

inside.java-->

private void editActionPerformed(java.awt.event.ActionEvent evt) {                                     
    // TODO add your handling code here:
    File file= new File("C://Users//user//Documents//NetBeansProjects//blogspot//dist//editor.jnlp");
    try{
        if (Desktop.isDesktopSupported()) {
            Desktop.getDesktop().open(file);
        }
    }catch(Exception e){
        System.out.println("ex:" + e.toString());
    };
}
4

1 回答 1

0

将 JTextArea 的内容保存在静态变量中,例如

public class Inside{

public static String TEXT_CONTENT = null;

//then when you saves the content:

TEXT_CONTENT = txtS.getText();
}

//then when you try to use it in another class:
String contentSaved = Inside.TEXT_CONTENT;

希望它符合您的要求。此致。(我避免了一些我确定你已经知道的代码)。

于 2013-03-26T17:12:02.480 回答