如何在Applet中访问一个类(或.java文件)的JTextArea文本?

时间:2013-03-26 15:05:32

标签: java swing applet

我有2个java文件。一个是inside.java,另一个是editor.javaapplet)。 我在JTextArea文件中有一个inside.java。当用户点击“修改”按钮时,它应该会运行appletJTextArea inside.java中的所有文字都应该复制到JTextArea applet

我该怎么做?

目前我正在使用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());
    };
}

1 个答案:

答案 0 :(得分: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;

希望它符合您的要求。最好的祝福。 (我避免使用一些我相信你已经知道的代码。)