首页 \ 问答 \ Netbeans平台中的多线程编程(Multithreaded programming in Netbeans Platform)

Netbeans平台中的多线程编程(Multithreaded programming in Netbeans Platform)

我查看了有关NBP的书籍/文档,但没有直接讨论NBP中的多线程编程。 NBP中的多线程有什么特别需要注意的吗? 所以,如果我想创建一个多线程的NBP应用程序,我只需要遵循常规的Java多线程编程实践,对吧?


I've looked through the books/docs about NBP, but there is nothing directly talks about multithreaded programming in NBP. Is there anything particular that needs attention regarding to multithreading in NBP? So, if I want to create a multithreaded NBP application, I just need to follow regular Java multithreaded programming practices, right?


原文:https://stackoverflow.com/questions/5075217
更新时间:2023-08-25 06:08

最满意答案

$(document).ready(function() {
    $('#questions input').on('change', function() {
      /* Answers array, if there are more questiones I would think about changing questionOne to question1
       * and build this array in a loop getting values by something like:
       *   userAnswers.push($('input[name=question'+ i +']:checked', '#questions).val());
       * or even group them under one class and query for .question:checked
       */
      var userAnswers = [
        $('input[name=questionOne]:checked', '#questions').val(),
        $('input[name=questionTwo]:checked', '#questions').val(),
        $('input[name=questionThree]:checked', '#questions').val()
      ];
      
      //Array that contains right answers, indexes must match userAnswers array.
      var rightAnswers = [2, 6, 8];
      
      //Check if all answers are defined
      for(var i = 0; i < userAnswers.length; i++){
        if(typeof userAnswers[i] === 'undefined'){
          return;
        }
      }
      
      //Check if all answers are rightAnswers
      for(var i = 0; i < userAnswers.length; i++){
        if(userAnswers[i] != rightAnswers[i]){
          return console.log('Found wrong answer!');
        }
      }
      
      console.log('All answers are correct.');
    });
});
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <title>repl.it</title>
        <link href="index.css" rel="stylesheet" type="text/css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    </head>
    <body>
      <form method="POST" id="questions">
        <div class="form-group" id="questionOne">
            <h3>Question 1</h3>
            <div class="radio">
                <input type="radio" name="questionOne" id="question1" class="radio" value="1" required/>
                <label for="question1">Option 1</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionOne" id="question2" class="radio" value="2"/>
                <label for="question2">Option 2 - Right answer</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionOne" id="question3" class="radio" value="3"/>
                <label for="question3">Option 3</label>
            </div>
        </div>
    
        <div class="form-group" id="questionTwo">
            <h3>Question 2</h3>
            <div class="radio">
                <input type="radio" name="questionTwo" id="question4" class="radio" value="4" required/>
                <label for="question4">Option 1</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionTwo" id="question5" class="radio" value="5"/>
                <label for="question5">Option 2</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionTwo" id="question6" class="radio" value="6"/>
                <label for="question6">Option 3 - Right answer</label>
            </div>
        </div>
    
        <div class="form-group" id="questionThree">
            <h3>Question 3</h3>
            <div class="radio">
                <input type="radio" name="questionThree" id="question7" class="radio" value="7" required/>
                <label for="question7">Option 1</label>
            </div>
            <div class="radio">
               <input type="radio" name="questionThree" id="question8" class="radio" value="8"/>
                <label for="question8">Option 2 - Right answer</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionThree" id="question9" class="radio" value="9"/>
                <label for="question9">Option 3</label>
            </div>
        </div>
    
        <div class="buttons">
            <a href="index.html" class="btn btn-default form_button_cancel">Avbryt</a>
            <button type="submit" class="btn btn-default form_button_next">Nästa</button>
        </div>
    </form>
    </body>
</html>

而对于重定向而不是打印'发现错误答案!' 或者'所有答案都是正确的!' 在控制台中,你会这样做:

  //Check if all answers are rightAnswers
  for(var i = 0; i < userAnswers.length; i++){
    if(userAnswers[i] != rightAnswers[i]){
      window.location.href = 'wrong.html';
      return; // End here, and do not execute further redirection.
    }
  }

  window.location.href = 'right.html';

return内部循环确保脚本将在那里结束函数执行,并且它不会执行'right.html'重定向。

这两个循环,用于检查是否定义了答案,以及它们是否正确可以合并为一个,但是有一些代码会注意到所有都已定义。

编辑:在下面的评论中回答你的问题,起初我以为我会将它绑定到按钮onclick事件,但是为了保持在这种情况下方便的验证(当一些问题没有得到回答时它注意到用户有关它)我认为form的onsubmit会更好。 我仍然会阻止默认行为,因此表单并未真正提交,但请记住,如果有人将js禁用,它将提交表单,请记住这一点。 所以,下一个按钮是提交类型,它将尝试提交表单,在onsubmit事件处理程序中我阻止表单子请求并检查答案。

