AddUse是向表添加用户
JMenu fileoperation=new JMenu("操作");
JMenuItem fileadd=new JMenuItem("添加");
fileoperation.add(fileadd);
bar.add(fileoperation);fileadd.addActionListener(this);//事件处理
public void actionPerformed(ActionEvent ae) throws Exception
{
String arg=(String)ae.getActionCommand();
if(arg.equals("添加"))
{
int re=AddUse(text1.getText(),text2.getText(),text3.getText(),text4.getText(),text5.getText());
}
}提示:main 中的 actionPerformed(java.awt.event.ActionEvent) 无法实现 java.awt.event.ActionListener 中的 actionPerformed(java.awt.event.ActionEvent);被覆盖的方法不抛出 java.lang.Exception
        public void actionPerformed(ActionEvent ae) throws Exception如果不添加 throws Exception,又提示:未报告的异常 java.lang.Exception;必须对其进行捕捉或声明以便抛出int re=AddUse(text1.getText(),text2.getText(),text3.getText(),text4.getText(),text5.getText());请指点一下,谢谢

解决方案 »

  1.   

    我下面这个就没throws Exception,像沙发说的加try...catch...就好了.
    //////////////////////////////////////////////////////////////////public void actionPerformed(ActionEvent e) {
                 if (e.getSource() == jme) {
    JOptionPane.showMessageDialog(panel, "" + "请在第一个文本框输入网址"
    + " \n(如:www.163.com)" + "\n如该处为空则ping本机IP"
    + "\n                                         2006-11-30");// 实现“关于”按钮 }
                 if(e.getSource() == button){
                    if(tf1.getText() == null || "".equals(tf1.getText())){
                         try{
                          ia = InetAddress.getLocalHost();
                          s2 = ia.toString().substring(16, 31);
                          
                            loger = Logger.getLogger("testLogger");
                    
                       loger.info("localhost/"+s2);
                       loger.info("-------------------------");
                    
                          tf2.setText(s2);
                          }
                          catch(Exception e1){
                           System.out.println(e1.getMessage());
                          }
                    }else{
                          try{
                          ia = InetAddress.getByName(tf1.getText());
                          
                          loger = Logger.getLogger("testLogger");
                  
                     loger.info(ia);
                     loger.info("-------------------------");
                    
                          tf2.setText(ia.toString());
                          }
                          catch(Exception e2){
                           System.out.println(e2.getMessage());
                          }
                    }
                 }
           }
      

  2.   

    这段代码有可能出现异常,java为了安全起见,要你把这段代码放入到
    try
    {
    }catch()
    {
    }
    语句中,这样如果有错误的话,就会根据catch中的设置打印出什么地方出错了