Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Exception 无法在ActionListener中实现actionPerformed(ActionEvent)_Exception_Methods_Jbutton_Outputstream_Jgrasp - Fatal编程技术网

Exception 无法在ActionListener中实现actionPerformed(ActionEvent)

Exception 无法在ActionListener中实现actionPerformed(ActionEvent),exception,methods,jbutton,outputstream,jgrasp,Exception,Methods,Jbutton,Outputstream,Jgrasp,我正在用2个密码做一个配置文件加密程序。我想有一个图形用户界面的按钮加密,解密和退出 我的问题是actionPerformed方法。它需要抛出outputStream抛出的异常。这是我在尝试编译时遇到的错误: :53: error: actionPerformed(ActionEvent) in ProfileEncryption_2 cannot implement actionPerformed(ActionEvent) in ActionListener public void actio

我正在用2个密码做一个配置文件加密程序。我想有一个图形用户界面的按钮加密,解密和退出

我的问题是actionPerformed方法。它需要抛出outputStream抛出的异常。这是我在尝试编译时遇到的错误:

: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
我想到了多种解决方案,但不确定如何正确实施它们。我可以捕获异常并对其进行处理,但我不确定如何以及如何处理。我还可以检查文件是否存在,如果存在,则输出,但我尝试的方法也不起作用

   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();
   }
public void actionPerformed(ActionEvent e)在单击按钮时引发异常//错误
{
如果(例如getSource()==encrBtn)
{
menu.setVisible(false);
createProfile();
menu.setVisible(true);
}
其他的
{
如果(如getSource()==decrBtn)
{
menu.setVisible(false);
viewProfile();
menu.setVisible(true);
}
其他的
{
如果(例如getSource()==exitBtn)
{
showMessageDialog(null,“再见!”);
系统出口(0);
}
}
}
}
//菜单结束
//开始创建/查看部分
公共静态void createProfile()引发异常//创建配置文件
{
字符串username=JOptionPane.showInputDialog(“输入您的用户名”);
字符串密码,confirmPass,strengcrtype;
int INTENTCRTYPE=0,unlock=0;
做
{
password=JOptionPane.showInputDialog(“输入密码。\n密码长度必须超过7个字符”);
confirmPass=JOptionPane.showInputDialog(“确认密码”);
if(password.equals(confirmPass)和&(password.length()>=7))
{
showMessageDialog(null,“密码匹配!”);
解锁=1;
}
其他的
{
如果(!password.equals(confirmPass))
showMessageDialog(null,“密码不匹配!”);
if(password.length()<7)
showMessageDialog(null,“密码不够长!”);
}
}
而(解锁==0);
做
{
strEncrType=JOptionPane.showInputDialog(“选择您喜欢的加密类型:\n1.Vigenère\n2.Erénegiv mod 4”);
如果(!strengrType.equals(“1”)和&!strengrType.equals(“2”))
showMessageDialog(null,“无效响应,请重试”);
}
而(!strengrType.equals(“1”)和&!strengrType.equals(“2”);
intEncrType=Integer.parseInt(strengrType);
String name=JOptionPane.showInputDialog(“输入您的真实姓名”);
String phone=JOptionPane.showInputDialog(“输入您的电话号码”);
String email=JOptionPane.showInputDialog(“输入您的电子邮件”);
String other=JOptionPane.showInputDialog(“输入要存储的注释/额外数据”);
字符串数据=密码+“-”+用户名+“-测试仪-”+姓名+“-”+电话+“-”+电子邮件+“-”+其他+“-”+强度类型;
if(intEncrType==1)
数据=加密1(数据);
其他的
数据=加密2(数据);
数据=数据+强度类型;
OutputStream输出=新文件OutputStream(用户名+“.txt”);
字节缓冲区[]=data.getBytes();
输出。写入(缓冲区);
output.close();
}

捕获并作为
运行时异常重新播放
,或者直接处理它。我不知道该怎么做,请您详细说明一下。我找到了一个解决方案,正在研究另一种处理方法。