So in my CS class we made a simple program to sort a list of names then re-write the names into a new file. It was really easy and I finished pretty fast. But then I decided to make it GUI with awt so I added 1 button that does everything it did. But I'm getting this error and I don't know how to fix it
actionPerformed(java.awt.event.ActionEvent) in SortMe cannot implement actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener; overridden method does not throw java.io.IOException
public void actionPerformed(ActionEvent e) throws IOException
Will someone review my source file and tell me what exactly I'm doing wrong?
import java.io.*; import java.util.Arrays; import java.awt.*; import java.awt.event.*; public class SortMe extends Frame implements ActionListener { private static String names[]; private static int fileSize; private static int tick = 0; private Button b; private BufferedReader input; private BufferedWriter output; public SortMe() { super("Sorting Names"); Frame f = new Frame(); b = new Button("Sort!"); f.add(b); b.addActionListener(this); } //---------------------------------------------------------------------------- public void actionPerformed(ActionEvent e) { if (e.getSource() == b) { perform(); } } //----------------------------------------------------------------------------- public void perform() { names = new String[100]; readFile("Names1.txt"); displayArray(); sortArray(); displayArray(); writeFile("Names2.txt"); } //------------------------------------------------------------------------------- public static void main (String args[]) { SortMe app = new SortMe(); app.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); } //------------------------------------------------------------------------------- public void readFile(String fileName) { input = new BufferedReader(new FileReader(fileName)); int i = 0; String in = input.readLine(); while (in !=null) { names[i] = in; i++; tick++; in = input.readLine(); } input.close(); } //------------------------------------------------------------------------------- public static void displayArray() { for (int x =0; x <= names.length-1; x++) { if (names[x] != null) System.out.println(names[x]); } } //------------------------------------------------------------------------------- public static void sortArray() { int tempCount = 0; String temp = ""; for (int x = 1; x < tick; x++) for (int y = 0; y < tick-x; y++) { String s = names[y]; String s1 = names[y+1]; tempCount = 1; while (tempCount != 0) { if (s.equals(s1)) tempCount = 0; else if (s.charAt(tempCount-1) == s1.charAt(tempCount-1)) { tempCount++; } else { if (s.charAt(tempCount-1) > s1.charAt(tempCount-1)) { temp = names[y]; names[y] = names[y+1]; names[y+1]= temp; } tempCount = 0; } } } } //------------------------------------------------------------------------------- public void writeFile(String fileName) throws IOException { output = new BufferedWriter(new FileWriter(fileName)); for (int x = 0; x < tick; x++) if (names[x] != null) { output.write(names[x]); output.newLine(); } output.close(); } }