kann actionPerformed (ActionEvent) nicht in ActionListener implementieren

Ich mache ein Profilverschlüsselungsprogramm mit 2 Chiffren. Ich möchte eine GUI mit Schaltflächen zum Verschlüsseln, Entschlüsseln und Beenden haben.

Mein Problem ist mit der actionPerformed-Methode. Es muss die Ausnahme auslösen, die der outputStream auslöst. Dies ist der Fehler, den ich erhalte, wenn ich versuche, ihn auszuführen:

:53: error: actionPerformed(ActionEvent) in ProfileEncryption_2 cannot implement actionPerformed(ActionEvent) in ActionListener
public void actionPerformed (ActionEvent e) throws FileNotFoundException//When a button is clicked

Ich habe zwar mehrere Lösungen, bin mir aber nicht sicher, wie ich sie richtig implementieren soll. Ich könnte die Ausnahme abfangen und etwas damit anfangen, aber ich bin nicht sicher, wie und was. Ich könnte auch prüfen, ob die Datei vorhanden ist, und wenn ja, dann ausgeben, aber was ich dafür versucht habe, hat auch nicht funktioniert.

   public void actionPerformed (ActionEvent e) throws Exception //When a button is clicked
   {
      if (e.getSource() == encrBtn)
      {
            menu.setVisible(false);
         createProfile();
         menu.setVisible(true);
      }
      else
      {
         if (e.getSource() == decrBtn)
         {
            menu.setVisible(false);
            viewProfile();
            menu.setVisible(true);
         }
         else
         {
            if (e.getSource() == exitBtn)
            {
               JOptionPane.showMessageDialog(null, "Goodbye!");
                    System.exit(0);
            }
         }
      }
   }

    //End of menu
    //Start of create/view section

   public static void createProfile() throws Exception //Create profile
   {
      String username = JOptionPane.showInputDialog("Enter your username.");
      String password, confirmPass, strEncrType;
      int intEncrType = 0, unlock = 0;
      do
      {
         password = JOptionPane.showInputDialog("Enter your password.\nIt must be more than 7 characters long.");
         confirmPass = JOptionPane.showInputDialog("Confirm password");
         if (password.equals(confirmPass) && (password.length() >= 7)) 
         {
            JOptionPane.showMessageDialog(null, "Passwords match!");
            unlock = 1;
         }
         else
         {
            if (!password.equals(confirmPass))
               JOptionPane.showMessageDialog(null, "Passwords do not match!");
            if (password.length() < 7)
               JOptionPane.showMessageDialog(null, "Password is not long enough!");
         }
      }
      while (unlock==0);
      do
      {
         strEncrType = JOptionPane.showInputDialog("Choose which encryption type you would prefer:\n1. Vigenère\n2. Erénegiv mod 4");
         if(!strEncrType.equals("1")&&!strEncrType.equals("2"))
            JOptionPane.showMessageDialog(null, "Invalid response, try again.");
      }
      while (!strEncrType.equals("1")&&!strEncrType.equals("2"));
      intEncrType = Integer.parseInt(strEncrType);
      String name = JOptionPane.showInputDialog("Enter your real name.");
      String phone = JOptionPane.showInputDialog("Enter your phone number.");
      String email = JOptionPane.showInputDialog("Enter your email.");
      String other = JOptionPane.showInputDialog("Enter notes/extra data you want stored.");
      String data = password + "-" + username + "-tester-" + name + "-" + phone + "-" + email + "-" + other + "-" + strEncrType;
      if (intEncrType ==1)
         data = encrypt1(data);
      else
         data = encrypt2(data);
      data = data + strEncrType;

        OutputStream output = new FileOutputStream(username + ".txt");
      byte buffer[] = data.getBytes();
      output.write(buffer);
      output.close();
   }

Antworten auf die Frage(0)

Ihre Antwort auf die Frage