2014-10-30 60 views
1

我是新来的Java,但想学,而不是被娇生惯养,所以请记住这一点:)的Java SWT InterruptedException的

我与挥杆的工作做一个GUI用于发送使用质量信息适用于Skype的Java API。我已经想出了我的方法,并为大众信使和所有工作代码,现在我与摆动。我已经制作了几个按钮,并制定了G​​UI的前端,现在我需要实现我的方法。

这里是我到目前为止的代码:

private void createContents() 
    throws SkypeException, InterruptedException { 
    final Mass objCL = new Mass(); 
    objCL.skype(); 
    shell = new Shell(); 
    shell.setSize(450, 300); 
    shell.setText("Test"); 

    text = new Text(shell, SWT.BORDER); 
    text.setToolTipText("Your message to send"); 
    text.setBounds(121, 166, 249, 38); 

    Button btnSend = new Button(shell, SWT.NONE); 
    btnSend.addSelectionListener(new SelectionAdapter() { 
     public void widgetSelected(SelectionEvent e) { 
       objCL.skype(); 
       } 
    }); 
    btnSend.setBounds(203, 210, 83, 29); 
    btnSend.setText("SEND"); 

    Link link = new Link(shell, SWT.NONE); 
    link.setBounds(10, 250, 83, 15); 
    link.setText("<a>Our Website</a>"); 
} 

(Code标签留下了一个“}”不要担心,这是没有问题的)

现在我有错误的挥杆不会请允许我把

 public void widgetSelected(SelectionEvent e) *InterruptedException* { 
       objCL.skype(); 
       } 

Eclipse的输出误差

未处理的异常类型InterruptedException

任何想法家伙?

+0

FYI:您似乎没有使用Swing中,你似乎使用SWT – MadProgrammer 2014-10-30 04:17:55

+0

Java不允许你改变接口的声明方法如'widgetS选举'添加'抛出'。您必须处理方法中的异常。 – 2014-10-30 07:44:00

回答

0

objCL.skype();try-catch子句,它不是由外方法来处理的,因为它们具有彼此没有上下文关系(所述createContents方法将被调用时,退出该程序上widgetSelected被调用之前长时间移动) ...

try { 
    objCL.skype(); 
} catch (InterruptedException exp) { 
    exp.printStackTrace(); 
} 

参见Catching and Handling Exceptions的部分获取更多细节