Hi all,
I'm trying to add an export function to an applet, which dumps the contents of an output text field into a .txt file. It compiles properly, but no file gets written
Here's what I've done so far:
Code:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class cdDiscount extends Applet implements ActionListener {
Panel TopPanel = new Panel(), MiddlePanel = new Panel(), BottomPanel = new Panel();
TextField iCDs = new TextField("Enter number of CDs", 30);
Button iCalculate = new Button("Calculate"), iClear = new Button("Clear"), iExport = new Button("Export");
TextArea iResult = new TextArea(20, 30);
public void init() {
setSize(400, 400);
TopPanel.setLayout (new FlowLayout(FlowLayout.CENTER));
TopPanel.add(iCDs);
MiddlePanel.setLayout (new FlowLayout(FlowLayout.CENTER));
MiddlePanel.add(iCalculate);
MiddlePanel.add(iClear);
MiddlePanel.add(iExport);
BottomPanel.setLayout (new FlowLayout(FlowLayout.CENTER));
BottomPanel.add(iResult);
this.setLayout(new BorderLayout());
add(TopPanel,BorderLayout.NORTH);
add(MiddlePanel,BorderLayout.CENTER);
add(BottomPanel,BorderLayout.SOUTH);
iCalculate.addActionListener(this);
iExport.addActionListener(this);
iClear.addActionListener(this);
}
public void actionPerformed(ActionEvent f) {
if (f.getSource()== iCalculate) {
int iInput=Integer.parseInt(iCDs.getText());
iResult.append(iInput+" CDs = "+Integer.toString(process(Integer.parseInt(iCDs.getText())))+"% discount\n");
}
else if (f.getSource()== iExport) {
export(iResult.getText());
}
else
iResult.setText("");
}
public static int process(int iCDs) {
if(iCDs<=14) return 0;
else if(iCDs<50) return 1;
else if(iCDs<120) return 5;
else return 10;
}
public static void export(String iLog) {
try {
FileOutputStream iOStream = new FileOutputStream("export.txt");
new PrintStream(iOStream).println(iLog);
iOStream.close();
} catch (IOException k) {}
}
}
I've used the export() method with another class and it worked.. so am a bit stumped. I think it might be to do with exceptions.. but am probably wrong..
Any help or suggestions would be brilliant

Thanks