public FileWindow(JMenuItem menuItem,final JTextArea text, JMenuItem save){
//Open
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
openFile();
if(fileToOpen == JFileChooser.APPROVE_OPTION){
text.setText("");
try{
Scanner scan = new Scanner(new FileReader(Open.getSelectedFile().getPath()));
while(scan.hasNext()){
text.append(scan.nextLine() + "\n");
}
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
});
//Save
save.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
saveFile();
if(fileToSave == JFileChooser.APPROVE_OPTION){
try{
BufferedWriter out = new BufferedWriter(new FileWriter(Save.getSelectedFile().getPath() + ".txt"));
out.write(text.getText());
out.flush();
out.close();
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
});
}
I'm getting an error on this line --> "menuItem.addActionListener(new ActionListener){" I tried initiating the variables but that didn't work. Any help would be very appreciated!