{"id":3426,"date":"2017-02-12T12:17:46","date_gmt":"2017-02-12T11:17:46","guid":{"rendered":"http:\/\/liceocuneo.it\/oddenino\/?p=3426"},"modified":"2017-02-12T12:22:13","modified_gmt":"2017-02-12T11:22:13","slug":"threadexample","status":"publish","type":"post","link":"https:\/\/liceocuneo.it\/oddenino\/threadexample\/","title":{"rendered":"ThreadExample"},"content":{"rendered":"<p><strong>JWait<\/strong><\/p>\n<pre>public class JWait extends JLabel implements Runnable {\r\n\r\n\tprivate final String MESSAGE = \"Wait, please\";\r\n\tprivate boolean running = false;\r\n\r\n\tpublic JWait() {\r\n\t\tthis.setText(MESSAGE);\r\n\t\tthis.setOpaque(true);\r\n\t\tthis.setBackground(Color.YELLOW);\r\n\t}\r\n\r\n\tpublic void start() {\r\n\t\tif (!running) {\r\n\t\t\trunning = true;\r\n\t\t\tThread t = new Thread(this);\r\n\t\t\tt.setDaemon(true);\r\n\t\t\tt.start();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void stop() {\r\n\t\trunning = false;\r\n\t}\r\n\r\n\tpublic void reset() {\r\n\t\tthis.setText(MESSAGE);\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void run() {\r\n\t\twhile (running) {\r\n\t\t\tthis.setText(this.getText() + \".\");\r\n\t\t\ttry {\r\n\t\t\t\tThread.sleep(1000);\r\n\t\t\t} catch (InterruptedException e) {\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n}<\/pre>\n<p>Progetto Eclipse:\u00a0<a href=\"https:\/\/liceocuneo.it\/oddenino\/wp-content\/uploads\/sites\/2\/ThreadExample.zip\">ThreadExample.zip<\/a><\/p>\n<p>Per la spiegazione teorica sui thread fare riferimento al testo: Java per Robot, pag. 121<br \/>\noppure alla pagina:\u00a0<a href=\"http:\/\/www.claudiodesio.com\/java\/tutorialjavathread\/threads.htm\" target=\"_blank\">http:\/\/www.claudiodesio.com\/java\/tutorialjavathread\/threads.htm<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>JWait public class JWait extends JLabel implements Runnable { private final String MESSAGE = &#8220;Wait, please&#8221;; private boolean running = false; public JWait() { this.setText(MESSAGE); this.setOpaque(true); this.setBackground(Color.YELLOW); } public void start() { if (!running) { running = true; Thread t = new Thread(this); t.setDaemon(true); t.start(); } } public void stop() { running = false; } &hellip; <a href=\"https:\/\/liceocuneo.it\/oddenino\/threadexample\/\" class=\"more-link\">Continua a leggere <span class=\"screen-reader-text\">ThreadExample<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-3426","post","type-post","status-publish","format-standard","hentry","category-informatica"],"_links":{"self":[{"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/posts\/3426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/comments?post=3426"}],"version-history":[{"count":0,"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/posts\/3426\/revisions"}],"wp:attachment":[{"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/media?parent=3426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/categories?post=3426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/tags?post=3426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}