Skip to content
← Back to Community
FileWriter to write variable to file inside of actionListener
Profile icon
L0k3d20uz4

This program is supposed to take an order from the user, and then print out the receipt. The receipt should also be saved to a file. However, I keep getting errors saying that it can't find the symbol of my object, or that I haven't used a try catch. Can someone please tell me what I'm doing wrong?

Voters
Profile icon
L0k3d20uz4
Comments
hotnewtop
Profile icon
ParthaSarathi6

import java.awt.;
import java.awt.event.
;
class Main extends Frame implements ActionListener {
TextField t;
Main() {
super("Event Handling - ActionEvent");
t = new TextField();
t.setSize(30,30);
t.setBackground(Color.green);
t.setForeground(Color.red);
Button b = new Button("click Me");
b.addActionListener(this);
setSize(300,250);
setLayout(new GridLayout(2,1));
add(t); add(b);
setVisible(true);
}
public void actionPerformed (ActionEvent ae) {
t.setText("Keep Learning");

} public static void main(String args[])

{
new Main();
}
}