作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 netbeans 中遇到一个项目问题:我主要上课:
CLASS MainFrame
...
Model m = null;
File f;
String filename = "";
String specific = readSpecification();
private void openModelActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text");
chooser.setFileFilter(filter);
chooser.showOpenDialog(null);
f = chooser.getSelectedFile();
filename = f.getAbsolutePath();
PrincipalFrame prFrame1 = new PrincipalFrame();
prFrame1.setVisible(true);
}
public String readSpecification() {
String spec = "";
/**
* Reads the model specification from file.
*
* @return a <code>String</code> with the model specification
*/
try {
BufferedReader reader = new BufferedReader(new FileReader(filename));
String line = reader.readLine();
while(line!=null) {
spec += line + "\n";
line = reader.readLine();
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
return spec;
}
}
PrincipalFrame 类大部分是空的。
MainFrame 类应选择要打开的 file.txt。PrimaryFrame 类有一个 JTextArea,应使用 MainFrame 类选择的 txt 来实现。换句话说,在MainFrame打开的第一刻,用户应该选择一个txt文件。一旦他选择了它,PrincipalFrame 就会出现,并且它的 JTextArea 应该已经用 file.txt 填充了。希望现在一切都清楚了!感谢您的帮助!
最佳答案
您可以在 PrincipalFrame
类中创建一个 setSpecification
方法来填充 JTextArea
。通过这种方式,您可以将规范文本从 MainFrame
传递到 PrincipalFrame
类。例如:
MainFrame.java:
public class MainFrame {
// [...]
private void openModelActionPerformed(java.awt.event.ActionEvent evt) {
// [...]
filename = f.getAbsolutePath();
PrincipalFrame prFrame1 = new PrincipalFrame();
prFrame1.setSpecification(readSpecification());
prFrame1.setVisible(true);
}
// [...]
}
PrincipalFrame.java:
public class PrincipalFrame {
private JTextArea textArea;
// [...]
public void setSpecification(String specification) {
textArea.setText(specification);
}
}
关于java - 在不同类的 JTextArea (java) 中加载文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35638264/
我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码: $y = 100; $n = 250; $m = 300; $number = ($y
我只是无法弄清楚这一点,也找不到任何对我来说有意义的类似问题。我的问题:我从数据库中提取记录,并在我的网页上以每个面板 12 条的倍数显示它们。因此,我需要知道有多少个面板可以使用 JavaScrip
我是一名优秀的程序员,十分优秀!