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
最满意答案
$(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'sonsubmit
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, inonsubmit
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>
相关问答
更多-
默认情况下, :checked选择器应匹配任何已检查的元素,因此您可能只需检查检查了多少元素: // Check if any elements are checked if ($('input[name^="answer"]:checked').length > 0){ // At least one question is answered } else { // No questions are answered } 如果要查看是否已选中所有单个组,只需将组总数与已检查组的数量(或 ...
-
单击相应的标签后,IE - 隐藏的单选按钮不被检查(IE - hidden radio button not checked when the corresponding label is clicked)[2022-03-02]
它可能与display: none - 您可能还会发现,隐藏的元素不会随其他表单一起提交其值。 如果您有控制权,您可能需要尝试将屏幕上的元素放置, 而不是隐藏它们 。 It probably is to do with the display: none - you may also find that hidden elements don't get their values submitted with the rest of the form. If you have control over it ... -
jQuery UI单选按钮 - 如何正确切换检查状态(jQuery UI radio button - how to correctly switch checked state)[2023-08-02]
更改基础状态后,需要调用refresh方法: 刷新按钮的视觉状态。 在本地元素的选中或禁用状态被程序更改之后,用于更新按钮状态。 工作示例: http : //jsbin.com/udowo3 function setRadio(id) { var radio = $('#' + id); radio[0].checked = true; radio.button("refresh"); } 它使用无线电的ID,但只要您获得包含相关input[type=radio]元素的jQuer ... -
if ( ! $("input").is(':checked') ) 不行吗 你也可以尝试迭代这样的元素: var iz_checked = true; $('input').each(function(){ iz_checked = iz_checked && $(this).is(':checked'); }); if ( ! iz_checked ) if ( ! $("input").is(':checked') ) Doesn't work? You might also try it ...
-
您可以将带有['value=yes]的元素长度与带有['value=yes]和属性的元素进行比较:checked : if($('[value=yes]').length==$('[value=yes]:checked').length){ //all yes elements are checked } You can rather compare the length of elements with ['value=yes] with elements with ['value=yes ...
-
你可以试试这个: function testRadios() { var r = document.getElementsByTagName("input"); for (var i=0; i < r.length; i++) { if ( (r[i].type == "radio") && (r[i].value == "false") && (r[i].checked != "checked")) { ...
-
这与添加属性和点击无关,它是附加代码,特别是这一行: if (myParent.data('val') == $(this).val() ){ 如果你之前点击了这个,那么就把它关掉。 但是 ,您没有告诉代码您已经(几乎)“点击”了它。 您可以通过将初始值添加到'myParent'来实现此目的,一种方法是将其添加到html:更新小提琴: https : //jsfiddle.net/8jh2k8u8/4/ 另一种方法是通过查找所选的无线电( :checked )来通 ...
如何知道检查哪些单选按钮并正确重定向(How to know which radio buttons are checked and redirect them correctly)[2022-04-03]
$(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 somet ...根据你提供的代码很难知道,但我猜测item.Prop是undefined 。 如果您向我们提供更多的代码,小提琴或撬棍,我们可能会提供更多帮助。 演示您正在体验的行为的示例小提琴: http : //jsfiddle.net/HB7LU/20982/ 示例小提琴的复选框工作,如你所愿: http : //jsfiddle.net/HB7LU/20983/ I have found the solution: The problem was that checkboxes are created for ea ...如何检查单选按钮(How do I make my radio buttons checked)[2022-02-03]
checked您要查找的正确HTML属性。 请注意其他答案: readonly不是必需的,OP也不是要求的。 因为你是用PHP做的,所以假设你传递的是HTML标记name foobar ,如下所示: 要确保即使在提交后仍保留该值,您也可以添加这样的代码(根据您的目的get或post ):相关文章
更多- 关于netbeans和mysql的问题
- Aspect-Oriented Programming
- 10 Programming Languages You Should Learn Right Now
- Object Oriented Programming
- 关于netbeans使用GWT框架失效或点击不显示的问题,最后导致生成失败
- 《实用C语言编程(第三版)》(Practical C Programming, Third Edition)扫描版[PDF]
- 《C++程序设计语言 特别版 十周年纪念版》(The C++ Programming Language Special Edition)扫描版[PDF]
- [转]Top 20 Programming Lessons I've Learned in 20 Years
- Java 多线程编程
- 求推荐JAVA 多线程编程书籍
最新问答
更多- 获取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的基本操作命令。。。