$(document).ready(function() {
    $('#questions').on('submit', function(e) {
      e.preventDefault(); // Prevent form submition; 
      
      var userAnswers = [
        $('input[name=questionOne]:checked', '#questions').val(),
        $('input[name=questionTwo]:checked', '#questions').val(),
        $('input[name=questionThree]:checked', '#questions').val()
      ];
      
      //Array that contains right answers, indexes must match userAnswers array.
      var rightAnswers = [2, 6, 8];
      
      //Check if all answers are defined
      for(var i = 0; i < userAnswers.length; i++){
        if(typeof userAnswers[i] === 'undefined'){
          return;
        }
      }
      
      //Check if all answers are rightAnswers
      for(var i = 0; i < userAnswers.length; i++){
        if(userAnswers[i] != rightAnswers[i]){
          return console.log('Found wrong answer!');
        }
      }
      
      console.log('All answers are correct.');
    });
});
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <title>repl.it</title>
        <link href="index.css" rel="stylesheet" type="text/css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    </head>
    <body>
      <form method="POST" id="questions">
        <div class="form-group" id="questionOne">
            <h3>Question 1</h3>
            <div class="radio">
                <input type="radio" name="questionOne" id="question1" class="radio" value="1" required/>
                <label for="question1">Option 1</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionOne" id="question2" class="radio" value="2"/>
                <label for="question2">Option 2 - Right answer</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionOne" id="question3" class="radio" value="3"/>
                <label for="question3">Option 3</label>
            </div>
        </div>
    
        <div class="form-group" id="questionTwo">
            <h3>Question 2</h3>
            <div class="radio">
                <input type="radio" name="questionTwo" id="question4" class="radio" value="4" required/>
                <label for="question4">Option 1</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionTwo" id="question5" class="radio" value="5"/>
                <label for="question5">Option 2</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionTwo" id="question6" class="radio" value="6"/>
                <label for="question6">Option 3 - Right answer</label>
            </div>
        </div>
    
        <div class="form-group" id="questionThree">
            <h3>Question 3</h3>
            <div class="radio">
                <input type="radio" name="questionThree" id="question7" class="radio" value="7" required/>
                <label for="question7">Option 1</label>
            </div>
            <div class="radio">
               <input type="radio" name="questionThree" id="question8" class="radio" value="8"/>
                <label for="question8">Option 2 - Right answer</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionThree" id="question9" class="radio" value="9"/>
                <label for="question9">Option 3</label>
            </div>
        </div>
    
        <div class="buttons">
            <a href="index.html" class="btn btn-default form_button_cancel">Avbryt</a>
            <button type="submit" class="btn btn-default form_button_next">Nästa</button>
        </div>
    </form>
    </body>
</html>


$(document).ready(function() {
    $('#questions input').on('change', function() {
      /* Answers array, if there are more questiones I would think about changing questionOne to question1
       * and build this array in a loop getting values by something like:
       *   userAnswers.push($('input[name=question'+ i +']:checked', '#questions).val());
       * or even group them under one class and query for .question:checked
       */
      var userAnswers = [
        $('input[name=questionOne]:checked', '#questions').val(),
        $('input[name=questionTwo]:checked', '#questions').val(),
        $('input[name=questionThree]:checked', '#questions').val()
      ];
      
      //Array that contains right answers, indexes must match userAnswers array.
      var rightAnswers = [2, 6, 8];
      
      //Check if all answers are defined
      for(var i = 0; i < userAnswers.length; i++){
        if(typeof userAnswers[i] === 'undefined'){
          return;
        }
      }
      
      //Check if all answers are rightAnswers
      for(var i = 0; i < userAnswers.length; i++){
        if(userAnswers[i] != rightAnswers[i]){
          return console.log('Found wrong answer!');
        }
      }
      
      console.log('All answers are correct.');
    });
});
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <title>repl.it</title>
        <link href="index.css" rel="stylesheet" type="text/css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    </head>
    <body>
      <form method="POST" id="questions">
        <div class="form-group" id="questionOne">
            <h3>Question 1</h3>
            <div class="radio">
                <input type="radio" name="questionOne" id="question1" class="radio" value="1" required/>
                <label for="question1">Option 1</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionOne" id="question2" class="radio" value="2"/>
                <label for="question2">Option 2 - Right answer</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionOne" id="question3" class="radio" value="3"/>
                <label for="question3">Option 3</label>
            </div>
        </div>
    
        <div class="form-group" id="questionTwo">
            <h3>Question 2</h3>
            <div class="radio">
                <input type="radio" name="questionTwo" id="question4" class="radio" value="4" required/>
                <label for="question4">Option 1</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionTwo" id="question5" class="radio" value="5"/>
                <label for="question5">Option 2</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionTwo" id="question6" class="radio" value="6"/>
                <label for="question6">Option 3 - Right answer</label>
            </div>
        </div>
    
        <div class="form-group" id="questionThree">
            <h3>Question 3</h3>
            <div class="radio">
                <input type="radio" name="questionThree" id="question7" class="radio" value="7" required/>
                <label for="question7">Option 1</label>
            </div>
            <div class="radio">
               <input type="radio" name="questionThree" id="question8" class="radio" value="8"/>
                <label for="question8">Option 2 - Right answer</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionThree" id="question9" class="radio" value="9"/>
                <label for="question9">Option 3</label>
            </div>
        </div>
    
        <div class="buttons">
            <a href="index.html" class="btn btn-default form_button_cancel">Avbryt</a>
            <button type="submit" class="btn btn-default form_button_next">Nästa</button>
        </div>
    </form>
    </body>
