package puzzle.puzzleClasses; import java.awt.FileDialog; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FilenameFilter; // Listener for the file button final class fileActionListener implements ActionListener { static public final int JEN = 0; static public final int ANM = 1; public int typeint; private String type; String selected; // file that the user selects repaintLabel label; // the gui label that says which file was selected AppletPuzzle j ; public fileActionListener (repaintLabel l, int t,AppletPuzzle jj) { label = l; j=jj; typeint = t; if (t == JEN) type = "jpg"; else type = "gif"; } public void actionPerformed(ActionEvent e) { Frame temp = new Frame("File Name"); FileDialog fd = new FileDialog(temp); // Set the filedialog to only accept .jen files- BUG! This does not work on Unix FilenameFilter file_filter; if (typeint == JEN) file_filter = new jenFilter(); else file_filter = new anmFilter(); fd.setFilenameFilter(file_filter); String url = null; String url_string = j.getDocumentBase().toString(); int last = url_string.lastIndexOf('/'); // so it works with appletviewer or as an application url = new String(url_string.substring(5, last + 1) +type +"/"); fd.setDirectory(url); // Show the file dialog box fd.setVisible(true); String name = fd.getFile(); if (name != null) { if (name.endsWith("." +type)) { String dir = fd.getDirectory(); selected = dir.concat(name); for(int i=0;i