2017-10-11 12 views
-2
public class MesssageBoxQuestionIconYESNOButton { 

public static void main(String[] args) { 
    Display display = new Display(); 
    Shell shell = new Shell(display); 

    //This is added to be able to run JUnit in this java class 
    JUnitCore junit = new JUnitCore(); 
    Result result; 

    int style = SWT.ICON_WARNING | SWT.YES | SWT.NO; 


    MessageBox messageBox = new MessageBox(shell, style); 
    messageBox.setMessage("Would you like to start the test?"); 
    int rc = messageBox.open(); 

    if(rc == SWT.YES) 
    { 
      //Must add in the .class else it will not work 
      result = junit.run(testMyCode.class); 

     //This part is to ask if the user want to repeat the test again 
      Display display1 = new Display(); 
      Shell shell1 = new Shell(display); 

      int style1 = SWT.ICON_WARNING | SWT.YES | SWT.NO; 

      MessageBox messageBox1 = new MessageBox(shell, style); 
      messageBox1.setMessage("Would you like to repeat the test?"); 
      int rc1 = messageBox.open(); 

      if(rc1 == SWT.YES) 
      { 
       result = junit.run(testMyCode.class); 
      } 
      else 
      { 
       MessageBox messageBox2 = new MessageBox(shell, style); 
       messageBox2.setMessage("Thank You For Using"); 
       display1.dispose(); 
      } 
    } 
    else 
    { 
     display.dispose(); 
    } 
} 
} 

これは現在持っているコードです。 だから、これは私が何をしたいです:彼らはテスト ネストされたSWTメッセージボックスにエラーが表示される

  • を開始したい場合は

    1. はイエス場合は、完成しJUnitテストの後JUnitテスト
    2. を実行するユーザーを確認して下さい。テストを再試行するかどうかをユーザに聞きます。

    このコードでは、すべてが3番目のステップまでうまくいきます。

    これは私が受け取ったエラーです:

    Exception in thread "main" org.eclipse.swt.SWTException: Invalid thread access 
    at org.eclipse.swt.SWT.error(Unknown Source) 
    at org.eclipse.swt.SWT.error(Unknown Source) 
    at org.eclipse.swt.SWT.error(Unknown Source) 
    at org.eclipse.swt.widgets.Display.checkDisplay(Unknown Source) 
    at org.eclipse.swt.widgets.Display.create(Unknown Source) 
    at org.eclipse.swt.graphics.Device.<init>(Unknown Source) 
    at org.eclipse.swt.widgets.Display.<init>(Unknown Source) 
    at org.eclipse.swt.widgets.Display.<init>(Unknown Source) 
    

    誰が間違っているかを見るために私を助けることができますか?ありがとう

    エラーが
    は、私はあまりにも、いくつかの変更を加え、新たなDisplay ...作成によって引き起こされるので、このような何かしようとした
  • +1

    1つの「ディスプレイ」 –

    +0

    を作成する必要があります。 –

    +1

    通常のSWTアプリケーションでは、すべてに使用される単一の 'Display'オブジェクトしか作成されません。同じスレッド上に2番目の表示オブジェクトを作成することは決してできず、一部のプラットフォーム(たとえばmacOS)では、2番目の表示オブジェクトをまったく作成することはできません。 –

    答えて

    0

    (ところで、使用されていませんでした。):

    public static void main(final String[] args) 
    { 
        final Display display = new Display(); 
        final Shell shell = new Shell(display); 
    
        // This is added to be able to run JUnit in this java class 
        final JUnitCore junit = new JUnitCore(); 
        Result result; 
    
        final int style = SWT.ICON_WARNING | SWT.YES | SWT.NO; 
    
        final MessageBox messageBox = new MessageBox(shell, style); 
        messageBox.setMessage("Would you like to start the test?"); 
        int rc = messageBox.open(); 
    
        if (rc == SWT.YES) 
        { 
         // Must add in the .class else it will not work 
         result = junit.run(testMyCode.class); 
    
         // This part is to ask if the user want to repeat the test again 
         final MessageBox messageBox1 = new MessageBox(shell, style); 
         messageBox1.setMessage("Would you like to repeat the test?"); 
         rc = messageBox1.open(); 
    
         if (rc == SWT.YES) 
         { 
          result = junit.run(testMyCode.class); 
         } 
         int style1 = SWT.ICON_WARNING | SWT.OK; 
         final MessageBox messageBox2 = new MessageBox(shell, style1); 
         messageBox2.setMessage("Thank You For Using"); 
         messageBox2.open(); 
        } 
        display.dispose(); 
    } 
    
    +0

    私はちょうど試しましたが、うまくいかないようです。最初のメッセージボックスのみが表示され、2番目のメッセージボックスは表示されませんでした。 –

    +0

    Oops、typoが修正されました... –

    +0

    同じこと、まだ2番目のメッセージボックスが表示されていません –

    0
    public static void main(final String[] args) 
    { 
        final Display display = new Display(); 
        final Shell shell = new Shell(display); 
    
        // This is added to be able to run JUnit in this java class 
        final JUnitCore junit = new JUnitCore(); 
        Result result; 
    
        final int style = SWT.ICON_WARNING | SWT.YES | SWT.NO; 
    
        final MessageBox messageBox = new MessageBox(shell, style); 
        messageBox.setMessage("Would you like to start the test?"); 
        int rc = messageBox.open(); 
    
        if (rc == SWT.YES) 
        { 
         // Must add in the .class else it will not work 
         result = junit.run(testMyCode.class); 
    
         // This part is to ask if the user want to repeat the test again 
         final MessageBox messageBox1 = new MessageBox(shell, style); 
         messageBox1.setMessage("Would you like to repeat the test?"); 
         int rc2 = messageBox1.open(); 
    
         if (rc2 == SWT.YES) 
         { 
          result = junit.run(testMyCode.class); 
         } 
         else 
         { 
         int style1 = SWT.ICON_WARNING | SWT.OK; 
         final MessageBox messageBox2 = new MessageBox(shell, style1); 
         messageBox2.setMessage("Thank You For Using"); 
         messageBox2.open(); 
         } 
        } 
        display.dispose(); 
    } 
    

    rcも変更する必要があります

    +0

    いいえ、あなたは... –

    +0

    しかし、それはrc2に2番目の部分を変更した後で動作します。それ以外の場合、2番目のメッセージボックスは表示されません。 –

    関連する問題