</html>

And for redirect instead of printing 'Found wrong answer!' or 'All answers are correct!' in console, you would do:

  //Check if all answers are rightAnswers
  for(var i = 0; i < userAnswers.length; i++){
    if(userAnswers[i] != rightAnswers[i]){
      window.location.href = 'wrong.html';
      return; // End here, and do not execute further redirection.
    }
  }

  window.location.href = 'right.html';

That return inside loop makes sure that script will end function execution there, and it will not execute 'right.html' redirection.

These two loops, to check if answers are defined, and if they're correct could be merged into one, but with some more code that will note that all were defined.

Edit: To answer your question in comment bellow, at first I thought I will bind it to button onclick event, but to keep validation that is handy in this case (when some questions aren't answered it notices the user about it) I think form's onsubmit will be better. I still prevent the default behavior so the form isn't really submitted, but keep in mind if someone will have js disabled, it will submit the form so keep that in mind. So, the next button is submit type, and it will attempt to submit form, in onsubmit event handler I prevent form submition and I check answers.

$(document).ready(function() {
    $('#questions').on('submit', function(e) {
      e.preventDefault(); // Prevent form submition; 
      
      var userAnswers = [
        $('input[name=questionOne]:checked', '#questions').val(),
        $('input[name=questionTwo]:checked', '#questions').val(),
        $('input[name=questionThree]:checked', '#questions').val()
      ];
      
      //Array that contains right answers, indexes must match userAnswers array.
      var rightAnswers = [2, 6, 8];
      
      //Check if all answers are defined
      for(var i = 0; i < userAnswers.length; i++){
        if(typeof userAnswers[i] === 'undefined'){
          return;
        }
      }
      
      //Check if all answers are rightAnswers
      for(var i = 0; i < userAnswers.length; i++){
        if(userAnswers[i] != rightAnswers[i]){
          return console.log('Found wrong answer!');
        }
      }
      
      console.log('All answers are correct.');
    });
});
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <title>repl.it</title>
        <link href="index.css" rel="stylesheet" type="text/css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    </head>
    <body>
      <form method="POST" id="questions">
        <div class="form-group" id="questionOne">
            <h3>Question 1</h3>
            <div class="radio">
                <input type="radio" name="questionOne" id="question1" class="radio" value="1" required/>
                <label for="question1">Option 1</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionOne" id="question2" class="radio" value="2"/>
                <label for="question2">Option 2 - Right answer</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionOne" id="question3" class="radio" value="3"/>
                <label for="question3">Option 3</label>
            </div>
        </div>
    
        <div class="form-group" id="questionTwo">
            <h3>Question 2</h3>
            <div class="radio">
                <input type="radio" name="questionTwo" id="question4" class="radio" value="4" required/>
                <label for="question4">Option 1</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionTwo" id="question5" class="radio" value="5"/>
                <label for="question5">Option 2</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionTwo" id="question6" class="radio" value="6"/>
                <label for="question6">Option 3 - Right answer</label>
            </div>
        </div>
    
        <div class="form-group" id="questionThree">
            <h3>Question 3</h3>
            <div class="radio">
                <input type="radio" name="questionThree" id="question7" class="radio" value="7" required/>
                <label for="question7">Option 1</label>
            </div>
            <div class="radio">
               <input type="radio" name="questionThree" id="question8" class="radio" value="8"/>
                <label for="question8">Option 2 - Right answer</label>
            </div>
            <div class="radio">
                <input type="radio" name="questionThree" id="question9" class="radio" value="9"/>
                <label for="question9">Option 3</label>
            </div>
        </div>
    
        <div class="buttons">
            <a href="index.html" class="btn btn-default form_button_cancel">Avbryt</a>
            <button type="submit" class="btn btn-default form_button_next">Nästa</button>
        </div>
    </form>
    </body>
</html>

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。