KirbyWallace
Programmer
In my attempts to escape the static dungeon in which I seem to have found myself, I've modified my previous attempt at this to the following:
Why does it think that it's in a static context? Nothing about the class (or the constructor) indicates staticicity...
Are constructors themselves static by default?
What I am trying to accomplish is pretty simple. "MainFrame" is a swing form which contains the text field (txt_OutputWindow) you see me trying to write to.
The only tricky bit is maybe that it's a button handler on that form that has created this instance of FileToConsole that I've presented here. The form calls the class, and I want the class to be able to write back onto one of the form's text fields.
If anyone can see through what I'm doing, to what I'm trying to do, please feel free to chime in.
Code:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class FileToConsole {
String cLine = null;
public FileToConsole(String cFile) {
try {
BufferedReader input = new BufferedReader(new FileReader(new File(cFile)));
while (( cLine = input.readLine()) != null) {
System.out.println(cLine);
// Add the same line to the jTextArea on the
// MainFrame Panel, IF it is open...
// how to check that it is open???
// ERROR ON FOLLOWING LINE: non-static variable
// txt_OutputWindow cannot be referenced from
// a static context
MainFrame.txt_OutputWindow.setText(cLine);
}
}
catch (IOException ex) {
System.out.println("File Not Found");
}
}
}
Why does it think that it's in a static context? Nothing about the class (or the constructor) indicates staticicity...
Are constructors themselves static by default?
What I am trying to accomplish is pretty simple. "MainFrame" is a swing form which contains the text field (txt_OutputWindow) you see me trying to write to.
The only tricky bit is maybe that it's a button handler on that form that has created this instance of FileToConsole that I've presented here. The form calls the class, and I want the class to be able to write back onto one of the form's text fields.
If anyone can see through what I'm doing, to what I'm trying to do, please feel free to chime in.