alanmin
asked on
a piece of code
public void actionPerformed(ActionEven t ae) {
//****deals with the buttons pressed****//
String str = ae.getActionCommand();
if(str.equals("Enter")) {
readNums();
count++;
}
else if(str.equals("Reset")) {
resetit();
}
else if(str.equals("Show")) {
setVisible(false);
s.setVisible(true);
}
}
public void readNums() throws IOException{
try {
fos = new FileOutputStream("C:/WINDO WS/Desktop /Aljava/Pr oject2/pla ne.txt");
} catch (IOException e) {
}
for (i=0; i<14; i++) {
air[i] = String.valueOf(tf[i].getTe xt());
}
}
}
in the code above I wish for the user to enter 14 strings of text then read them to a file each time the enter button is pressed however it appears that you can't throw an exception out of an action performed function does anyone have any ideas how to do this. I can't call it in the main method as the funcion always requires the enter button to be pressed!
//****deals with the buttons pressed****//
String str = ae.getActionCommand();
if(str.equals("Enter")) {
readNums();
count++;
}
else if(str.equals("Reset")) {
resetit();
}
else if(str.equals("Show")) {
setVisible(false);
s.setVisible(true);
}
}
public void readNums() throws IOException{
try {
fos = new FileOutputStream("C:/WINDO
} catch (IOException e) {
}
for (i=0; i<14; i++) {
air[i] = String.valueOf(tf[i].getTe
}
}
}
in the code above I wish for the user to enter 14 strings of text then read them to a file each time the enter button is pressed however it appears that you can't throw an exception out of an action performed function does anyone have any ideas how to do this. I can't call it in the main method as the funcion always requires the enter button to be pressed!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The code as it stands seems reasonable. In other words there are
no obvious problems left. However, you have, politely, not posted
all the code, so various declarations are not visible. It could
be some variable being automatic rather than instance or class,
or something like that. Anyway, the next step I would take, is
to add a console printing line to the output loop. After
prt.println(air[i][j]);
add
System.out.println(air[i][ j]);
and maybe before the two for loops add
System.out.println(count);
This may illuminate what it going on. At least it will verify
whether or not the loop is executing as you expect it to. If it
is, the problem is rather mysterious. If it isn't, it will just
be a matter of getting it to execute. Probably relatively
simple.
Let me know what you find either way.
no obvious problems left. However, you have, politely, not posted
all the code, so various declarations are not visible. It could
be some variable being automatic rather than instance or class,
or something like that. Anyway, the next step I would take, is
to add a console printing line to the output loop. After
prt.println(air[i][j]);
add
System.out.println(air[i][
and maybe before the two for loops add
System.out.println(count);
This may illuminate what it going on. At least it will verify
whether or not the loop is executing as you expect it to. If it
is, the problem is rather mysterious. If it isn't, it will just
be a matter of getting it to execute. Probably relatively
simple.
Let me know what you find either way.
ASKER
I got it all sorted
try {
file[0] = new File("C:/WINDOWS/Desktop/P roject2/pl ane0.txt") ;
fWriter[0] = new FileWriter(file[0]);
for (j=0; j<6; j++) {
fWriter[0].write(air[pCoun t][j]);
//****to space the files for reading in again !!!don't ask
fWriter[0].write(" ");
}
fWriter[0].close();
}
catch(IOException e){
}
try {
file[0] = new File("C:/WINDOWS/Desktop/P
fWriter[0] = new FileWriter(file[0]);
for (j=0; j<6; j++) {
fWriter[0].write(air[pCoun
//****to space the files for reading in again !!!don't ask
fWriter[0].write(" ");
}
fWriter[0].close();
}
catch(IOException e){
}
ASKER
//****deals with the buttons pressed****//
String str = ae.getActionCommand();
if(str.equals("Enter")) {
writeNums();
count++;
}
else if(str.equals("Reset")) {
resetit();
}
else if(str.equals("Show")) {
setVisible(false);
s.setVisible(true);
}
}
public void writeNums(){
try {
fos = new FileOutputStream("C:/WINDO
prt = new PrintWriter(fos);
}
catch(IOException e){
}
for (i=0; i<count; i++) {
for (j=0; j<14; j++) {
air[i][j] = String.valueOf(tf[j].getTe
prt.println(air[i][j]);
}
}
}
imladris i wish i hadn't started this...my first draft was a simple applet for web release the came along a lot of files...i can't really figure them out...your assumption were correct in what you have said above i guess because i do this all day i expect everyone to know what i'm on about.
What i really can't understand (lordy he wants more, sorry), is why the above doesn't work. I am increasing the count each time enter is pressed to a maximum of 3 times...then sending these values to my file yet the file is always empty??????
TA for your help