2014-10-30 32 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的部分獲取更多細節