我有2个java文件。一个是inside.java
,另一个是editor.java
(applet
)。
我在JTextArea
文件中有一个inside.java
。当用户点击“修改”按钮时,它应该会运行applet
,JTextArea
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());
};
}
答案 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;
希望它符合您的要求。最好的祝福。 (我避免使用一些我相信你已经知道的代码。)