KirbyWallace
Programmer
Really stuck on this one...
I am about to .setText() on a textfield, but just before I attempt it, I need to check whether the field exists or not: the jFrame form that it is on may or may not be open.
Any ideas?
Thanks
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
if (frame.isVisible()) {
textField.setText("Here is some text");
}
public class Main {
public static void main(String[] args) {
int i;
String cInputFile = "";
String cOutputFile = "";
// process the command line for requested options.
for (i = 0; i < args.length; i++) {
if (args[i].equals("-i")) {
cInputFile = args[i + 1];
}
if (args[i].equals("-o")) {
cOutputFile = args[i + 1];
}
}
// neither param specified - OPEN FORM TO GET THEM
if (cInputFile.equals("") && cOutputFile.equals("")) {
//*********************************************
//************** LOOK HERE ********************
//*********************************************
MainFrame mf = new MainFrame();
mf.setVisible(true);
}
// Input but not output, dump to console
if (!cInputFile.equals("") && cOutputFile.equals("")) {
FileToConsole.fileToConsole(cInputFile);
}
// input AND output - file copy
if (!cInputFile.equals("") && !cOutputFile.equals("")) {
FileToFile.fileToFile(cInputFile,cOutputFile);
}
}
}
public class MainFrame extends javax.swing.JFrame {
JFileChooser fc;
public MainFrame() {
initComponents();
fc = new JFileChooser();
fc.setCurrentDirectory(new File("."));
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
:
: GENERATED CODE/SWING LAYOUTS - not included here
:
:
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
//*********************************************
//************** LOOK HERE ********************
//*********************************************
new MainFrame().setVisible(true);
}
});
}
}
public class FileToConsole {
public static void fileToConsole(String cFile) {
try {
BufferedReader input = new BufferedReader(new FileReader(new File(cFile)));
String line = null;
while (( line = input.readLine()) != null) {
System.out.println(line);
//*********************************************
//************** LOOK HERE ********************
//*********************************************
// Add the same line to the jTextArea on the
// MainFrame Panel, IF it is visible...
}
}
catch (IOException ex) {
System.out.println("File Not Found");
}
}
}