<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6022595936443891655</id><updated>2024-10-06T22:15:04.148-07:00</updated><category term="java"/><category term="java poo"/><category term="Programación"/><category term="poo"/><category term="Principiantes java"/><category term="eclipse ide"/><category term="Java magazine"/><category term="GUI SWING"/><category term="Greenfoot"/><category term="Java SWING"/><category term="Juegos"/><category term="Juegos en java"/><category term="Video juegos"/><category term="aprender java creando un juego"/><category term="Entradas y Salidas"/><category term="GUI Java"/><category term="I/O"/><category term="Java Greenfoot"/><category term="Video juegos Greenfoot"/><category term="Como crear una GUI en Java"/><category term="Crear GUI en Java"/><category term="JOptionPane"/><category term="ejemplos GUI en Java"/><category term="E/S"/><category term="Eclipse IDE GUI"/><category term="I/O E/S"/><category term="Java IO"/><category term="Mensajes GUI Java"/><category term="Mensajes JOptionPane"/><category term="Mensajes Sencillos GUI Java"/><category term="Archivo de texto en java"/><category term="Crear GUI Java"/><category term="Java NIO"/><category term="Java NIO.2"/><category term="LF Java SWING"/><category term="Leer archivo de texto"/><category term="NIO"/><category term="NIO.2"/><category term="SQL y Java"/><category term="sql"/><category term="sqlite"/><category term="Captura JOptionPane"/><category term="Captura Java"/><category term="Como leer entrada de usuario con dialogo en Java"/><category term="Como mostrar un dialogo de mensaje en Java"/><category term="Como usar Look and Feel en Java"/><category term="Consola"/><category term="Consola Java"/><category term="Crear una clase Java Eclipse IDE"/><category term="Cómo mostrar un dialogo de pregunta en java"/><category term="Dialog Timer"/><category term="Dialogo Temporizado"/><category term="Dialogo Timer"/><category term="Dialogo de captura en Java"/><category term="JDialog con tiempo"/><category term="Java y Eclipse"/><category term="LF en Java"/><category term="Look And Feel SWING"/><category term="POSIX"/><category term="Permisos POSIX"/><category term="SQL 92"/><category term="SQLITE y Java"/><category term="Utilizar SQLITE y Java"/><category term="bienvenida"/><category term="calculadora JOptionPane"/><category term="calculadora java"/><category term="calculadora java dialogos"/><category term="como hacer calculadora"/><category term="como hacer calculadora java"/><category term="instalar libreria"/><title type='text'>El Blog De Baro</title><subtitle type='html'>Aprende Java sin complicaciones.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>24</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-2251451720317499641</id><published>2019-09-25T12:08:00.000-07:00</published><updated>2019-09-25T12:08:01.189-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="calculadora java"/><category scheme="http://www.blogger.com/atom/ns#" term="calculadora java dialogos"/><category scheme="http://www.blogger.com/atom/ns#" term="calculadora JOptionPane"/><category scheme="http://www.blogger.com/atom/ns#" term="como hacer calculadora"/><category scheme="http://www.blogger.com/atom/ns#" term="como hacer calculadora java"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="JOptionPane"/><title type='text'>[Baro Tarea] Como hacer una calculadora básica en Java con diálogos (JOptionPane)</title><content type='html'>Hola y buen día a todos mis lectores, después de años de no escribir aquí les traigo algo para ayudarles en sus tareas escolares ¿No pusiste atención a tu profe cuando explicó cómo hacer una calculadora con Java? ¿Te dejó de tarea hacer una calculadora y no sabes ni usar la que está en tu mochila? ¡Entonces estás en el lugar indicado! Abajo te dejo el código con dos métodos diferentes:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Calculadora sencilla con JOptionPane (3 Diálogos)&lt;/h3&gt;
&lt;div&gt;
Una calculadora hecha lo más sencilla posible, con unas 50 líneas de código, si has manejado if, String, Float y JOptionPane, entenderás a la perfección el código, y si no, más abajo explíco el código a detalle.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/GustavoHdz/59c56ecfac13184d0acba18ab7000b2d.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;h4&gt;
¿Sencillo, verdad?&lt;/h4&gt;
&lt;b&gt;Algunas cosas que debes saber:&lt;/b&gt; El método &lt;i&gt;calcularValores&lt;/i&gt;&amp;nbsp;acepta dos parámetros&amp;nbsp;&lt;i&gt;Float&lt;/i&gt;&amp;nbsp;y por lo tanto la lógica dicta que debería devolver un resultado del mismo tipo, pero como ya sabrás, no es complicado que acepte y devuelva &lt;i&gt;Integer&lt;/i&gt;, &lt;i&gt;Double&amp;nbsp;&lt;/i&gt;o &lt;i&gt;Long&amp;nbsp;&lt;/i&gt;simplemente reemplazando &lt;i&gt;Float&lt;/i&gt;&amp;nbsp;por la clase de tu preferencia.&amp;nbsp;Si ya probaste el código, también habrás notado, que al llamar a JOptionPane la ejecución del programa se detiene hasta que el diálogo haya cumplido su trabajo (Ésa es la razón por la que no ves todos los diálogos apilados), ya sea que presionaste &lt;b&gt;Aceptar&lt;/b&gt;, presionaste a la tecla&amp;nbsp;&lt;b&gt;Enter&lt;/b&gt;&amp;nbsp;o &lt;b&gt;cerraste el diálogo presionando la X.&lt;/b&gt;&amp;nbsp;Ahora que ya sabes todo lo importante y el profe te pregunte sobre el código ya tendrás algo que decir.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Calculadora compleja con JOptionPane (1 Diálogo)&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNkpxuSGOj6e0AeiI_QVxlXxdKOAz-7qNJ-zRK7pL-yUCT6vmvz-DWOPnW_BBAh1zFjZgF9ROrDhkHwVSUbvR-a9dcD5SkACk7tocnYKfpFwh5-Odniy9y0JQ6urh9apxdmDJmwY8LldaZ/s1600/Hackerman.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;680&quot; data-original-width=&quot;680&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNkpxuSGOj6e0AeiI_QVxlXxdKOAz-7qNJ-zRK7pL-yUCT6vmvz-DWOPnW_BBAh1zFjZgF9ROrDhkHwVSUbvR-a9dcD5SkACk7tocnYKfpFwh5-Odniy9y0JQ6urh9apxdmDJmwY8LldaZ/s200/Hackerman.png&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
¿Quieres dejar en vergüenza a todos tus amigos? Mientras ellos quizá muestren 3 horribles e ineficientes diálogos, tú te sentirás como&amp;nbsp;&lt;i&gt;Hackerman&lt;/i&gt;&amp;nbsp;con tu código de un solo diálogo ¿La desventaja? Puede que tu profe no crea que tú lo hayas hecho, te lo dejo a tu criterio. A continuación el código.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script src=&quot;https://gist.github.com/GustavoHdz/e51063b71cf3520780d5086d38a315ad.js&quot;&gt;&lt;/script&gt;
&lt;/div&gt;
&lt;b&gt;Algunas cosas que debes saber:&lt;/b&gt; El código en ambos ejemplos obviamente necesitan algo de optimización, pero es algo que dejaré a cada quién y además deja espacio para adaptarlo a sus necesidades. Como ya viste, por razones de no confundir a nadie no cambié nada en el método&amp;nbsp;&lt;i&gt;calcularValores&lt;/i&gt;, todo el código para hacer la operación en un solo diálogo se encuentra en&amp;nbsp;&lt;i&gt;mostrarCalculadora1Dialogo &lt;/i&gt;lo que hace&amp;nbsp;&lt;i&gt;operacion.indexOf(&quot;+&quot;)&lt;/i&gt; es indicarnos con un entero en qué posición de la cadena &lt;i&gt;operacion&lt;/i&gt; se encuentra el &lt;i&gt;String&lt;/i&gt; que pasamos como parámetro &#39;&lt;b&gt;+&lt;/b&gt;&#39; y en caso de devolver &lt;b&gt;-1&lt;/b&gt;&amp;nbsp;nos indica que no encontró el &lt;i&gt;String&lt;/i&gt; que le pasamos, ahora si te parece puedes leer nuevamente el código y seguramente entenderás todo, y si no, siempre podemos experimentar a poner lo que devuelve &lt;i&gt;indexOf&lt;/i&gt; en la consola con &lt;i&gt;System.out.println&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
Hasta aquí llega mi entrada, espero de verdad que le sirva a muchos estudiantes perdidos o que no quieren hacer su tarea de programación, si gustan pueden comentar abajo qué otras tareas sería bueno publicar para ayudarlos o cuales recuerdan que les costó trabajo realizar, la mejor idea gana medio kilo de tortillas, hasta la próxima shabos.</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/2251451720317499641/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2019/09/baro-tarea-como-hacer-una-calculadora.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/2251451720317499641'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/2251451720317499641'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2019/09/baro-tarea-como-hacer-una-calculadora.html' title='[Baro Tarea] Como hacer una calculadora básica en Java con diálogos (JOptionPane)'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNkpxuSGOj6e0AeiI_QVxlXxdKOAz-7qNJ-zRK7pL-yUCT6vmvz-DWOPnW_BBAh1zFjZgF9ROrDhkHwVSUbvR-a9dcD5SkACk7tocnYKfpFwh5-Odniy9y0JQ6urh9apxdmDJmwY8LldaZ/s72-c/Hackerman.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-7720358692720202581</id><published>2014-09-16T19:13:00.000-07:00</published><updated>2014-09-16T19:19:23.812-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Como crear una GUI en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Dialog Timer"/><category scheme="http://www.blogger.com/atom/ns#" term="Dialogo Temporizado"/><category scheme="http://www.blogger.com/atom/ns#" term="Dialogo Timer"/><category scheme="http://www.blogger.com/atom/ns#" term="Eclipse IDE GUI"/><category scheme="http://www.blogger.com/atom/ns#" term="GUI SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="JDialog con tiempo"/><title type='text'>BaroTip - Como crear dialogo que se cierra con tiempo</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;



Hola y buen día a todos mis lectores, un buen tiempo ha pasado desde mi última entrada, pero aquí les traigo un pequeño código que me pidió un lector hace ya mucho tiempo, pero que nunca salió de mi cabeza (Ésta noche podré dormir en paz) la verdad es algo de lo más sencillo, pero me daba flojera hacerlo :P jaja, aquí les va:&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img src=&quot;data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxQREhQUExQUFhUXGBUYFhcWFBYYGBgWFxoYGBgcFxgYHCggGxsmHhYXITEhJSosLi4uGB8zODMsNygtLisBCgoKDg0OGxAQGywkICQsLCwsNCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLP/AABEIAOEA4QMBEQACEQEDEQH/xAAcAAEAAgMBAQEAAAAAAAAAAAAABgcDBAUCAQj/xABNEAABAwICBgYGBgcECAcAAAABAAIDBBEFIQYSMUFRcQcTImGBkTJCcqGxwRRSYoLR8CMzQ5KiwvEVU7LhJDRUY3Ojs9IWFzV0k8Py/8QAGgEBAAMBAQEAAAAAAAAAAAAAAAMEBQIBBv/EADQRAAICAQMBBAkEAwEAAwAAAAABAgMRBBIxIRMiQWEFMlFxgZGhsfAzQsHRFFLhIzRD8f/aAAwDAQACEQMRAD8AvFAEAQBAEAQBAEB4nmaxpc9wa0ZlziAAO8nYvUs8AheNdKVBT3DXundwhbcfvuIb5EqzDR2y56e8ildBEQrul6qkv9GpWMG5zy6Q+7VA96uV+jk+W37ivPVpexHHfpVjFSezM4fZiYwW/caXe9WVoK4eskveyD/N3cNv3I8f2PjEubpK4831AHkbBe7NPH90PoeK218Rl9j7/wCEsV41f78n/evM6b/aPyPd9/8AozE/AcWjzD60cn1H8pK6UdPLiUPoedrauYy+55GPYvT2H0iYd0hDv+q26f4Vc+Ip+7/h4tZt5bXvR1KPpVxCH9dHFKOJYWH95p1fcq0/R0fNFiGrz7GSnCOmKlksJ4pITvI/SM822d/Cqs9DNeq8/QnjqIvknWFY3T1TdaCVkg36rgbcxtHiqc4Sg8SWCZST4OguT0IAgCAIAgCAIAgCAIAgCAIAgCAw1lWyFjpJXtYxou5ziGtA7yV6ouTwg3grHSPpbFzHh8Rkds62QEM5tZkTzdq8itCnQOXr/JFWzUqPBE48ExHFna8z5JBfeQI28tjB90ErQ206dd5pe7qyn2tl3qLPnwiY4L0VQssZn3PBg/nePgAqs/SKX6cfi/6JY6SUv1JfBEvodF6OG2rAwkb3jXPm+9vBVJ6y+fMn8On2J4aWmPEV8ev3OywgCwAA4AWVV9eSwj1rpg9yNdMDI10wMnl5DhYgEcCLhFlcHnJxq7RajlvrQMaeMY6s/wAFr+KtQ1l8OJP49fuV56WmXMV8On2IhjXRXE+5hfY8JBb+Ng+IKuQ9Ip/qR+K/ory0co/py+DIBiuiFXQv1268ZHova4j92Rht4GyuR7K5dxp+TIXOdb76x5rg7eAdKVVTEMq29c3jYNlA5+i/3c1Su0EX6vR/Qt16nPmWvo5pVTVzNaGQE+s05Pb7TTmOexZllU63iSLcZqXB3FGdBAEAQBAEAQBAEAQBAEAQEU0106gw4ap/STkXbC059xefUb7zuBVijTSt8kR2WKBVUsdfjUwMxcWg3bE3sxxg77HJvN13FbEKqtPHMun3ZnTuna9sOv2RYOjugtPTgGQCR3D1AeW1/N3kql2unLu191fUlr0sc5s6v6Eua8AWFgB5AKhjJbycPENMKaI6rXGZ/wBSEa5v3kdkeanhpbJdcYXmRyuijnSY/XS/qoI4W/WmcXOt7LbWPO6njpa16zz7iF6h+CMYw+um9Osm5QxhgHJzQCu8UQ/avizjdbL2noaFuf6b6p/tz/ivP8mtcY+R72Vr9vzNWbRSBkjYnB4kdm0dY43vfeMtxUkbsxc1wvI5cJKW18mydCC30XVDPYm/BR/5Vb5x8jrsrV7fmeXYPWRfq6yob/xW9YP47j3L3NM/2r4HmbY+09MxnEIfTjhqG8WExv8Aw8guXpqnw2jpaiS5N2j03gcdWYPp38JW2b++MgOdlDPSTXVdfcTRvi+ehIBK17ci1zXDuLSPgQq2GmS5TIlpDoJBUAmICN31fUJ7htZ93yWhTr5Lu2dV9SnZpI819H9CrcU0eqaGXWj12Pbm0g9q3Fjhk4d3gVe2wtjmPVECtlCWJ9GTnQnpS1i2Gts12wS7Gn2x6p79nJZV+ice9Dj2GhXfnpItaGYPFwbhUCwZEAQBAEAQBAEAQBAEBXfSH0g/RiaWjs+pOTnCxbF4bC/uOQ2ngr2l0js70uPv/wAK91ygiI6J6GvneZp3OJJu6Rxu5zt+qTtP2itOy2FCwur+iM+MZXP2R+5aFDTMhYGRtDWjhvPEnee9Zdk5Te6TLsIxgsROZiukzIndVG0zTf3bNjfbdsb8V3Xp3Lq+iPJ2qJz2YRU1p/0mQ6v9zD2Yx3Pd63ieSn3VU8fN8kPfs6ElwzRqOIWAa0cGC3m45lVrNW3x9SaOm/2Z14aNjdjRzOZ8yq0rZy5ZYjXGPCMdJicUrnsY67mGzhY5bsr7cxuSdM4JOS5EbIybS8DDSYyySaSEB2tHe5IyNiAbZ8Sup0SjBTfDPI2qUnH2HGxj/wBSpvZb8Xq1T/8AGn+ewgs/Xj+e07Jxln0gU9na5F727OzWttvsVXsJdn2ngT9qt+zxM0uJxtlbCXWkcLgWPfv2DYVyqZuDml0R67IqW3PUzS0zHek0Hwz815Gco8M9lCMuUcvENHopRYgEcHDWHhvCsQ1clyQS0yfBFKjRmakJfSSOj3lhOtE7z2eOfeFbVtd3SX/Su4zr/OhsYdpZZwiq2dRJud+zdycfR8bjvUdmla6w6r6kkLk+jO3X0sc7NSRoc0+Y7wdx71DXOVct0WdzjGaxIqzTLQkx3ezNp2Pt7pAN/wBr+i1aro3L2SKMoyp84mroVpxLh7xDPrGEG2ebo+XFnd5cFU1Ok39Y8/cuU34XXgvXDcQZOxr2ODgQCCDcEHgslpp4ZdTyba8AQBAEAQBAEAQFedJmnBpv9EpDepeO04fsmn+cjMcBmd172k0vaPdLj7kF1ygiMaFaJD9ZLmD6RO153gHbq32nf8NK65VLbHn7GdGLte6XH3LCMrWN3Na0dwAA+AWbhtlzOCOyYhNXEspy6OC9nTW7cnERjcO/by2G1GqNazPn85IZWN9IklwLRmOBoAbbiN59p2/kq12qcvVJq9P4yPmF1b4al9PK64d2oicuQFshkPNp4pbCM6lZHw5Pa5OE3B/A36WqmNRIx8YEQHYfnnstnfO+fKyhnCtVpp9fEkjKbm010GGYV1Mkr+sc7rDex3Zk8czntyS27fGMcYwIV7G3nk26ejjjc5zGNa55u4gbSo5TlJJN8Haik8pGUNAJNhc7TbM24lc9T04mIYbI+shlaBqMADjcXyLt3iFartjGmUHyyCdcnapeB29UXvYXta9s7cL8FV64wTmJ9HG54kLGl7RYOtmB+SfNdKclHan0PHFN7sdTUqcK16iOfrHDUFtQbDt33y258bKSN22t145OJV5mp54H0qb6TqdWOp1b6+e23G9tuVvFNlfZbs972DdPfjHQ09Ja992U8JtJIRcj1W/528geKl01cetk+EcXzfSEeWe8U0djmj1XAONhe4tc2zIt6J5LyvVSi+p5PTprpyQ4/SMMNjrS0w9U+nGPs93u5K44wuWVz9yupSg8MklNWRzx6zSHscPA8QQd/cVVcZQfsZNlNEA000TFtZno+qd7D9V3Fp4/k6VNytW2XP3Kc4Op5XBxdB9LJMOm6qW/VE5g+oTvH2Tv8+dbV6bf3l633LdF2PcX5h9a2Zgc0g3Cxy8bSAIAgCAIAgIt0haWDDqbWbYzyXbCw/W3uI+q29+82G9WNPR2sseHiR2WbEVnojgDpHulnJc951pXE53dnq34naf6LanJUxwufAynm2XkWEZGsbua1o5AAfJZ+G2Wc4OFBE/EnjJzaYHst2GYje7gwfnPZP3aVl8/Y46zeET3D6BsLQGgXAtkLADgBuCz7bXNluutQ95iqKuYTsY2O8RHafnkc9+wWy53XsYQdbbfX2BylvSS6GvpNQGWMPZ+sj7TSNthmQPK45LvTWbJYfDObobllco38MqjJEx7mlriMwRbPiO47VFbBRk0iSEnKKbNm6jOsi6DIugyLoMi6DIugyLoMnmWTVaTYmwJsBcm24d69Sy8BvCOFo3Sue59TKO28kNB9Vuw/C3Id6t6maSVUeEV6Yttzlyzco6+TWmMzBHGy5a85DVF7kk7RYXuop1wxHY8tkkJSbeUa2H4zTYgHtjddzdrXCzg05B1jtaf62XrhZQ+p7OKmupE8VwyTDpDLCLxHOSPdb6zeHy5bL0Jxvjh8lNp1s69NVxzxhze0xw2H3gjcVA4uD8zvKaIBpno3vZtzLDxG9p7+H9Vo1z7WPmVf0pY8GZei7S4wvFNKTq/syd3Fh+XlwWbrdP/APZH4/2aFFn7X8C74JQ4Ajes0tGRAEAQBAYqqobEx0j3BrGNLnOOwNaLknwXqTbwg3goh9W/Fa11U8HUB1Kdh2NaNnzce8ngt+ipUw+/vMnUWOcsIndJEI2ho3e87yq05ObyzqKUVhHNcx1fN1LL9Qw/pCP2jx6gPAb/AOi7WK47nyOsnhE9poGU8e5oaMzsAA3DuWfOUrJFuEVBGDEaUVcbOrlLRfWDm53tlxGYXVc+xk9yPJx7RLDOk1QEp9ugF0AugF0AugF0AugF0AugF0AugKq6QtLuuIp4LvbrBoDczNJewDRvaD5nPZZammo2LdLn7L+wSPQnRxmGQumqHD6RLq9a6+TRtbGzuG87z3AWrXWSvltgui4/s8clFdSWTxNlbY2IIyO3bvCrxk4PJ5KKksFcYjSuw2cuAP0eQ9to9U7nD87MtwWpFq6PmUmnB4Z1KqNszLXBBzafgQo4ScJZE0pLBVulmFmJ/WtyOsNa2542OHP424q7JKSz4Miqk13X4Fq9GelH0mENee23suHeN/I7Vg6insp48PA1a5745LAUBIEAQBAVn0yY04tioIj25yHSW3RA5A9xcCeTDxWhoasy3vw4K2ps2xwaGAUTYmCwyA1W/M8yfmtC6X7UZ0OdzMuL1brNij/WynVb9kes7wH5yUcIrl8IkyTTRzCG0sLWtGdvHvJ7yqN9u+RaqhtWWZW1sc75YC0nVBDriwNjY2IN9q5dcq0rDrfGbcTcpadsbQxgs0bB796jlJyeWdxSisIy3XJ6LoBdALoBdALoBdALoBdALoAgK+6R9MGxMfBG61spXg/8tvfx4bONr+l0/E38P7/oDo30RMdq2qbadw/RRuH6iMjeDskI28AbbyudVfnuR48fP/gJzWUjJm6sguL32kZjvCqwnKDzE5lFSWGYBiDGytpwCDqi1h2QALgeQXXZScO0Od6UtgxjDm1EbmOF7g/n8717TY4SyLYbkV7hMroJHUsh9G5jPFu23z8+C0ZpNbkU0z1j1G2RpuLhw1XfI8/8l3TL9rIp87kQTRqvdQVmq42BcGO4Z+i73jwJUOrq3w80XKLMPPgz9E4TViWMFYpfN1AEB5keGgkmwAJJO4DagKGoak11ZUVrtjnlkV9zBk3+EN8S7ivoKYKuCXsMnUT3SJUHho7guH1OEbGg9F18j6p4y9GMHcwfifnxUWpnsjtRNVHLySGrpZ43ukheXhxu5jvl/lY81XhOuUVGax5k0ozTzFmXDsZjeSHDq5NhByuefyK8solFZXVHsLU+ejOrdVyXIugyLoMi6DIugyLoMi6DIugyLoMi6DIugyRPTrSoUjDGxwErhcn+7ad/tHcPHhe1p6N73Pj7hEW6OtFzVPbXVLT1bTemjd6xv+tffaPq8dvC8+qu29yPPj/R6y1brOPMi6DJz8RxSKE52L7WAFtbxO4Kauqc+OCOVkY+80Gw1FSQXkwx7Q0ekeH5Pkpd1dXRdWcYnPnojkdIGFnVbUR+nGb+G+/x8XKXSWZWxkd0cPJyI69sjAbGzh5f0KsqDTKzkuCGabUPoSj2HfFp+I8lKz2p+BY/RXjvWwtDjmOy7mPxyPisHUV9nY0a1Ut0cljqAkCAh/Svi/0bDZrGzpbQt+/fWt9wPVnSQ32ry6kV0sQZBMDpOphjZvDbn2jmfeStp8GQ3l5MmKSEtEbfSlcGDx2+7LxXiWOp7HqyzcIoRBCyMbGgBZFs98mzRrjtjg84fVvkdIHRlgabAm+e38L5cV7ZBRSaecnkZNt5RmqKFkhDnNBLSCDvy48R3LmNkorCZ04J8mey4PRZALIBZALIDQxPFGQWBuXEXDR8zuCgv1MaueS9pNBZqeq6JeJqYVjnWv1HNDb31SDw3G6ho1naS2yRa1votU174NvHP9nasrpjiyAWQHE0r0gbRxXyMjgdRp97nfZHv2KemrtH5HuCttEsAfi07p59Y0rHkuLttRKNrfYG/wDdG+12+1Ux2x5+yPS5GtsLDIDIAbAO5ZhyLLwCyAwChZrmTVGubZ8uHA9677SW3bnoebFnJgqKx7ZmMEZLXDN2eW3wy+a6jBODlk5cmpJYM1ZAJGOYRkQQvIS2yyezjuWCqaOIxSywH1XEjl+bHxWynlZM6aPeLUfXQyM3lpt7Qzb7wEOYvDycHozxIxTlm51nDmMj7iPJZ+vh3VL4Glp5dWj9B0sms0HuWWWzKgKp6X5+tq6ClvkC6V47rgNv4Mk81p6CPSUvgVNVLCwakz7FaKRltmbRem6+vZfNsTS4+0f6hQ6mWytliiO5li4jK9kZMbdZ2Vh8chtWXWouWJPCL820uhlp3OLGlws4gXHA71zLCbwerOOpksuT0WQCyAWQCyAWQEf0ro7hso3dl3LcfMnzWfrq84mvcbfofUYbpfj1X8kcjeWkEZEEEHvCzk2nlG9KKknF8MnlDUiWNrxvGfcd481vVWKcFJHxmopdNjg/Az2XZCc/HMWZSRGR/Jrd7nbgPmdwUldbslhAqOjo58crHAuIhaQaiUbA3dFF3keWZPfpynHTw8/Bfyz0uaio2QxsjjaGMYA1rRsACypScnlnhmsuQLL0HxDw+FAa9c97WOLG6zhsH52ruCi5YlwcybS6Hqkc5zGl41XEZjgUlhNpcHsc46lf6b03U1kUo2SCx5ns/MeS0tLPdXj2FK+OJGLVU5XK+cPo2IcB1n8Mn/69yh1Ed1Ul+dC3TLDTP0HoxU68IWEaR2EBTWkcvXY7Nwhha0futP8A9rls6RYpXmZ2qfeMNTJ23c7eWSvRXQzpPqSbowgv9Jl4vDByb/ULO18uImjpY9MktxB8wdH1TQQT277hl381TrUGnufuLE92VtN2yiJBZALIBZALIBZALIDxPCHtLXbHAg+K8lFSTTO65yrkpx5RAKqAxvcw7Wm34FYM4OEnFn2dNqtgpx4Z2dFa3VcYzsdm32ht8x8Fc0VuJbH4mV6X0+6CtXK6P3f8/kkNfWMgjdJIdVjRcn4AcSdgC1YRcnhHzxTeLVtRjNYIIezxO1sEN8y7i4+82GzZqxUKK8v/APWC29H8EiooGQQizW7SfSc4+k5x3uJ/DYFmWWSslukDo2UYPi9PD4gFl6BZAfCEBqYY6UtPXNDTfK3DwJUlqgn3DiG5rvEa6Tqa9M142sePeD8wFZ0Uu80RahdEzixHWaHcQD5i6ulLBAtPYtWoa4etG0+LS4fgvV1JIPoXJ0f1WvHzAPmvnmsPBrrqTFeApOjd1mKYm/hLqeTnN/kW5SsVR9xmXvMmak8vadzPxV9LoZjfUsPoyitQtP1nvPv1f5Via15t+Btaddw730iTr9Tq/wBHa+vnttx2bcrbVBth2e7PUkzLdjHQ3bKM7FkAsgFkAsgFkAsgFkBHtKcOLgJWjYLP9kZg+Gf5Co6uhzalFZZs+i9ZGtOux4XK/k5GHUjxqzWGq0hwBdqk2z4G3ipaPRklJOT6+xL+TnV+mYShKEI5T6Zb/givSFj09TNFBG0ND3asQLgG69u06R2wWueQ5r6CihVJuXx/4YsJxmsxLC0L0Wjw6Dq2nXkd2ppTte/u4NGwD5krOvvdssvjwJDv3UJ4fF6AgCAIAgCA0qeokMr2uZZgHZdnns37DfPZsspJRioJp9ThOW5proc/TiHWopu4NPk5qk0jxajm9dxkLwc3gj9kDyy+S0pcmeyKdI8ecB7pB5ahHxK9idwJ90VzXij9hvwCw71iyXvZqV+oiyVEdlIaPC9fin/uX/8AVnW7H9OPuX2RmXeuzmVDs3c3fNaK4Mr9xaWg7yzDInNbrOAkIHE9a8blgalJ6hp+X2N2rKqyvP7m3/atR/s5/devOxq/2+w7Sf8AqbOH10r36r4ixtjnZ3zXFlcIxzGWTqE5N4aOrZVyYWQCyAWQGOeZsYu9zWji5waPMrqKcuFk8OLV6YUce2drjwjDn+9ot71PHS2vwx7+gOBiHSfAy+pG498j2xj3ax9ymjoW+ZfJZ/oZItivSgaj9CDExr7DshxO29tcm27grlGihGSk8/nkQ37uzlt5wejjkurq3Wx/iV5yfN/5M8YNSnwaornGKBzGvtrl8l9VrbgHYDmb5DuPBVfSFldSi39DR9Fbm5N8Fw4NQmCnhhc8yGONjC8ixcWgAm27kvmpy3ScscmybllwBZALIBZALIBZAaOKVUker1cevfWvkTa1rbOZ8lNVCMs7ngjnKS4WTQ/tSo/uD5PUvY1f7fY47Sf+pjxid8lDUmRmoQx1hYjKwN80rjGN0dryJNut5RDcAH+jx/e/xOWhPkokc6Sh2YOcnwavYHcCWdFJ7EfshY2p/Vl7zSq9RFpqAkKWwePUxPFG8Zi7zfI7+dbcHmqPuMy5d5nLr47SSD7T/iVpQeYr3GXLpJ+8tDo2ffD4e4yD+Nx+a+f1i/8AZ/D7G9p/UO0a09eItQ2tfX3bL+W7mouzWzdk73vdtwbqiOwgCAICqdO8UxT6W+GCCqdH2erMIcGObYZl7N973BK09NGhVqUms+OefqeYOFBoVjFSdZ0cUN/WmlBd/Dru9ynlq6I9Mt+78Qwdqj6IJX51Ne7vbDHbyc4/yqCXpCK9SHzPcHfw/olw6OxeySYjfLK7PmGao9yglr7nw8e5A3NItGWw0kgw+mhZIRmI42Ne9mes1rrbT3nZdc1XN2J2SeDxroRzRLQCd8AfVSuhe4ktia1jixm4OLr9ru3Cyv2elHB7YdUU56Cqb3YJJolSNo5Zac3LnG+u70nkDK54apuAMhmsGWttuvatfu9hu2aGmvSwsoXTx/PJ9CWWUxniyAWQCyAWQCyAWQCyA0qatL5XxlhAbscdhztw37RyUkoJQUs8nEZNyawaemT9WiqD9i37zg35rvTLNsTm7pBkJwFlqeL2b+ZJ+a0pvvMzyKdJzs6cf8U/4APmu6zqJMeixlmR+w34LF1DzbL3mnX6i9xaChOynq6Pqseqm7pYmvHPVjPxa9a9DzQvIoahd80Mdh1Z399j5j8brSplmCMq5YmyadFE96aWPeyU+TgLf4Ssf0hHFifka+klmBK66uMbmNDC7XNrjds9+aq117k3ngnnPa0sG4oiQIAgCAIAgCAIAgCAj+lFMRqTs9JhF+V8j4HLxVPVwaxZHlGt6MtT3UT4l+P88js0VQJWNeNjhfkd48DkrVc1OKkjNuqdVjg/AzLsjCAIAgCAIAUBp4ZWmZpJYW2Ns1JbXseM5I4T3Lg4HSZU6lE4fXexvld/8oVjQrNufYiPUvuYORQwakcbfqtaPIBXG8spld9Jk16hjfqxA+LnO+QClr4PUWb0c02qAOAA8hZYMnmTZqJYWCfrk9Kp6To+oxSgqd0gMTjyNs/Cb3LS0TzXKPs6/nyKmpXVMw6UU+bH82nwzHzWhppcoy9RHhmx0aVfV1kkR2SsuPaZn8Ncqv6RhmCl7P5Lehn4Fk11T1TC+xNrZDvNllQhvlg0Jy2rJ6ppddjXWIuL2K8ktraPYvKyZVyehAEAQBAEAQBAEBjmiD2lrswQQeRXkkpLDOoScJKS5RH9HZTDLJTP4ks7+XMWPgVS00nCbqfwNf0hBXVR1EPj+eT6EjV4xggCAIAgCAwV1T1TC+xNrZDvyXdcN8sHM5bVk908uu1rrEXANjtzXko7W0ep5WSCdI8vW1FLTDjruHcT/wBrHea0NFHEJT+BU1LzJI2NVSZICo8ck+kYk+2Y6wM8I7A/4SpZy2VN+RJWsySLu0Gp7R34rCNElSAgnTLhZmw8yN9KB7ZRbbq5sf5B2t91W9FPbbj29CG+OYnIil+mUTJBtcxruT25OHmHBaEHssM6yO6JHoak080M4/ZvBPe05EeIy8Vathvg4+0g089ssl2xPDmhwNw4Ag8QcwvnGsPDNzk1qesLpXsLCA3Y7j7t/wAlJKCUFLPJwpNyawbZKjOz6gCAIAgCAIAgCA+ICP6UUxbqVDPSYQDyv2SfHLxVLVRaxYvA1/Rliluonw+P5/v4Hao6gSsa9uxwvy4jwOStQmpxUkZt1Tqm4PwMy7IggCAIBdAahqz13V6hta+tu2X4bNyk2LZuycbnu24NtRnZV1HN9Lrp6j1G9iP4C33R/Gtjb2dUYGbKW6TkdLF6wQQSyn1GOdzIHZHibDxXEVl4BVOhtMZJy852G3i552/HzXmuniCj7f4LGnjmWT9DaP0+pC0dyyS4dNAYa2mbLG+N4u17XNcOLXCx9xXqbTyjxrPQp7QF7qeSpoJT24XuLb723sSO49l331sTaklNeJnuOHgzYzh+q5zfVdmOR/A/BWq57olKcdkiXdGmLdZAYHn9JAdXnGfRPhmOWrxWXrqts9y4f3NTS2bo49h363Fg06kbS9+yw2A/NQQoyt0uiJJW4eF1Zigwx8jg+dxuMw0HZ5bPDzXUroxW2CPFW28yZ17KsTCyAWQCyAWQCyAWQCyAIDHPCHtc12YcCDyK8klJYZ1CbhJSXKI/o3KYpJKZ+4kt7+NuYsfNU9NJwk62a3pCCtrjqIfH88n0JIrpjhAEAQHMrsMJcZInlr+85H8Pgp4XJLbJdCKVbzui+pjgxYtOpO3UP1tx/PELqVCazW8nitx0maGn+MfRqVwae3LdjbbbH0j5Zc3BdaOrfZl8I81E9scLxOHgGH9RA1p9I9p/tO2jwyHgrdk90slRLCIp0p4nqxx04Obzrv8AYaezfm7P7ikpj1yD30b4SbMuM3HXPjs91lm6uzfY/LoXqY7Yl0wssAFWJT2gCAqrpVoXUdVT4nELi4jnA35EAnm27bneGLR0c90XW/eirqI/uOrWxNqIWyRkOBAewje0i/wU1c9ksMqWQ3IjcFW6jqGVLASB2ZWj1mHL894arFtatg4MjpscJZLbonxvaJY7ESAO1gNoIyusOW5PbLwNeOH1XiY6Z0vWPDwNT1T8PcupKG1Y58TmO7c88G4ozsIAgCAIAgCAIAgCAjulNOWFlQz0mEB3K+V/h4qnqotNWLwNf0bYpqWnnw+P5/s7lHUCRjXt2OF/8lahJSipIzLa3XNwl4GZdEYQBAabnS9cBYdVbM5Xv8b3UmIbPM4727yM9S1mqS8N1W9ol2wWzv3LmLlnunTxjqVmJziVa6cg9RCbRg7yM25cfWP3QtZRVFWzxfJnyl2kt3gSGeRrGue4gNaC5xOwAC5JUK6npSlRO7Ea1zzfVc69vqxNyaPK3i4qxbPsas+P8ntcd8sF3aEYbqt1yFiGgS5AEAQGjjeFx1cEkEouyRpaeIO0Ed4IBHeF1CbhJSR5JJrDKp0HrH0k8uGVOT43OMJOxw9IhvcR2xzcNy1bMTirIlBxcXhnexjDhmbXa7IjvO3wK7qsysFeyGHlGPQrGjRy/RZnfonm8Lz6pPqk8D7jnvUero7Rb48rksae7HdfBYtSwua4NOqSMjwWXFpPLL0llYMNOeqY0SPBOy5O3uzXcu/JuKOV3Vhs2lGdhAEAQBAEAQBAEBjqIQ9rmO2OBB8VzKKksM7hNwkpR5RH9GZjFJJTP2gkt+duYsfNVNNJwk62avpGCtrjqIePP59CSK6Y58JQGnVtMzP0Uls9oPDdcKSD2S7yOJd5d1m2wWABNzYZ8VG+TtEC04xt08goaY3JP6Vw2C20E8BtPfYLS0tKgu1n8CnfZueyPxN3DcPbBG2Nmxu/eSdpPeSvJTcnlkaWCCdKekIaPokZzNnTEbm7Ws8cie63FWKIfuZ4zFoBgByuO06xd3DcPn4rP1d3aTwuEXKYbY9eS7KKnEbA0KqTGdAEAQBAQHpT0TdUxtqqcEVUGY1fSexp1rD7TT2m+I3q3pL9j2y4ZDdXuWVya2hukLMQg7VhK0ASs79zgPqn3G43KzZB1yKq6o841goe0sdsObXbwfx+Klrt8SCUNrN3Q/SdzHCkqzZ4sIpDseNgBJ38D4HPbX1Omz/6V/FFui79siaVVIyS2sL2NxnZUYTlHgsyipcniSstK2PVOYvrbht/BdKGYOWTxy723AxKq6phO/Y3mlUN8sCctqyZKMuLGl/pWzyt+SuZ43PbwdRzjqZlyehAEAQBAEAQEc0ppyxzKhnpNIDv5SfeDzCpamLi1YvA1/RtinGWnnw+P5/s6OCYj1zM/SGfMH82WhJRcVOPDMhxlCcq58pmaCq6x0jCwgC4ud42eC9lDalJM4UtzawZqWmbGNVosL323zXM5uTyzqMVFYRE9MtKzGfo1Ld87+yS3PUvuH2u/wBXarmm02f/AEs4+/59Svddjux5NbRzAhTMJcQ6V/pu/lb3D37eUttu9+RBGOEYdMdImUEOtkZXXETOLuJ+yN/gN68qg5s9bwVTo7hz6qYzSXddxJJ9d5N/If5LvV3quOyPP2RJTXue5l66KYR1TA4jMrJLhI0AQBAEAQBAVLp/o1LQT/2lQiwuTPGBln6TrDaw+sNx7XLR01ymuyn8CrdXjvIkejuNw4hBrs25B7Ce0x3A/I70nGVciLpJGtjeBNlbqu2eq4bWn87t6lrtx1RFKGDxgelMtG5tPW3dHsjnFzlwdvPxHeM1zdpo2d+vn2E1V7j0lwT+GZr2hzSHNIuCDcEdxCzWmnhl1PPVHLYOvmv6kezvP5+AVh/+cMeLIV35eSN2Ks1pHR6p7Ivf881C68RUskinmWDZBXB0fUAQGrNWhsjY7Htb78/wUirzFyOXPEsG0ozoID5fdvQGlUStkc6BzTYtNzzH5z4rqdO6vL8T2u5wsTjyupFsLldTzFjtrSfEb/MWIUGhl61Evevz6/M0fStalGOqhw+j/j+vkTTrRq61wG2vc5C225upsPODNysZILpBpe+d/wBGoAXOOTpBlYby0+qPtHw3LQp0qgt9vy/PsVLL3Luw+Zm0d0ebSguJ15Xek/5N4D3n3Bbc5vyI4w2mXSPHIqKEyynuYwek93BvzO5cwg5vCOn0KYkkmxSpdJIcsgbeixu5jPzxJVq2yOnhhcnkIObLc0L0bDQ0ltmgZBY0pOTyy8kksInrW2Fl4en1AEAQBAEAQHl7QRY5goCodLdEJ8MmNbh3oZmSEC4aNps31o+7a3d3aVOojYtlvz/PEqWVNPdEkmiWlcGIM7NmygduInMd7frN7/Oy5tqlWzhNM6VdhbJGlrmhzTtafkkbWmcuBHYaOrw9xdSOMkW10L8z93jzFjzU8nXcsWc+08i5QfdJHgWmtNP2XfoJb9pkmQ1u53HnYqpbo7IdV1XkWa9RCXR9GSgFUywa1PRtY5zgTd22/O6klY5JJ+BxGCTbPkMUgkcXOuw+iOH4JKUXFJLqEpbm3wfYJXl7g5tmj0Tx/FJRiopp9QnLLTRpVn+sx8h8XKWH6TI5fqI3TK/rQ3V7FvS/PwUWI7M56kmZbsY6HwxSdbra3Yt6Ph+Od03R2Yx1GJbs+B9fRtMgkubgbN2/8UVjUdocE5bjZUZ2RXH9JaKmeXnVkmAtZlj+8dg95VinQznLfjHmcWa3bDss5XsI9LHW4oQZSaen2htiC4brNOZ9p2XAK8nVR6vVlKTnZ63RElwvCoqZmpE2w3na5x4uO8qvOyU3lnailwc3SzSmHD2XedaUjsRA9p3efqt7z4XK6qqdj6BvBT80lRik5klOWzIdljfqsH54lWrLIaeOFycwg7GWjodooGhvZs0e/vPErInOU5bpF6MVFYRYkMQaAAuD0yIAgCAIAgCAIAgPjm32oCstNOjgl/0qgPVTA62q06oc7i0j0He477XJV6jV4W2zqiCynPWPJoaO9Ipjd9HxJhikbkZdUgX/AN4wDL2m9nkFNPTprdX1RApYeJFhRFkjQ9pa5rhdrmkEEdxGRVXLXQ6wmc7FtHYaj9YwE7njsvH3ht5G4UsLpQ4Zy4JnGjwWupP9UqNdn93L8Be7f8KldtVn6kfijlKcPVZss05ngyq6N7eL2X1fm3+JcPR1y/Tn8/z+CVaiS9aJ06PT6ik/aOZ3OY74tuPeopaG5eGTtamtnUi0jpHbKiHxkaPcSoXp7V+1/Ik7av2o8zVlO57ZPpEQt/vGW39/euoxsUXHa/kzluDe7KPUmkVK3bUQ+EjT8CuVp7X+1/I67av2o5tXp3RR/tC/uax3xcAPepY6G5+GPicPU1o5EnSA+bKkpZJD9YgkeIbkPFymWhjH9SX5+eRE9S36qNd+GYlWf6xMIYz6jbE24FrDbzcVIrKKvUWWcNWT9ZnXwfRWnprOa3XePXk7Th7I2N8AobNROfLPY1qJ15ntY0ucQ1oFy5xAAHEk7FEup2Vvpb0nsZeOis92wzOHYHsNPpnvOXNW6tK31mRyn7CF4ZgM1XIZZy8lxuS4kvfzvsH5Fku1ca1tr5+iO4UuXWRbWi+iQYGlzQANgWXKTk8stpJLCJvFEGiwC8PT2gCAIAgCAIAgCAIAgCAj2k+iNPXNtKwaw9F4yc3k75bFJXdOt5izmUFLkrGp0bxLCHF9HI6WK9yy2tcfai2Hm3PktCOoqu6WLD/PH+ytKqUfV6nYwPpWhd2KuN0LxkXNBcy/e3028rHmvJ6SXMHk5Vi8Sd4biUNS3WgljlG8scHW5gZg9xVWUZR6NYO+Tc1VzkYNCqwSnl/WQROPEsbfztddxtnHhs8cU+Uc6XQmidn1JHsySj3B1lKtVavH7HLqg/AxHQOj+rJ/8r/xXv8AmW+36HnYwPUeg1EP2Tjzll+AdZHq7fb9Ee9lE6FNo7Sx5sp4geJYCfN1yondN8tnShFeB0gy2Q2KPJ0auI4hDTt1ppY428XvDb8r7T3BdRi5dEsnhBMe6V4I7tpWOmd9d12Rjz7TvIc1ahpJP1uhw7F4EDrq2vxR15XHUvcNsWRD2Wj0uZue9TOdNHHP1PFCcyT6MaB5hxBc76zhs9kbviqF2qnZ04RZhTGPXxLOwfR5kIBIuVVJTuAWQH1AEAQBAEAQBAEAQBAEAQBAeXsB2hARrSDQmmq/TjbrfWGTh94ZqSu6dfqs5lCMuUV5inRVLC7XpZnNI2XuHDk9liPJXY6/KxOP57iB6f8A1ZqNxLG6LIudK0fWDZR5mz/eu92ls8vp/wAONlkfM2IulqqiynpIye4yQ+5wcuv8SEvVl9mc9o1yjowdMcRHbpZAfsyMcPeGrh6KXgwrUZ//ADhpv9nqP+V/3Lz/AAp+1HvaIwzdMcIHYpZSftSMaPcCvVopeLDtRy6npgqH5Q00TT9p75fc0NUn+FFdZP8Ag87XPBy6nSvF6rIOfG07o2CIfvHte9eY01fLX3PcWS4Rq02htTO7WleS47SS57jzc7/Ncy10I9IL+DpaeT9ZkwwPo5aLEtueL8z5bB5KnZqrJ+OPcTRqjEnWGaLRx2JzKrkp34oWtFgLIDIgCAIAgCAIAgCAIAgCAIAgCAIAgCAEIDBLSsdtAQGhUaPxP9UIDk1OgtO/bGw82NPyXasmuG/meOKfgaTujmm/u4/3G/guu2s/2fzOezj7D1H0ewDYyMfcb+C8ds3zJ/M92R9hvQaGxN4eAUbeeTo6EGjkTdyA6ENCxuxoQGwBZAfUAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAf//Z&quot; /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;br /&gt;
Lo que haremos será utilizar la clase JDialog y Timer, como ya se habrán imaginado, JDialog representa al dialogo que mostraremos y Timer será nuestro contador, por falta de un equipo de cómputo decente donde estoy ahora mismo, no puedo probar que el código funcione correctamente, así que tendrán que hacerlo por mí, soy un mal educado, nunca aprendí a compilar y ejecutar código Java desde la línea de comandos :P puro IDE, así que aquí les va el código:&lt;br /&gt;


&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
class DialogoTiempo extends TimerTask{
	//Será nuestro contador, obviamente.
	Timer contador;
	//El dialogo donde pondremos el mensaje.
	JDialog dialogo;

	public void lanzarDialogo(String mensaje, int segundos){
		//Panel que sostendrá la etiqueta con el mensaje
		JPanel panel = new JPanel(new FlowLayout());
		//Etiqueta que contiene el mensaje.
		JLabel texto = new JLabel(mensaje);
		//Agregamos la etiqueta al panel
		panel.add(texto);
		String titulo = &quot;Soy un dialogo que se cierra después de &quot; + segundos + &quot; segundos.&quot;;
		//Creamos el dialogo.
		dialogo = new JDialog();
		//Le damos un título al dialogo.
		dialogo.setTitle(titulo);
		//Agregamos el panel creado al dialogo.
		dialogo.getContentPane().add(panel);
		//Centramos el dialogo.
		dialogo.setLocationRelativeTo(null);
		//Mostramos el dialogo
		dialogo.setVisible(true);
		//Instanciamos el contador.
		contador = new Timer();
		//Iniciamos el contador ejecutando
		timer.schedule(this, segundos * 1000);
	}
	
	//Se ejecuta cuando se cumple el tiempo
	//establecido por timer.schedule
	public void run(){
		
		//Si el dialogo está visible
		//(Que no se ha cerrado por el usuario)
		if(dialogo.isVisible()){
			//Cerramos el dialogo
			dialogo.dispose();
			//Salimos del programa
			System.exit(0);
		}
	}

	public static void main(String[] args){
		//Creamos un objeto de nuestra clase.
		DialogoTiempo dialogo = new DialogoTiempo();
		//Lanzamos el dialogo.
		dialogo.lanzarDialogo(&quot;¡Éstas en el Blog de Baro!&quot;, 5);
	}
}
]]&gt;&lt;/script&gt;



&lt;br /&gt;
Sencillo, ¿no?&amp;nbsp;Siéntanse&amp;nbsp;libres de expresar aquí sus dudas, comentar mejoras o fallas,&amp;nbsp;repito, no tengo un IDE donde probarlo por hoy, los detalles los arreglo conforme los encuentre, espero que haya sido de ayuda, un placer escribir para ustedes, saludos :D.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;color: orange; font-family: Verdana, sans-serif;&quot;&gt;Entradas Relacionadas:&lt;/span&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;a class=&quot;GCUXF0KCPB&quot; href=&quot;http://baro3495.blogspot.com/2013/10/como-utilizar-el-dialogo-de-pregunta-en.html&quot; style=&quot;border: 0px; color: #1155cc; display: inline-block; font-size: 12.8000001907349px; margin: 0px 10px 0px 0px; max-width: 100%; overflow: hidden; padding: 0px; text-decoration: none; text-overflow: ellipsis; vertical-align: baseline; white-space: nowrap; width: auto;&quot; target=&quot;_blank&quot;&gt;Cómo utilizar el dialogo de pregunta en Java (JOptionPane)&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;GCUXF0KCPB&quot; href=&quot;http://baro3495.blogspot.com/2013/04/como-mostrar-un-dialogo-de-mensaje-en.html&quot; style=&quot;border: 0px; color: #1155cc; display: inline-block; font-size: 12.8000001907349px; margin: 0px 10px 0px 0px; max-width: 100%; overflow: hidden; padding: 0px; text-decoration: none; text-overflow: ellipsis; vertical-align: baseline; white-space: nowrap; width: auto;&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Cómo mostrar un dialogo de mensaje en Java (JOptionPane)&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;GCUXF0KCPB&quot; href=&quot;http://baro3495.blogspot.com/2012/11/creando-una-gui-en-java.html&quot; style=&quot;border: 0px; color: #1155cc; display: inline-block; font-size: 12.8000001907349px; margin: 0px 10px 0px 0px; max-width: 100%; overflow: hidden; padding: 0px; text-decoration: none; text-overflow: ellipsis; vertical-align: baseline; white-space: nowrap; width: auto;&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Como crear una GUI en Java&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;GCUXF0KCPB&quot; href=&quot;http://baro3495.blogspot.com/2012/12/syntaxhighlighter.html&quot; style=&quot;border: 0px; color: #1155cc; display: inline-block; font-size: 12.8000001907349px; margin: 0px 10px 0px 0px; max-width: 100%; overflow: hidden; padding: 0px; text-decoration: none; text-overflow: ellipsis; vertical-align: baseline; white-space: nowrap; width: auto;&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Como crear una GUI en Java - Parte 2&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/7720358692720202581/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2014/09/barotip-como-crear-dialogo-que-se.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/7720358692720202581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/7720358692720202581'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2014/09/barotip-como-crear-dialogo-que-se.html' title='BaroTip - Como crear dialogo que se cierra con tiempo'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-2068084893743985684</id><published>2014-07-04T19:20:00.000-07:00</published><updated>2014-07-05T13:53:55.194-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Captura Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Captura JOptionPane"/><category scheme="http://www.blogger.com/atom/ns#" term="Como leer entrada de usuario con dialogo en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Dialogo de captura en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="JOptionPane"/><category scheme="http://www.blogger.com/atom/ns#" term="Mensajes GUI Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Mensajes JOptionPane"/><category scheme="http://www.blogger.com/atom/ns#" term="Mensajes Sencillos GUI Java"/><title type='text'>Como leer la captura del usuario con un dialogo en Java (JOptionPane)</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;



Hola y buen día a todos mis lectores, largo tiempo de no escribir por aquí por cuestiones de trabajo, sé que me extrañaban, jaja, así que les traigo éste nuevo tema, y le dedico ésta entrada a Jeanette que espero que no se esté durmiendo, jaja :P, comencemos.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio2twLuTEMWjk_v-nc8nt71fPkxE4tGuO0wVPOfqhzcemudOkLk4aDyXU8E5tYb1iOgbhk2ifQCXC_VBMU08EevP5PfaQxUuFfUUPnhyphenhyphen01omwIrR8gQGz7Kg9Z25wDxXrtOhA7fg-9wEfr/s1600/Captura1.png&quot; /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Ejemplo de dialogo de captura.&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Ya vimos en una entrada anterior &lt;a href=&quot;http://baro3495.blogspot.mx/2013/04/como-mostrar-un-dialogo-de-mensaje-en.html&quot; target=&quot;_blank&quot;&gt;cómo mostrar mensajes al usuario con distintos cuadros de dialogo&lt;/a&gt;, así que ahora viene la contra parte, pedirle datos al usuario, lo que es realmente importante en cualquier programa del mundo real, ya que cualquier software requiere siempre de la entrada del usuario, a continuación unos ejemplos utilizando la siempre útil clase &lt;a href=&quot;http://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;JOptionPane&lt;/i&gt;&lt;/a&gt;&amp;nbsp;(Clic para ver documentación).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Ejemplo #1:&lt;/b&gt; Obtener y mostrar cualquier texto ingresado por el usuario.&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[

import javax.swing.JOptionPane;

public class DialogosCaptura {
 
 //Ejemplo #1:
 public static void main(String[] args){
  //Guardamos en la variable &#39;entrada&#39; lo que captura el usuario.
  String entrada = JOptionPane.showInputDialog(&quot;Captura lo que sea: &quot;);
  
  //Mostramos en otro dialogo lo que el usuario capturó.
  JOptionPane.showMessageDialog(null, &quot;Has capturado: &quot; + entrada);
 }
}

]]&gt;&lt;/script&gt;


&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Y el resultado de nuestro código es:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio2twLuTEMWjk_v-nc8nt71fPkxE4tGuO0wVPOfqhzcemudOkLk4aDyXU8E5tYb1iOgbhk2ifQCXC_VBMU08EevP5PfaQxUuFfUUPnhyphenhyphen01omwIrR8gQGz7Kg9Z25wDxXrtOhA7fg-9wEfr/s1600/Captura1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio2twLuTEMWjk_v-nc8nt71fPkxE4tGuO0wVPOfqhzcemudOkLk4aDyXU8E5tYb1iOgbhk2ifQCXC_VBMU08EevP5PfaQxUuFfUUPnhyphenhyphen01omwIrR8gQGz7Kg9Z25wDxXrtOhA7fg-9wEfr/s1600/Captura1.png&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;Dialogo de captura #1: Donde capturas cualquier texto.&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj35qN9QckUwj0eD7Mjq0aXpydhF-gzZicRfpYuW7o8coBT2U5rwHE1MdZXjT6wAEI0QJs-rQ7MbqmPeJVNGW7O0DNmfn55EuPZ2ALGez9GFWkk48MHt1Grpb-5SsehenzRK-5LmAWkM_M-/s1600/Mensaje1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj35qN9QckUwj0eD7Mjq0aXpydhF-gzZicRfpYuW7o8coBT2U5rwHE1MdZXjT6wAEI0QJs-rQ7MbqmPeJVNGW7O0DNmfn55EuPZ2ALGez9GFWkk48MHt1Grpb-5SsehenzRK-5LmAWkM_M-/s1600/Mensaje1.png&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;Dialogo de mensaje #1: Donde se muestra lo que capturaste.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Ejemplo #2:&lt;/b&gt;&amp;nbsp;Obtener y mostrar cualquier texto ingresado por el usuario.&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import javax.swing.JOptionPane;

public class DialogosCaptura {
 
 //Ejemplo #2:
 public static void main(String[] args){
  //Guardamos en la variable &#39;entrada&#39; lo que captura el usuario.
  String entrada = JOptionPane.showInputDialog(&quot;Captura otra cosa&quot;, &quot;Sugerencia&quot;);
  
  //Mostramos en otro dialogo lo que el usuario capturó.
  JOptionPane.showMessageDialog(null, &quot;Has capturado: &quot; + entrada);
 }
}

]]&gt;&lt;/script&gt;



&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
¿Qué diferencia encuentras aquí? Hice un ligero cambio en el código, usando un método &lt;i&gt;JOptionPane.showInputDialog&lt;/i&gt; diferente, que permite agregar, además del título de captura, una sugerencia de la misma, haciendo la vida del usuario un poco más sencilla como se aprecia en las&amp;nbsp;imágenes&amp;nbsp;;).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9H3m6XjJCapbnMbMVgn1yY8eUkvCfx5Irx8u39A8q_A2Oto1JiAqphba6flE3taK7pa-4azW-_UVNQ1kA1pK_IMD6dzW1GnU1CRjejV3QmaG1UNUbBf8jAZFIcmcH2Zs6lA7O2MMAGTcw/s1600/Captura2_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9H3m6XjJCapbnMbMVgn1yY8eUkvCfx5Irx8u39A8q_A2Oto1JiAqphba6flE3taK7pa-4azW-_UVNQ1kA1pK_IMD6dzW1GnU1CRjejV3QmaG1UNUbBf8jAZFIcmcH2Zs6lA7O2MMAGTcw/s1600/Captura2_1.png&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;Dialogo de captura #1: Donde capturas cualquier texto con una sugerencia al mostrarse el dialogo.&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZIbsYtS5KS0KNb0DRR2fFNXRkTIdYiX4o69j35oxGPAYv0zJoLbGlxF_6miuNUGa5VM5MycxC3ef4QtcZ091WnsI7EohJRmmbVQGpKjDJ1-8cRaFC7SWmnjObsbTbtTz7_xuStcEhH3KI/s1600/Captura2_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZIbsYtS5KS0KNb0DRR2fFNXRkTIdYiX4o69j35oxGPAYv0zJoLbGlxF_6miuNUGa5VM5MycxC3ef4QtcZ091WnsI7EohJRmmbVQGpKjDJ1-8cRaFC7SWmnjObsbTbtTz7_xuStcEhH3KI/s1600/Captura2_2.png&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;D&lt;/i&gt;&lt;span style=&quot;text-align: start;&quot;&gt;&lt;i&gt;ialogo de captura #2: Donde se ve modificada la sugerencia del dialogo.&lt;/i&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8eZsy25gb312lTJhKlcWBPhOcZ_VYDYv9mojUD_Ed8NBfXbkLYhF1TxC-QwTXuavd8hWpEPltIa7VaGyIIdVMYZ9rf92SjeuQ_fXHRzqLRfPNrBPGuxXSUHROUmfITtV4v7inoptIBhA5/s1600/Mensaje2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8eZsy25gb312lTJhKlcWBPhOcZ_VYDYv9mojUD_Ed8NBfXbkLYhF1TxC-QwTXuavd8hWpEPltIa7VaGyIIdVMYZ9rf92SjeuQ_fXHRzqLRfPNrBPGuxXSUHROUmfITtV4v7inoptIBhA5/s1600/Mensaje2.png&quot; height=&quot;126&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;Dialogo de mensaje #1: Donde se muestra lo que capturaste.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Algunas cosas que debes saber sobre JOptionPane&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Cuando llamamos a un dialogo por medio de cualquiera de los métodos de &lt;i&gt;JOptionPane&lt;/i&gt;, como lo son &lt;i&gt;showMessageDialog&lt;/i&gt; o &lt;i&gt;showInputDialog &lt;/i&gt;debemos tener en cuenta que se &#39;bloqueará&#39; la ejecución de&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;nuestro&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;programa hasta que el dialogo se cierre, ¿te preguntabas por qué aparecían un dialogo tras otro en orden y no todos a la vez? Ahí tienes la respuesta. Otra cosa muy importante, es que si en el dialogo de captura se presiona el botón &quot;Cancel&quot;, en el código de nuestro ejemplo (y en cualquiera) nos devolverá &lt;i&gt;null&lt;/i&gt; en la variable donde almacenamos la entrada,&amp;nbsp;compruébalo&amp;nbsp;tú mismo ;). Y ahora, podemos aprovechar las características de &lt;i&gt;JOptionPane&lt;/i&gt; para pedir datos en orden al usuario, hagamos algo un poquito más complejo (y útil) con los&amp;nbsp;diálogos.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;b&gt;Ejemplo #3:&lt;/b&gt;&amp;nbsp;Sumar 2 números por medio de&amp;nbsp;diálogos.&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[

import javax.swing.JOptionPane;

public class DialogosCaptura {
	
	//Ejemplo #3:
	public static void main(String[] args){
		//Variables enteras para almacenar las capturas y operaciones.
		Integer num1 = 0, num2 = 0, sum;
		
		//Guardamos en la variable &#39;entrada&#39; lo que captura el usuario.
		String entrada = JOptionPane.showInputDialog(&quot;Captura el primer número:&quot;, &quot;0&quot;);
		
		//Nos aseguramos de que el usuario no haya presionado &#39;Cancel&#39;
		if(entrada != null){
			//Tratamos de convertir la entrada del usuario en un entero:
			try{
				//Aquí converitmos un texto a entero.
				num1 = Integer.parseInt(entrada);
			}
			catch(NumberFormatException ex){
				//Visto anteriormente en la entrada de dialogos de mensaje
				JOptionPane.showMessageDialog(null, &quot;Lo que capturaste no es un entero: &quot; + entrada,
						&quot;Error de captura&quot;, JOptionPane.ERROR_MESSAGE);
			}
		}
		else{
			JOptionPane.showMessageDialog(null, &quot;Has presionado el botón de cancelar.&quot;,
					&quot;Usuario canceló&quot;, JOptionPane.ERROR_MESSAGE);
		}
		
		//Guardamos en la variable &#39;entrada2&#39; lo que captura el usuario.
		String entrada2 = JOptionPane.showInputDialog(&quot;Captura el segundo número:&quot;, &quot;0&quot;);
		
		//Nos aseguramos de que el usuario no haya presionado &#39;Cancel&#39;
		if(entrada != null){
			//Tratamos de convertir la entrada del usuario en un entero:
			try{
				//Aquí converitmos un texto a entero.
				num2 = Integer.parseInt(entrada2);
			}
			catch(NumberFormatException ex){
				//Visto anteriormente en la entrada de dialogos de mensaje
				JOptionPane.showMessageDialog(null, &quot;Lo que capturaste no es un entero: &quot; + entrada2,
						&quot;Error de captura&quot;, JOptionPane.ERROR_MESSAGE);
			}
		}
		else{
			JOptionPane.showMessageDialog(null, &quot;Has presionado el botón de cancelar.&quot;,
					&quot;Usuario canceló&quot;, JOptionPane.ERROR_MESSAGE);
		}
		
		//Hacemos la suma:
		sum = num1 + num2;
		
		//Mostramos resultado:
		JOptionPane.showMessageDialog(null, &quot;El resultado de la suma es: &quot; + sum);
	}
}

]]&gt;&lt;/script&gt;





&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;Salida del programa:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi77vEi_cvaZZdag84qjAl5oee0cKkUVhJ5KX8saPS_K9hAAcmaFsk1Toi10f9lIsraIw2Y8SfDlrmtu3YStwlFA0MbtOew_uKnHnJ5gquVOJuiesEJahKQ9lJt8T4q7cq4jFa-Ubd6pOw/s1600/Captura3_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi77vEi_cvaZZdag84qjAl5oee0cKkUVhJ5KX8saPS_K9hAAcmaFsk1Toi10f9lIsraIw2Y8SfDlrmtu3YStwlFA0MbtOew_uKnHnJ5gquVOJuiesEJahKQ9lJt8T4q7cq4jFa-Ubd6pOw/s1600/Captura3_1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;i style=&quot;font-family: Verdana, sans-serif;&quot;&gt;D&lt;/i&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;ialogo de captura #1: Donde capturas el primer número para la suma.&lt;/i&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwjEAwv2vbRRXIGJ6MIsKMMs5pWd-3j1554imjvXhFlsA39wdtS8uswZQ_Yr1KgVe8-LsbPSABnphuBj9Ru86SkS_dmLBgB2JPjrE_hMlXg_si_XSM1MJWsZZMhrSEC403SaeasDQPHUWs/s1600/Captura3_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwjEAwv2vbRRXIGJ6MIsKMMs5pWd-3j1554imjvXhFlsA39wdtS8uswZQ_Yr1KgVe8-LsbPSABnphuBj9Ru86SkS_dmLBgB2JPjrE_hMlXg_si_XSM1MJWsZZMhrSEC403SaeasDQPHUWs/s1600/Captura3_2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;&lt;i style=&quot;font-family: Verdana, sans-serif;&quot;&gt;D&lt;/i&gt;&lt;i style=&quot;font-family: Verdana, sans-serif;&quot;&gt;ialogo de captura #2: Donde capturas el segundo número para la suma.&lt;/i&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwRzgNtgztz6Tcv3Exb69DIXrlVAeJl0OxUpfDNem7TBScsWW-cRztsL9RyIPaW1vF68yfOPnKlKFDUfMaqCPrVrO5xNwlU9c8XOAPWtxMEAW0RUKZe0_b9nwFQlRl8rwHTU3aVy7i4Q77/s1600/Mensaje3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwRzgNtgztz6Tcv3Exb69DIXrlVAeJl0OxUpfDNem7TBScsWW-cRztsL9RyIPaW1vF68yfOPnKlKFDUfMaqCPrVrO5xNwlU9c8XOAPWtxMEAW0RUKZe0_b9nwFQlRl8rwHTU3aVy7i4Q77/s1600/Mensaje3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;&lt;i style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Dialogo de mensaje #1: Donde se muestra el resultado de la suma.&lt;/i&gt;&lt;br /&gt;
&lt;i style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/i&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu1Dg6NxMv4lpHEqw_zyMymCXb1r-LJ_7OTHQPjBDQEeUqcSPzORf3n9oeFiYW6yGIT50bWrb98IDVpO65A8gMSvkNdn2TxAunfZWmzTDpyEHv2Y818yzofuy7C_vvqELhfQVxdQSEa8jZ/s1600/MensajeError3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu1Dg6NxMv4lpHEqw_zyMymCXb1r-LJ_7OTHQPjBDQEeUqcSPzORf3n9oeFiYW6yGIT50bWrb98IDVpO65A8gMSvkNdn2TxAunfZWmzTDpyEHv2Y818yzofuy7C_vvqELhfQVxdQSEa8jZ/s1600/MensajeError3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;i style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Dialogo de mensaje #2: Lo que verás si capturas un texto.&lt;/i&gt;&lt;br /&gt;
&lt;i style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/i&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;¡Funciona! Cuando se usa como debe ser, claro, pero si lo miras y pruebas con atención, el código tiene muchas cosas que se pueden mejorar, ¿qué cambios le harías tú? Como siempre, siéntete libre de mejorar y experimentar con el código a tu gusto, ya que es la mejor forma de aprender y a mí me da flojera escribir tanto código :P.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
Espero hayan disfrutado leyendo mi primer entrada del año tanto como lo hice yo al escribirla, como siempre saben que cualquier duda, critica, comentario o sugerencia es bien aceptada en la parte donde pone &quot;Comentarios&quot;, no olviden dar &#39;like&#39; a la página de Facebook para que estén al tanto del blog, ya le daré más atención, se los prometo, saludos ;).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2013/10/como-utilizar-el-dialogo-de-pregunta-en.html&quot; target=&quot;_blank&quot;&gt;Cómo utilizar el dialogo de pregunta en Java (JOptionPane)&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/&quot;&gt;&lt;span id=&quot;goog_38194357&quot;&gt;&lt;/span&gt;Cómo mostrar un dialogo de mensaje en Java (JOptionPane)&lt;span id=&quot;goog_38194358&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/2068084893743985684/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2014/07/como-leer-la-captura-del-usuario-con-un.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/2068084893743985684'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/2068084893743985684'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2014/07/como-leer-la-captura-del-usuario-con-un.html' title='Como leer la captura del usuario con un dialogo en Java (JOptionPane)'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio2twLuTEMWjk_v-nc8nt71fPkxE4tGuO0wVPOfqhzcemudOkLk4aDyXU8E5tYb1iOgbhk2ifQCXC_VBMU08EevP5PfaQxUuFfUUPnhyphenhyphen01omwIrR8gQGz7Kg9Z25wDxXrtOhA7fg-9wEfr/s72-c/Captura1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-5208468728993447915</id><published>2013-10-08T11:14:00.001-07:00</published><updated>2013-10-08T11:14:58.359-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cómo mostrar un dialogo de pregunta en java"/><category scheme="http://www.blogger.com/atom/ns#" term="GUI Java"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Java SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="JOptionPane"/><category scheme="http://www.blogger.com/atom/ns#" term="Mensajes GUI Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Mensajes JOptionPane"/><category scheme="http://www.blogger.com/atom/ns#" term="Mensajes Sencillos GUI Java"/><title type='text'>Cómo utilizar el dialogo de pregunta en Java (JOptionPane)</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;



Hola y buen día a todos mis lectores, hoy me han dado ganas de escribir sobre un tema sencillo para algunos aquí, pero que igualmente puede resultar útil para muchos otros, los diálogos de pregunta, ésos pequeños diálogos que normalmente utilizamos para confirmar una acción del usuario, un ejemplo: En Windows, cuando estamos en la palera de reciclaje, al vaciarla siempre nos pregunta: “¿Estás seguro de eliminar estos elementos de forma permanente?” (Algo así) El caso es que ése es un dialogo de pregunta, a continuación veremos cómo utilizarlos en Java, pero antes, una imagen de lo que haremos:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFwXDtUjLpojVVyRmisTpVH2X81W1aOubkRhG94TgLeNjyNYfBeNMoWUz7aZ0P7W4sCOdPOPdMUm4qVvK-hEhqIzN645-B7yumlTN_kV6aTUMrygcTZbEQlEdypnx8wEsacHiilh0U_CSx/s1600/Dlg1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFwXDtUjLpojVVyRmisTpVH2X81W1aOubkRhG94TgLeNjyNYfBeNMoWUz7aZ0P7W4sCOdPOPdMUm4qVvK-hEhqIzN645-B7yumlTN_kV6aTUMrygcTZbEQlEdypnx8wEsacHiilh0U_CSx/s1600/Dlg1.png&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Ahora que tenemos un buen concepto de lo que es un dialogo de pregunta, veremos cómo hacer uno propio siguiendo el código de ejemplo a continuación, que sepan que no es la única (Y tal vez ni la mejor) forma de utilizar el dialogo, si tienen mejores formas de uso son muy bien recibidas en los comentarios, las publicaré en esta entrada para mejorarla (Obviamente dando el crédito a quién sugiera ésa forma de uso), pero por ahora, lo importante es que vean una de las muchas formas de utilizar el dialogo esperando que les sea de ayuda. Ahora sí, ahí les va el código:&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import javax.swing.JFrame;
import javax.swing.JOptionPane;
 
/***
 * Clase sencilla que se encarga de mostrar un dialogo de pregunta.
 * @author Gustavo Hernández Salinas
 */
public class DialogoPregunta {
 
 /**
  * Método estático que lanza un dialogo de pregunta,
  * con la posibilidad de cambiar el título del dialogo.
  * @param titulo - El título a poner en el dialogo.
  */
 public static void lanzarDialogo(String titulo){
  JFrame padre = new JFrame();
  
  //Representa la selección del usuario:
  int seleccion = JOptionPane.showOptionDialog(padre, //Ventana que lo maneja
    cargarTxtEtiqueta(), //Texto del dialogo.
    titulo,  //Título del dialogo.
    JOptionPane.YES_NO_OPTION, //Tipo de dialogo.
    JOptionPane.QUESTION_MESSAGE, //Tipo de mensaje.
    null, //No se usa ícono personalizado.
    cargarOpciones(), //Títulos de los botones.
    cargarOpciones()[0]); //El título del botón por default.
  
  //Si se ha seleccionado la opción afirmativa
  if (seleccion == JOptionPane.YES_OPTION) {
   //Hacemos lo siguiente:
   accionesAceptar();
   padre.dispose();
  }
  //Si se la seleccionado la opción negativa...
  else if (seleccion == JOptionPane.NO_OPTION) {
   //Cerramos la ventana y por lo tanto el dialogo también.
   padre.dispose();
  }
 }
 
 /**
  * Devuelve los textos que van dentro de los
  * botones del dialogo.
  * @return Las opciones del usuario.
  */
 private static Object[] cargarOpciones(){
  String opc1 = &quot;Aceptar&quot;;
  String opc2 = &quot;Cancelar&quot;;
  Object[] opciones = {opc1, opc2};
  return opciones;
 }
 
 /**
  * Representa lo que haremos si el usuario selecciona la opción afirmativa.
  */
 private static void accionesAceptar(){
  //Ponemos aquí las operaciones confirmadas por el usuario...
  //y mostramos un mensaje al realizarlas para informarlo (Opcional)
  JOptionPane.showMessageDialog(null, &quot;¡Acción realizada con éxito!&quot;);
 }
 
 /**
  * El texto que aparece en nuestro dialogo de pregunta, que por
  * lo general es (Oh sorpresa), la pregunta.
  * @return - El texto del dialogo.
  */
 private static String cargarTxtEtiqueta(){
  String texto = &quot;¿Está seguro de realizar ésta operación?&quot;;
  return texto;
 }
 
 public static void main(String[] args) {
  //Mostramos el dialogo llamando al siguiente método estático:
  DialogoPregunta.lanzarDialogo(&quot;Soy un dialogo de pregunta&quot;);
 }

}

]]&gt;&lt;/script&gt;



&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Como podemos ver, el código es realmente corto, se alarga al doble por que lo lleno de comentarios :P. Tal vez a algunos les parezcan demasiados comentarios, pero mejor que sobren a que falten ya que a veces son importantes para aclarar ciertas dudas.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Si corremos el código de arriba, veremos que al dar clic al botón &quot;Aceptar&quot; nos mostrará un dialogo como el siguiente:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0-DdGRCH8Dkxn4Jx51sFbPtr7tJMBH6FwFCsI9fx6HjiOgMjVZzN9RZ4rCT_MxGH9WbZRfOclKTvm17ZXVeRoVKBtUpaVU9YHT8k_jfcgFJJngLC-edztOE8denFfpyvpid9k54F3tk8k/s1600/Confirmado.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0-DdGRCH8Dkxn4Jx51sFbPtr7tJMBH6FwFCsI9fx6HjiOgMjVZzN9RZ4rCT_MxGH9WbZRfOclKTvm17ZXVeRoVKBtUpaVU9YHT8k_jfcgFJJngLC-edztOE8denFfpyvpid9k54F3tk8k/s1600/Confirmado.png&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Eso muestra muy bien la manera en que trabaja un dialogo de pregunta y cómo podemos utilizarlo.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Como ahora me parece que ésta entrada es muy corta, les ofrezco otro ejemplo muy bueno de uso, cambiando unas cuántas líneas del código anterior podemos tener un dialogo muy distinto y para otro propósito, aquí les va:&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import javax.swing.JFrame;
import javax.swing.JOptionPane;
 
/***
 * Clase sencilla que se encarga de mostrar un dialogo de pregunta.
 * @author Gustavo Hernández Salinas
 */
public class DialogoPregunta {
 
 /**
  * Método estático que lanza un dialogo de pregunta,
  * con la posibilidad de cambiar el título del dialogo.
  * @param titulo - El título a poner en el dialogo.
  */
 public static void lanzarDialogo(String titulo){
  JFrame padre = new JFrame();
  
  //Representa la selección del usuario:
  int seleccion = JOptionPane.showOptionDialog(padre, //Ventana que lo maneja
    cargarTxtEtiqueta(), //Texto del dialogo.
    titulo,  //Título del dialogo.
    JOptionPane.YES_NO_CANCEL_OPTION, //Otro tipo de dialogo.
    JOptionPane.WARNING_MESSAGE, //Otro tipo de mensaje.
    null, //No se usa ícono personalizado.
    cargarOpciones(), //Títulos de los botones.
    cargarOpciones()[0]); //El título del botón por default.
  
  //Si se ha seleccionado la opción afirmativa
  if (seleccion == JOptionPane.YES_OPTION) {
   //Hacemos lo siguiente:
   accionesAceptar();
   padre.dispose();
  }
  //Si se la seleccionado la opción negativa...
  else if (seleccion == JOptionPane.NO_OPTION) {
   //Cerramos la ventana y por lo tanto el dialogo también.
   padre.dispose();
  }
 }
 
 /**
  * Devuelve los textos que van dentro de los
  * botones del dialogo.
  * @return Las opciones del usuario.
  */
 private static Object[] cargarOpciones(){
  //Cambiamos las opciones y añadimos una más:
  String opc1 = &quot;Sí&quot;;
  String opc2 = &quot;No&quot;;
  String opc3 = &quot;Cancelar&quot;;
  Object[] opciones = {opc1, opc2, opc3};
  return opciones;
 }
 
 /**
  * Representa lo que haremos si el usuario selecciona la opción afirmativa.
  */
 private static void accionesAceptar(){
  //Ponemos aquí las operaciones confirmadas por el usuario...
  //y mostramos un mensaje al realizarlas para informarlo (Opcional)
  JOptionPane.showMessageDialog(null, &quot;¡Cambios guardados con éxito!&quot;);
 }
 
 /**
  * El texto que aparece en nuestro dialogo de pregunta, que por
  * lo general es (Oh sorpresa), la pregunta.
  * @return - El texto del dialogo.
  */
 private static String cargarTxtEtiqueta(){
  //Para hacer un salto de linea en el dialogo:
  String nl = System.getProperty(&quot;line.separator&quot;);
  String texto = &quot;Advertencia: No ha guardado los cambios.&quot; + nl + &quot;¿Desea guardarlos antes de salir?&quot;;
  return texto;
 }
 
 public static void main(String[] args) {
  //Mostramos el dialogo llamando al siguiente método estático:
  DialogoPregunta.lanzarDialogo(&quot;Soy un dialogo de pregunta&quot;);
 }

}

]]&gt;&lt;/script&gt;



&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Y el resultado es el siguiente:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIMf851tmGJCAp5847ZzO_tBfLgRyFTPDi2wdk5CnzcC6T1veTxKEFvxjx96w6SnzSITi2s1c14d00XJjl22aCz1NCXP3ykYZVwIlxNMRZzdyCTejeR_iBTws_inD5PPUaAvJ0lHzwdL84/s1600/Dlg2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIMf851tmGJCAp5847ZzO_tBfLgRyFTPDi2wdk5CnzcC6T1veTxKEFvxjx96w6SnzSITi2s1c14d00XJjl22aCz1NCXP3ykYZVwIlxNMRZzdyCTejeR_iBTws_inD5PPUaAvJ0lHzwdL84/s1600/Dlg2.png&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5DEgKviU9O8CSi2oVyr_SjPK7mrZW9MZW9weIJb6z7oid4s04zFm7waUOj7fjJpYva-5SHAswt3m8kfSHc6D60RReMipeICDflsrOyhUWbJgIcR_ThV-e-ilwR0_ARkUxcStgnuEQuQ2m/s1600/Confirmado2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5DEgKviU9O8CSi2oVyr_SjPK7mrZW9MZW9weIJb6z7oid4s04zFm7waUOj7fjJpYva-5SHAswt3m8kfSHc6D60RReMipeICDflsrOyhUWbJgIcR_ThV-e-ilwR0_ARkUxcStgnuEQuQ2m/s1600/Confirmado2.png&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;¿Qué les parece? Unos cuántos cambios al código y tenemos algo muy distinto, y si lo notaron, no hay ni necesidad de darle código al botón &quot;Cancelar&quot; si le damos clic a ése botón ahora nos daremos cuenta que el dialogo se cierra por &lt;i&gt;default&lt;/i&gt;, todo por la magia de JOptionPane. Como siempre, los invito a investigar y experimentar por su cuenta, les recomiendo hacer una copia del código original para no perderlo y así experimentar con la otra copia con toda seguridad de que si se equivocan, pueden volver al código anterior.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Como siempre mis queridos lectores, es un placer escribir para ustedes, si les gusta lo que hago suscríbanse en la parte de arriba, pueden unirse a la página de Facebook, o recibir las noticias del blog en su E-mail escribiéndolo dónde pone &quot;Noticias del Blog a tu E-Mail&quot;. Cualquier duda, aclaración, sugerencia o critica constructiva es bienvenida en los comentarios, saludos.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2013/04/como-mostrar-un-dialogo-de-mensaje-en.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;Cómo mostrar un dialogo de mensaje en Java (JOptionPane)&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/11/creando-una-gui-en-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;Como crear una GUI en Java&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/12/syntaxhighlighter.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;Como crear una GUI en Java - Parte 2&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/5208468728993447915/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2013/10/como-utilizar-el-dialogo-de-pregunta-en.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/5208468728993447915'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/5208468728993447915'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2013/10/como-utilizar-el-dialogo-de-pregunta-en.html' title='Cómo utilizar el dialogo de pregunta en Java (JOptionPane)'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFwXDtUjLpojVVyRmisTpVH2X81W1aOubkRhG94TgLeNjyNYfBeNMoWUz7aZ0P7W4sCOdPOPdMUm4qVvK-hEhqIzN645-B7yumlTN_kV6aTUMrygcTZbEQlEdypnx8wEsacHiilh0U_CSx/s72-c/Dlg1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-1016178400750873249</id><published>2013-08-15T14:38:00.000-07:00</published><updated>2013-08-17T19:37:10.483-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Como crear una GUI en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Crear GUI en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Crear GUI Java"/><category scheme="http://www.blogger.com/atom/ns#" term="ejemplos GUI en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="GUI Java"/><category scheme="http://www.blogger.com/atom/ns#" term="GUI SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Java SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="LF Java SWING"/><title type='text'>Cómo utilizar JInternalFrame</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;




Hola y buen día a todos mis lectores. Después de mucho tiempo sin publicar nada por aquí, he tenido la mejor de las motivaciones para hacerlo, dedico ésta entrada a la fan #1 del blog, jaja :P, mi chica linda: Mery, quien ha estado conmigo desde hace años y espero que eso siga así por mucho tiempo más, es la persona más especial que he tenido la suerte de conocer, como le digo siempre, es una en un millón :) y quería que todos lo supieran, ¡La adoro!.

Ahora sí, jaja, el tema de hoy: Cómo utilizar JInternalFrame, comencemos...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Les dejo a continuación una imagen de 2 JInternalFrames con distintos componentes en ellos:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdkYUs25hK9smEP11BQy8-yvZwSMn4fJs8qzAATsiCykmuejQ1Chtiz1Dq0Bwa5yXs47bGSE6XFjSf15oleVXMMJreeeuz4cMlGTj-Bcl9EIVtSt6NL5bNpSfCaQQYlWeSp1BxJKq0A9Df/s1600/ImgMuestra.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;271&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdkYUs25hK9smEP11BQy8-yvZwSMn4fJs8qzAATsiCykmuejQ1Chtiz1Dq0Bwa5yXs47bGSE6XFjSf15oleVXMMJreeeuz4cMlGTj-Bcl9EIVtSt6NL5bNpSfCaQQYlWeSp1BxJKq0A9Df/s320/ImgMuestra.png&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;El contenido de “Ventana Interna #1” no lo veremos en el ejemplo que daré aquí, es una creación propia y solo la puse para ilustrar la ventana interna con algo más complejo, además de que sería mucho código.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;¿Qué es un JInternalFrame y para qué nos puede servir?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Un JInternalFrame, es una ventana interna, algo diferente de un JFrame ya que va dentro de un panel especial que por lo general es un JDesktopPane y no puede salir de él. A un JInternalFrame podemos darle cualquier uso, los mismos que a cualquier JFrame, podría ser útil por ejemplo, si estamos desarrollando algún tipo de procesador de texto, para abrir varios documentos a la vez o formularios, etc. Veremos a continuación sus constructores y un ejemplo de uso.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Constructores de JInternalFrame:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;span style=&quot;color: orange;&quot;&gt;JInternalFrame()&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Crea un JInternalFrame no-reizable, no-closable, no-maximizable, no-iconifiable y sin título.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;span style=&quot;color: orange;&quot;&gt;JInternalFrame(String titulo)&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Crea un JInternalFrame no-reizable, no-closable, no-maximizable, no-iconifiable y con el título especificado.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;span style=&quot;color: orange;&quot;&gt;JInternalFrame(String titulo, boolean resizable)&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Crea un JInternalFrame no-closable, no-maximizable, no-iconifiable con el título y ‘resizability’ especificado.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;color: orange; font-family: Verdana, sans-serif;&quot;&gt;JInternalFrame(String titulo, boolean resizable, boolean closable)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Crea un JInternalFrame no-maximizable, no-iconifiable con el título, ‘resizability’ y ‘closability’ especificado.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;color: orange; font-family: Verdana, sans-serif;&quot;&gt;JInternalFrame(String titulo, boolean resizable, boolean closable, boolean maximizable)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Crea un JInternalFrame no-iconifiable con el título, ‘resizability’, ‘closability’ y ‘maximizability’ especificado.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;color: orange; font-family: Verdana, sans-serif;&quot;&gt;JInternalFrame(String titulo, boolean resizable, boolean closable, boolean maximizable, boolean iconifiable)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Crea un JInternalFrame con el título, ‘resizability’, ‘closability’, ‘maximizability’ y ‘iconifiability’ especificado.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;Nota:&lt;/b&gt; Dejo los argumentos en inglés porque cuando buscas el método no vas a buscar por ‘setCerrable’ o algo así.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Ejemplo de uso&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;A continuación veremos un ejemplo sencillo de uso del JInternalFrame, simplemente mostraremos un par de ventanas internas y les agregaremos algunos componentes para ver qué tal se ven.&lt;br /&gt;&lt;br /&gt;Para el ejemplo yo utilicé 2 clases dentro de un mismo fichero, esto con la idea de no complicarnos tanto, aquí les va:&lt;br /&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

/**
 * Sencilla clase que demuestra como utilizar un JInternalFrame.
 */
final class InternalFrameDemo extends JFrame{
 private static final long serialVersionUID = 1L;
 JDesktopPane desktop; //Contendrá los JInternalFrames.
 
 /**
  * Crea la ventana de demostración de JInternalFrame.
  * @param tit - El título de la ventana de demostración.
  */
 public InternalFrameDemo(String tit) {
  super(tit);
  desktop = new JDesktopPane(); //Un panel especializado.
  setContentPane(desktop);
  /**
   *No sé a ustedes, pero a mí me sale con fondo blanco
   *y no me gusta, por eso le puse otro color, esto es 
   *opcional ;) 
   */
  desktop.setBackground(Color.LIGHT_GRAY);
 }
 
 /**
  * Crea una ventana interna (JInternalFrame) añadiendo
  * el componente y título pasados como argumento.
  * @param comp - El componente a añadir a la ventana.
  * @param tit - El título de la ventana.
  */
 protected void crearVentana(JComponent comp, String tit) {
  //Clase que es creada más abajo:
  MiInternalFrame interna = new MiInternalFrame(comp, tit);
  desktop.add(interna); //Añadimos la ventana interna al JFrame
  
  try {
   interna.setSelected(true);
  }
  catch (java.beans.PropertyVetoException e){
   e.printStackTrace(); //En caso de error...
  }
 }
 
 /**
  * Crea y devuelve un panel con algunos componentes con 
  * el propósito de mostrarlo una ventana interna. 
  * @return - El panel con los componentes a mostrar.
  */
 protected static JPanel crearContenido(){
  JPanel panel = new JPanel(new FlowLayout());
  panel.add(new JLabel(&quot;Etiqueta de muestra&quot;));
  panel.add(new JButton(&quot;Botón De Muestra&quot;));
  panel.add(new JTextField(&quot;Campo de muestra&quot;));
  panel.add(new JCheckBox(&quot;Casilla de muestra&quot;));
  panel.add(new JRadioButton(&quot;Botón de radio de muestra&quot;));
  return panel;
 }
 
 public static void main(String[] args) {
  //Instanciamos el demo y damos un título a la ventana...
  InternalFrameDemo ifd = new InternalFrameDemo(&quot;Cómo usar JInternalFrame - El Blog de Baro&quot;);
  ifd.setDefaultCloseOperation(EXIT_ON_CLOSE);
  //Creamos las ventanas:
  ifd.crearVentana(crearContenido(), &quot;Ventana Interna #1&quot;);
  ifd.crearVentana(crearContenido(), &quot;Ventana Interna #2&quot;);
  //Tamaño y locación (null = centro):
  ifd.setSize(800, 500);
  ifd.setLocationRelativeTo(null);
  //Mostramos la ventana:
  ifd.setVisible(true);
 }

}


/**
 * Clase sencilla que se encarga de externder una ventana interna.
 */
class MiInternalFrame extends JInternalFrame{
 private static final long serialVersionUID = 1L;
 //Contador estático que aumenta cada que instanciamos una ventana.
 static int openFrameCount = 1;
 //Para posicionar la ventana interna:
 static final int xOffset = 50, yOffset = 50;
 static int posX = 0, posY = 0;
 
 /**
  * Construye una ventana interna, añadiendo el componente
  * y título pasados como argumento.
  * @param comp - El componente a añadir.
  * @param titulo - El título para la vetana.
  */
 public MiInternalFrame(JComponent comp, String titulo) {
  super(titulo,
    true, //Resizable
    true, //Closable
    true, //Maximizable
    true);//Iconifiable
  
  //Aumentamos el conteo de ventanas.
  openFrameCount ++;
  //Añadimos el componente a la ventana interna.
  add(comp);
  pack();
  setVisible(true);
  //Ponemos la locación de la ventana.
  setLocation(posX, posY);
  //Operación sencilla para posicionar un poco más abajo la siguiente ventana:
  posX = xOffset*openFrameCount;
  posY = yOffset*openFrameCount;
 }
 
}
]]&gt;&lt;/script&gt;



&lt;br /&gt;Y ahora veremos al correr el código dos ventanas internas, pero podemos crear tantas como queramos, aquí algunas imágenes del resultado:&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRUHq5ahrfLB7zgbCNCq74okDwdrIspCvjnGB2FcULurLRQAoqslQTq3fUo8dlJt0deVpqjiExLHO9bpVeGcVdShJav8gbiy83ZjiRynZvMbLdpGjm_zamtY7Cac67kevcqrPOEQIodXi1/s1600/Img0.png&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRUHq5ahrfLB7zgbCNCq74okDwdrIspCvjnGB2FcULurLRQAoqslQTq3fUo8dlJt0deVpqjiExLHO9bpVeGcVdShJav8gbiy83ZjiRynZvMbLdpGjm_zamtY7Cac67kevcqrPOEQIodXi1/s320/Img0.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Al correr el código veremos las ventanas así.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn8wZVBhKMkoyQVA2RPMjwol5FVFSJhF6UsHE6w6Pj5xcKs4yTPw5fUhPyZ1ynlCUwpLUbW6V_k_pduR3ru-IKQQLQR9Diz3mZPM1N__SYx82DgSNcz62sqpcLxat93QEJbKyokSa0gZAR/s1600/Img1.png&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn8wZVBhKMkoyQVA2RPMjwol5FVFSJhF6UsHE6w6Pj5xcKs4yTPw5fUhPyZ1ynlCUwpLUbW6V_k_pduR3ru-IKQQLQR9Diz3mZPM1N__SYx82DgSNcz62sqpcLxat93QEJbKyokSa0gZAR/s320/Img1.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Cambio de tamaño de la ventana #2.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNFSfyUMtnKKFa2BlE8yYpv0Iu5EJYOSzsONZrchyphenhyphen0ARMqXpwi6J5af23wB0prlGWxeuOFVqMO-cALQPDSYJ_f_NGTPT67F8XucYAbE4aswwkSfsQNcpgFZ8CseE4ivdSXQWd-tpA5thpd/s1600/Img2.png&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNFSfyUMtnKKFa2BlE8yYpv0Iu5EJYOSzsONZrchyphenhyphen0ARMqXpwi6J5af23wB0prlGWxeuOFVqMO-cALQPDSYJ_f_NGTPT67F8XucYAbE4aswwkSfsQNcpgFZ8CseE4ivdSXQWd-tpA5thpd/s320/Img2.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Minimizamos la ventana #2.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLeyTft4AJdQrvGBmNW2BHTvZB-fHgWXLkTGQoscz7rSFgC8QiujR_UCWlUPrD5M4EZ3tRO4FJQpLQQmDQoiT1AmmIhrFlEQr0Su-N3w7Z-nLBSHPeOE18S4iaoE93h5h5U5ZxeCCVcyTL/s1600/Img3.png&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLeyTft4AJdQrvGBmNW2BHTvZB-fHgWXLkTGQoscz7rSFgC8QiujR_UCWlUPrD5M4EZ3tRO4FJQpLQQmDQoiT1AmmIhrFlEQr0Su-N3w7Z-nLBSHPeOE18S4iaoE93h5h5U5ZxeCCVcyTL/s320/Img3.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Maximizamos la ventana #1 (Nótese que ha dejado de verse la #2).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKqCV3h59Ug1bq3w_NHFufp4qdpKjkTcq0Ze-2TrlKYv_bX42RGhgUkHqjRA7vNGIfXtjM9JQ3-rx4D7A5cV_C9Kk5Kx6qfg5c1iqZ4JhuCfRm7ZMSZcCPxiQJcNUJ81O0mrjf03ld4Uve/s1600/Img4.png&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKqCV3h59Ug1bq3w_NHFufp4qdpKjkTcq0Ze-2TrlKYv_bX42RGhgUkHqjRA7vNGIfXtjM9JQ3-rx4D7A5cV_C9Kk5Kx6qfg5c1iqZ4JhuCfRm7ZMSZcCPxiQJcNUJ81O0mrjf03ld4Uve/s320/Img4.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Minimizamos ambas ventanas.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Si quieren aprender más sobre cómo utilizar JInternalFrame, les dejo aquí la &lt;a href=&quot;http://docs.oracle.com/javase/7/docs/api/javax/swing/JInternalFrame.html&quot; target=&quot;_blank&quot;&gt;documentación oficial&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Bien, esto ha sido todo por hoy, espero les haya sido útil, ya saben, dudas, comentarios, críticas constructivas o lo que quieran en los comentarios, un gusto escribir para ustedes. Mery, si lograste llegar hasta el final del artículo sin dormirte, te mando un beso :* jaja y si no también :).&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2013/04/como-mostrar-un-dialogo-de-mensaje-en.html&quot; target=&quot;_blank&quot;&gt;Cómo mostrar un dialogo de mensaje en Java&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/11/creando-una-gui-en-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Cómo crear una GUI en Java&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/12/syntaxhighlighter.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Cómo crear una GUI en Java - Parte 2&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2013/01/como-usar-look-and-feel-en-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Cómo usar Look And Feel en Java&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/1016178400750873249/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2013/08/como-utilizar-jinternalframe.html#comment-form' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/1016178400750873249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/1016178400750873249'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2013/08/como-utilizar-jinternalframe.html' title='Cómo utilizar JInternalFrame'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdkYUs25hK9smEP11BQy8-yvZwSMn4fJs8qzAATsiCykmuejQ1Chtiz1Dq0Bwa5yXs47bGSE6XFjSf15oleVXMMJreeeuz4cMlGTj-Bcl9EIVtSt6NL5bNpSfCaQQYlWeSp1BxJKq0A9Df/s72-c/ImgMuestra.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-1433050046601445598</id><published>2013-04-23T11:28:00.001-07:00</published><updated>2013-04-25T20:11:54.199-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Como mostrar un dialogo de mensaje en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Crear GUI en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="GUI SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Java SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="JOptionPane"/><category scheme="http://www.blogger.com/atom/ns#" term="Mensajes GUI Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Mensajes JOptionPane"/><category scheme="http://www.blogger.com/atom/ns#" term="Mensajes Sencillos GUI Java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><title type='text'>Cómo mostrar un dialogo de mensaje en Java (JOptionPane)</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;



Hola y buen día a todos mis lectores, hoy veremos de nuevo un tema para principiantes en lenguaje Java, y el tema (como dice ahí arriba) es “Cómo mostrar un dialogo de mensaje en Java” para logra tal cosa usaremos la clase JOptionPane. Aquí abajo hay una imagen que muestra lo que haremos más adelante, comencemos…&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_yo9lHhbtQP8bjC3O3JyGaio6lTKv2GNslTfICddAyOU7nDFlqBKn0vqXXmAR4NT3EmnB5eqNomfndJAM-gq3KZKz2IeAfe955AXh-2BdiDTMk-NGMMLYuI6r_Yli1qPXoPKb0BrYxI5t/s1600/TiposMensaje.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;289&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_yo9lHhbtQP8bjC3O3JyGaio6lTKv2GNslTfICddAyOU7nDFlqBKn0vqXXmAR4NT3EmnB5eqNomfndJAM-gq3KZKz2IeAfe955AXh-2BdiDTMk-NGMMLYuI6r_Yli1qPXoPKb0BrYxI5t/s320/TiposMensaje.png&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Dentro de la programación, la comunicación con el usuario es una de las cosas más importantes (y a mi parecer la más importante, ya que es el fin de cualquier programa), anteriormente ya habíamos hablado de eso en &lt;a href=&quot;http://baro3495.blogspot.mx/2012/11/creando-una-gui-en-java.html&quot; target=&quot;_blank&quot;&gt;otro de mis artículos&lt;/a&gt;, pero hoy nos centraremos específicamente en cómo mostrar diferentes tipos de mensajes, ya sea un simple aviso, un mensaje de error, de advertencia, pregunta, etc.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Mostrando un mensaje simple en la pantalla&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Si lo que queremos es mostrar un mensaje de una línea fácil y rápido, aquí les va la solución:&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import javax.swing.JOptionPane;

public final class Mensajes {
 
 /**
  * Lanza un dialogo de mensaje de una línea:
  */
 public static void lanzarMensaje(){
  //En la siguiente línea está la magia (es lo que muestra el mensaje).
  JOptionPane.showMessageDialog(null, &quot;¡Hola mundo!&quot;);
 }
 
 public static void main(String[] args){
  lanzarMensaje();
 }
 
}
]]&gt;&lt;/script&gt;



&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Y lo que tenemos es:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgguTcODqT8sbbMxXHzbytvfTABXdJVdOpoCo3ftbwL_lBI5x_29JTKR5MAfG9ZoJsauSEq8IJKHG5uzBbHrnpJpgqJ9sUc4K1iYLh6VutMi6mpstu4Wjp6HAb5Ju1PUDWOJdHutGYjv6an/s1600/Msj1.bmp&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgguTcODqT8sbbMxXHzbytvfTABXdJVdOpoCo3ftbwL_lBI5x_29JTKR5MAfG9ZoJsauSEq8IJKHG5uzBbHrnpJpgqJ9sUc4K1iYLh6VutMi6mpstu4Wjp6HAb5Ju1PUDWOJdHutGYjv6an/s1600/Msj1.bmp&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Sencillo, ¿verdad? Como vieron, esto va dentro de algún método ya sea el &lt;i&gt;main&lt;/i&gt; o cualquier otro, un constructor, lo que sea. Ahora, veamos algo un poco mejor, ¿y qué es mejor que un mensaje de una línea? Pues un mensaje de 2 líneas :D (o las que queramos).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para mostrar un dialogo de varias líneas, necesitamos un salto de línea, para esto, llamaremos a una propiedad del sistema, esto será tal como dar &lt;i&gt;\n&lt;/i&gt; en C++ y en Java es también válido, pero esta no es la forma más extensible de hacerlo ¿Por qué? Pues recordemos que Java es multiplataforma, puede que no en todos los sistemas operativos tomen esto como un salto de línea, en algunos es algo como &lt;i&gt;\n\r&lt;/i&gt; o dependiendo, así que para no complicarnos, lo haremos de la siguiente manera:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Mostrando un mensaje de varias líneas:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import javax.swing.JOptionPane;

public final class Mensajes {

 /**
  * Lanza un dialogo de mensaje de una línea:
  */
 public static void lanzarMensaje(){
  //En la siguiente línea está la magia (es lo que muestra el mensaje).
  JOptionPane.showMessageDialog(null, &quot;¡Hola mundo!&quot;);
 }
 
 /**
  * Lanza un dialogo de varias líneas:
  */
 public static void lanzarMensajeVariasLíneas(){
  //Propiedad del sistema para salto de línea:
  String nl = System.getProperty(&quot;line.separator&quot;);
  //Lanzamos el mensaje:
  JOptionPane.showMessageDialog(null, &quot;Soy un mensaje&quot;
    + nl + &quot;de varias líneas...&quot;
    + nl + &quot;Y esto lo viste en el Blog de Baro :D.&quot;);
 }
 
 public static void main(String[] args){
  lanzarMensajeVariasLíneas();
 }
 
}
]]&gt;&lt;/script&gt;



&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Y el resultado es:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrnFR20RbZVdn4FDw1LiCUHFIM7xDyi7bwAIh9A95UpbUZBAQ3mTJ3ROf0FE-EqclT7-RULOz_5dFpDTYwgau6kPCgGZ0iCpZeiROtbgHvyrYlXWi8Z9j1IH9vhRZKpKsBsycNUUa2gBo8/s1600/Msj2.bmp&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrnFR20RbZVdn4FDw1LiCUHFIM7xDyi7bwAIh9A95UpbUZBAQ3mTJ3ROf0FE-EqclT7-RULOz_5dFpDTYwgau6kPCgGZ0iCpZeiROtbgHvyrYlXWi8Z9j1IH9vhRZKpKsBsycNUUa2gBo8/s1600/Msj2.bmp&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora, esos son mensajes sencillos, muy útiles claro, pero &lt;i&gt;JOptionPane&lt;/i&gt; (la clase que estamos usando) tiene aún muchos trucos bajo la manga, podemos hacer muchos tipos de diálogos de manera sencilla, como por ejemplo:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Dialogo de confirmación (Hace una pregunta de confirmación como Sí, No, Cancelar).&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Dialogo de entrada (Solicita alguna entrada al usuario).&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Dialogo de mensaje (Le comunica al usuario algo que ha pasado).&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Dialogo de opción (Es la unificación de los otros tres).&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Éstos diálogos pueden mostrarse también en un &lt;i&gt;JInternalFrame&lt;/i&gt;, con su respectivo método &lt;i&gt;showInternalXXX()&lt;/i&gt; pero ése no es el tema de hoy, lo veremos luego.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora, hemos utilizado ya el dialogo de mensaje más simple con el método &lt;i&gt;showMessageDialog(Component comp, Object msj)&lt;/i&gt; de &lt;i&gt;JOptionPane&lt;/i&gt; mostramos mensajes de una y varias líneas, pero, si quieren hacer algo un poco más complejo con estos diálogos aquí les van los otros 2 métodos de &lt;i&gt;JOptionPane&lt;/i&gt; para mostrar diálogos de mensaje:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;showMessageDialog(Component comp, Object mensaje, String titulo, int tipoMensaje)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;showMessageDialog(Component comp, Object mensaje, String titulo, int tipoMensaje, Icon icon)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El primer método, pide el “componente padre” (&lt;i&gt;Component&lt;/i&gt;), en caso de que llamemos al dialogo desde un &lt;i&gt;JFrame&lt;/i&gt; o un &lt;i&gt;JPanel&lt;/i&gt;, podemos ponerlo como argumento, luego nos pide el mensaje (&lt;i&gt;Object&lt;/i&gt;), ya hemos visto como se utiliza para mostrar una línea o varias, después pide el título (&lt;i&gt;String&lt;/i&gt;) donde ponemos el título del dialogo a nuestro gusto (por si alguno todavía no se daban cuenta para qué era :P) luego el tipo de mensaje (&lt;i&gt;int&lt;/i&gt;), esto es lo interesante, aquí podemos poner una de las constantes que ofrece &lt;i&gt;JOptionPane&lt;/i&gt; para cambiar el icono que aparece a la izquierda del dialogo, las constantes son: &lt;i&gt;PLAIN_MESSAGE&lt;/i&gt;, &amp;nbsp;&lt;i&gt;INFORMATION_MESSAGE&lt;/i&gt;, &lt;i&gt;QUESTION_MESSAGE&lt;/i&gt;, &lt;i&gt;ERROR_MESSAGE&lt;/i&gt; y &lt;i&gt;WARNING_MESSAGE&lt;/i&gt;, a continuación la imagen del icono que vamos a cambiar:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhubauJF7OUzF-B347TY6kmW9s2b4yDQuMxEh4zGTTfaWrae_qOA8VLOJ5LXfC40zhsE08kYRpyGBu2QuUXbLmTjw0_Vmkqcnc4gFFPdfq-7a4A8V7vv4MH6fhKJDD2YYb_sUTlTQ0HsXlT/s1600/Msj3.bmp&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhubauJF7OUzF-B347TY6kmW9s2b4yDQuMxEh4zGTTfaWrae_qOA8VLOJ5LXfC40zhsE08kYRpyGBu2QuUXbLmTjw0_Vmkqcnc4gFFPdfq-7a4A8V7vv4MH6fhKJDD2YYb_sUTlTQ0HsXlT/s1600/Msj3.bmp&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Y ahora un ejemplo de uso en la clase con la que hemos estado trabajando:&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import javax.swing.JOptionPane;

public final class Mensajes {
 
 /**
  * Lanza un dialogo de mensaje de una línea:
  */
 public static void lanzarMensaje(){
  //En la siguiente línea está la magia (es lo que muestra el mensaje).
  JOptionPane.showMessageDialog(null, &quot;¡Hola mundo!&quot;);
 }
 
 /**
  * Lanza un dialogo de varias líneas:
  */
 public static void lanzarMensajeVariasLíneas(){
  //Propiedad del sistema para salto de línea:
  String nl = System.getProperty(&quot;line.separator&quot;);
  //Lanzamos el mensaje:
  JOptionPane.showMessageDialog(null, &quot;Soy un mensaje&quot;
    + nl + &quot;de varias líneas...&quot;
    + nl + &quot;Y esto lo viste en el Blog de Baro :D.&quot;);
 }
 
 /**
  * Lanza varios dialogos con diferentes tipos de ícono.
  */
 public static void lanzarTiposDeMensaje(){
  //Propiedad del sistema para salto de línea:
  String nl = System.getProperty(&quot;line.separator&quot;);
  //Mensaje (lo usaremos en todos los dialogos):
  Object msj = &quot;Soy un mensaje&quot;
   + nl + &quot;de varias líneas...&quot;
   + nl + &quot;Y esto lo viste en el Blog de Baro :D.&quot;;
  
  /*
   * Pongo cada argumento en diferente línea para
   * que no se haga muy largo y el código esté
   * más ordenado: 
   */
  JOptionPane.showMessageDialog(null, 
    msj, //Mensaje
    &quot;Mensaje Plano&quot;, //Título 
    JOptionPane.PLAIN_MESSAGE); //Tipo de mensaje
  
  JOptionPane.showMessageDialog(null, 
    msj, //Mensaje
    &quot;Mensaje Informativo&quot;, //Título 
    JOptionPane.INFORMATION_MESSAGE); //Tipo de mensaje
  
  JOptionPane.showMessageDialog(null, 
    msj, //Mensaje
    &quot;Mensaje de Pregunta&quot;, //Título 
    JOptionPane.QUESTION_MESSAGE); //Tipo de mensaje
  
  JOptionPane.showMessageDialog(null, 
    msj, //Mensaje
    &quot;Mensaje de Error&quot;, //Título 
    JOptionPane.ERROR_MESSAGE); //Tipo de mensaje
  
  JOptionPane.showMessageDialog(null, 
    msj, //Mensaje
    &quot;Mensaje de Advertencia&quot;, //Título 
    JOptionPane.WARNING_MESSAGE); //Tipo de mensaje
 }
 
 public static void main(String[] args){
  lanzarTiposDeMensaje();
 }
 
}
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Al correr este código veremos 5 mensajes de dialogo (se muestra el siguiente dando click al botón “&lt;i&gt;Aceptar&lt;/i&gt;”) con diferente icono, como se muestra en la siguiente imagen (Sin el bonito fondo verde ni el texto obviamente :P)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIPFOkU3hVjCoOf2q5ziUxGe3oUxOclc3p00BLXUM0fYjN8SLBUyrEUS2RZIJePawm-zrLAAh_R4cOi30JU8uGcUBxJVDojMjC9EKq_diz8zurXYGwcRUbxmANuburCO9khdp44bMl75c7/s1600/TiposMensaje.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;289&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIPFOkU3hVjCoOf2q5ziUxGe3oUxOclc3p00BLXUM0fYjN8SLBUyrEUS2RZIJePawm-zrLAAh_R4cOi30JU8uGcUBxJVDojMjC9EKq_diz8zurXYGwcRUbxmANuburCO9khdp44bMl75c7/s320/TiposMensaje.png&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El segundo método que enlistamos pide lo mismo que el primero pero además podemos poner un ícono a nuestro gusto en el último argumento (&lt;i&gt;Icon&lt;/i&gt;), en lugar de uno de los que ya vienen por parte de &lt;i&gt;JOptionPane&lt;/i&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Me gustaría extenderme más en el uso de &lt;i&gt;JOptionPane&lt;/i&gt; para ver los demás diálogos, como el de pregunta (muy útil) o los de entrada, pero me saldría un poco del tema de los mensajes así que si quieren saber más sobre estos&amp;nbsp;diálogos&amp;nbsp;les dejo la &lt;a href=&quot;http://docs.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html&quot; target=&quot;_blank&quot;&gt;documentación de &lt;i&gt;JOptionPane&lt;/i&gt; aquí&lt;/a&gt; para que experimenten por su cuenta, o esperen mi siguiente entrada, encantado de escribir para ustedes ;), saludos.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;Entradas Relacionadas:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/11/creando-una-gui-en-java.html&quot; target=&quot;_blank&quot;&gt;Cómo crear una GUI en Java&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/12/syntaxhighlighter.html&quot; target=&quot;_blank&quot;&gt;Cómo crear una GUI en Java - Parte 2&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-1.html&quot; target=&quot;_blank&quot;&gt;Aprender Java Creando un juego&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/1433050046601445598/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2013/04/como-mostrar-un-dialogo-de-mensaje-en.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/1433050046601445598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/1433050046601445598'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2013/04/como-mostrar-un-dialogo-de-mensaje-en.html' title='Cómo mostrar un dialogo de mensaje en Java (JOptionPane)'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_yo9lHhbtQP8bjC3O3JyGaio6lTKv2GNslTfICddAyOU7nDFlqBKn0vqXXmAR4NT3EmnB5eqNomfndJAM-gq3KZKz2IeAfe955AXh-2BdiDTMk-NGMMLYuI6r_Yli1qPXoPKb0BrYxI5t/s72-c/TiposMensaje.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-7079949787040010487</id><published>2013-03-12T21:49:00.000-07:00</published><updated>2013-03-12T21:49:57.066-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Crear una clase Java Eclipse IDE"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse ide"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Java y Eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><title type='text'>Cómo crear una clase Java en Eclipse IDE</title><content type='html'>&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hola y buen día a todos mis lectores, hoy, volvemos al génesis de la programación en Java, que son las clases, para muchos de ustedes, crear una clase en Java con Eclipse IDE, es algo de lo más simple, pero hoy me voy a centrar en los principiantes, todos lo hemos sido alguna vez :P, así que aquí vamos…&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwX0AHMfSsbs8Tc7A5BST7jqpEbZwfG_Je77fzwbRNdcO08y7HYz7JPx2yVQpRM1p0g4zNPni5CnjS3VFEharzlflUATyriMN2HC65YkmL1e8J1sixSOpvT4OznUvBbX7D5qdUq1Qo06gJ/s1600/Clase-Objeto.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;240&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwX0AHMfSsbs8Tc7A5BST7jqpEbZwfG_Je77fzwbRNdcO08y7HYz7JPx2yVQpRM1p0g4zNPni5CnjS3VFEharzlflUATyriMN2HC65YkmL1e8J1sixSOpvT4OznUvBbX7D5qdUq1Qo06gJ/s320/Clase-Objeto.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Como siempre, primero veremos algunas definiciones, para tener todo bien claro sobre las clases en Java antes de crear una, veremos también algunos ejemplos, ahí van:&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¿Qué es una clase en Java?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Aquí les traigo una buena definición:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Desde un punto de vista simplista, una clase es un conjunto de valores (atributos) junto con las funciones y procedimientos que operan sobre los mismos (métodos), todo ello tratado como una entidad. Estas clases constituyen los bloques principales en los cuales se encuentra contenido el código.&lt;br /&gt;En un fichero fuente puede declararse una o más clases:&lt;br /&gt;&lt;b&gt;class Clase1 {&lt;/b&gt;&lt;b&gt;…&lt;/b&gt;&lt;b&gt;}&lt;/b&gt;&lt;b&gt;class Clase2 {&lt;/b&gt;&lt;b&gt;…&lt;/b&gt;&lt;b&gt;}&lt;/b&gt;&lt;b&gt;…&lt;/b&gt;&lt;b&gt;class ClaseN {&lt;/b&gt;&lt;b&gt;…&lt;/b&gt;&lt;b&gt;}&lt;/b&gt;&lt;br /&gt;El cuerpo de las clases comienza con una llave abierta ({) y termina con una llave cerrada (}).&lt;br /&gt;Declaración de clase {&lt;br /&gt;Cuerpo de clase&lt;br /&gt;}&lt;br /&gt;La declaración de una clase define un tipo de dato referencial.&lt;br /&gt;Dentro del cuerpo de la clase se declaran los atributos de la clase y los métodos.&lt;/span&gt;&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Bueno, creo que con eso tenemos una idea bastante clara de lo que es una clase en Java, ahora, veremos cómo crear una en Eclipse IDE. Pero antes hay algo que casi olvidaba, hay que tener antes nuestro respectivo proyecto y paquete donde pondremos nuestra clase dentro, eso es algo sencillo, lo explicaré también a continuación, ahí vamos:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para crear un proyecto abrimos Eclipse IDE, y nos vamos a &lt;i&gt;File -&amp;gt; New -&amp;gt; Java Proyect&lt;/i&gt; Tal como se muestra a continuación:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFQtVLUlZCtnaLhMDIE_X9yXX22BvLo8x5KDjTPiY5oDw4JsxFluDbrMvcW8TAZOiRw487CfhPNHUPthVvI3cI77C5Ru7IkJfioODtIbxRlppnMa5TUAuAXk2GGLghRQw3qz-ocupjWFfM/s1600/Proyecto1.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFQtVLUlZCtnaLhMDIE_X9yXX22BvLo8x5KDjTPiY5oDw4JsxFluDbrMvcW8TAZOiRw487CfhPNHUPthVvI3cI77C5Ru7IkJfioODtIbxRlppnMa5TUAuAXk2GGLghRQw3qz-ocupjWFfM/s320/Proyecto1.JPG&quot; width=&quot;224&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora veremos una ventana que nos pide el nombre de proyecto como se muestra en la imagen de abajo, simplemente le damos un nombre a nuestro gusto y luego click en &lt;i&gt;Finish&lt;/i&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-Hq4kNKVdlrz8XhYPyDBjLaQ8ac0PoGb-IwywvTe4hyphenhyphen6F1eB4eoZ-gDact6sTnMvb2QwQtN4ofVkYkRvgkZ2JFp6jXdBaDfuSsfjZNvT0n1-Xo7G6khR0_57umHRWcZRsG2NXQlM6QzVm/s1600/Proyecto2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-Hq4kNKVdlrz8XhYPyDBjLaQ8ac0PoGb-IwywvTe4hyphenhyphen6F1eB4eoZ-gDact6sTnMvb2QwQtN4ofVkYkRvgkZ2JFp6jXdBaDfuSsfjZNvT0n1-Xo7G6khR0_57umHRWcZRsG2NXQlM6QzVm/s320/Proyecto2.JPG&quot; width=&quot;241&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Así de fácil, tenemos un proyecto, ahora lo que sigue es crear un paquete/paquetes que contenga las clases que hagamos, podemos hacer tantos como queramos y por lo general, el nombre del mismo se relaciona con lo que hacen las clases dentro de él, he aquí algunos ejemplos: “&lt;i&gt;compras&lt;/i&gt;”, “&lt;i&gt;ventas&lt;/i&gt;”, “&lt;i&gt;ventas.interfaz&lt;/i&gt;”, “&lt;i&gt;compras.interfaz&lt;/i&gt;”, “&lt;i&gt;compras.interfaz.acciones&lt;/i&gt;”, etc.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para crear un paquete dentro de nuestro proyecto simplemente damos click al nombre de nuestro proyecto y posteriormente click al ícono del paquete (encerrado en rojo) como se muestra en la siguiente imagen:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizJVU1UdmdEHKVhl7ZJAsZzV5O0hOzX0Ulzlrw3poKENcaJeVXepEZhBqt8lsPoBLdJmVeQLrjMvtggDG_0WencWEuHtJ03YBxHzES4ay4L9lMyHJhfr_2tgVU9BFwAlWTNCSm-B2ZSM8u/s1600/Proyecto3.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;123&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizJVU1UdmdEHKVhl7ZJAsZzV5O0hOzX0Ulzlrw3poKENcaJeVXepEZhBqt8lsPoBLdJmVeQLrjMvtggDG_0WencWEuHtJ03YBxHzES4ay4L9lMyHJhfr_2tgVU9BFwAlWTNCSm-B2ZSM8u/s320/Proyecto3.JPG&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Veremos una ventana que nos pide el nombre del paquete, de nuevo, podemos darle el nombre que queramos, siempre y cuando tomemos en cuenta ciertos criterios, como no iniciar el nombre con mayúscula, no iniciarlo con puntuaciones, etc. De todas formas la ventana donde creamos el paquete nos avisa si hicimos algo mal, al finalizar damos click en el botón &lt;i&gt;Finish&lt;/i&gt; aquí se les muestro la ventana:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibONx_zcMJPmolZO_WiRZQSnM_LbliFZFJjWZETLpuKx3DlYJdienJXouz3kIeiKHzaGyXT6uzaXRxwxT-oYR4ME5ao-Vwmm-h16Bo7PkBIBJoRqNmv4j92h-qZv0Ki96RUgTO3BJLSDpO/s1600/Proyecto4.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibONx_zcMJPmolZO_WiRZQSnM_LbliFZFJjWZETLpuKx3DlYJdienJXouz3kIeiKHzaGyXT6uzaXRxwxT-oYR4ME5ao-Vwmm-h16Bo7PkBIBJoRqNmv4j92h-qZv0Ki96RUgTO3BJLSDpO/s320/Proyecto4.JPG&quot; width=&quot;307&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Y listo, veremos que en nuestro proyecto aparece un ícono de paquete blanco, indicando con ese color que está vacío, pero se cambia a café al crear una clase dentro de él, que es justo lo que veremos a continuación (ahora sí).&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Primero que nada, para crear una clase, tenemos que darle una ubicación, eso es, un paquete, entonces, seleccionamos el paquete creado y entonces damos click en el ícono verde con la C blanca de clase como se encierra en rojo en la imagen a continuación:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH65d8XjVKy3JBIwt6wktKeoLeSAY0coENHrtewJkxlfj6mvtIbRpzZxSLYxQUEep6Hk2Vvck4wjY8sfl7igZpcYE5CF_fsYEDUrJVO9NU41MTpLeH3beYnDlhv2G14qQSlu8H54-kFLrd/s1600/Proyecto5.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;154&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH65d8XjVKy3JBIwt6wktKeoLeSAY0coENHrtewJkxlfj6mvtIbRpzZxSLYxQUEep6Hk2Vvck4wjY8sfl7igZpcYE5CF_fsYEDUrJVO9NU41MTpLeH3beYnDlhv2G14qQSlu8H54-kFLrd/s320/Proyecto5.JPG&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Lo que veremos a continuación es la ventana para la creación de clase, aquí, podemos dar un nombre a nuestra clase (recordando iniciar el nombre con mayúscula, no usar espacios, etc) y darle modificadores, súper clase, interfaces, métodos como el constructor, el famoso &lt;i&gt;main()&lt;/i&gt;, nos da también una opción para heredar los métodos abstractos y por último, generar comentarios, pero todo queda a nuestro criterio/necesidades, marcaré la casilla de &lt;i&gt;main()&lt;/i&gt; y le daré los modificadores &lt;i&gt;public&lt;/i&gt; y &lt;i&gt;final&lt;/i&gt; para mostrarles como queda, pero primero vean la ventana de creación de clase:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4o7dYcgQvgDpbjUBtYGsLQTbPGUkgnDfBDPv5qSFITRoMzrFulDY5Cr23DIFkQyC8_dnQhxI-5fhrJGFJ-IjPaZjSqYidkz4tnVlrTSfEaihrr9CnmskgMkWGFs7h26J3KiukJjZFEc4J/s1600/Proyecto6.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4o7dYcgQvgDpbjUBtYGsLQTbPGUkgnDfBDPv5qSFITRoMzrFulDY5Cr23DIFkQyC8_dnQhxI-5fhrJGFJ-IjPaZjSqYidkz4tnVlrTSfEaihrr9CnmskgMkWGFs7h26J3KiukJjZFEc4J/s320/Proyecto6.JPG&quot; width=&quot;262&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Y ahora, les va el código fuente que genera esta ventana con los métodos y modificadores que elegí:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKDRHs8d9SMTQSdhXkmBBu618ndqvvTwBOZYP_gpT91uLnFSYcBcF3Zw2JkDjwiqHbMQYbeR2ZmxRb5tSqK2VQE4FsCe11vg2y6nhBbPOySJRkzKMhHkPHiXQzfhHTQD2vxGhY31fGzxXZ/s1600/Proyecto7.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;159&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKDRHs8d9SMTQSdhXkmBBu618ndqvvTwBOZYP_gpT91uLnFSYcBcF3Zw2JkDjwiqHbMQYbeR2ZmxRb5tSqK2VQE4FsCe11vg2y6nhBbPOySJRkzKMhHkPHiXQzfhHTQD2vxGhY31fGzxXZ/s320/Proyecto7.JPG&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Y listo, acabamos de crear una clase en la cual somos libres de poner todos nuestros métodos, atributos, etc.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Eso es todo por esta entrada, espero haya sido de su agrado, cualquier duda, petición, crítica constructiva, felicitación o agradecimiento por pasar horas creando la entrada, investigando, editando las imágenes y cuidando cada detalle para ustedes (¡malditos, nunca lo hacen!) :P jaja, lo pueden poner en la parte de abajo, no olviden suscribirse y dar Like a la página de Facebook :D ¡Saludos!&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;Artículos Relacionados:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/11/creando-una-gui-en-java.html&quot; target=&quot;_blank&quot;&gt;Creando una GUI en Java&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-1.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Aprender Java creando un juego (Parte 1)&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/como-instalar-sqlite-en-eclipse-ide.html&quot; target=&quot;_blank&quot;&gt;Cómo instalar SQLITE en Eclipse IDE&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/7079949787040010487/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2013/03/como-crear-una-clase-java-en-eclipse-ide.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/7079949787040010487'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/7079949787040010487'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2013/03/como-crear-una-clase-java-en-eclipse-ide.html' title='Cómo crear una clase Java en Eclipse IDE'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwX0AHMfSsbs8Tc7A5BST7jqpEbZwfG_Je77fzwbRNdcO08y7HYz7JPx2yVQpRM1p0g4zNPni5CnjS3VFEharzlflUATyriMN2HC65YkmL1e8J1sixSOpvT4OznUvBbX7D5qdUq1Qo06gJ/s72-c/Clase-Objeto.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-7732291273710463826</id><published>2013-01-26T20:43:00.000-08:00</published><updated>2013-02-03T12:57:59.384-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Como usar Look and Feel en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Eclipse IDE GUI"/><category scheme="http://www.blogger.com/atom/ns#" term="ejemplos GUI en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="GUI Java"/><category scheme="http://www.blogger.com/atom/ns#" term="GUI SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Java SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="LF en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="LF Java SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="Look And Feel SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><title type='text'>Como usar Look And Feel en Java</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;



&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hola y buen día a todos mis lectores, después de un laaargo tiempo de ausencia, he vuelto y aunque esté “Con el agua al cuello” de trabajo, tengo ganas de escribir acerca de cómo trabajar con Look And Feel en Java, así que comienzo:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAlD8G9iB4A4BNCpsQ9mH40b9Vyffajp-9FcuxSF_eZKZi3pX4fiFUo6d_6wEZwPDaWkkSMdQejkXXlqDSsMh0QsBOtApg7vVYzzFVAmZYemdlmHCi64iWcIXuseS1zQtzvAc0pZunkepg/s1600/gui.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;256&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAlD8G9iB4A4BNCpsQ9mH40b9Vyffajp-9FcuxSF_eZKZi3pX4fiFUo6d_6wEZwPDaWkkSMdQejkXXlqDSsMh0QsBOtApg7vVYzzFVAmZYemdlmHCi64iWcIXuseS1zQtzvAc0pZunkepg/s320/gui.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Primero que nada, hay que saber lo que es Look and Feel (Aspecto y Comportamiento) en Java, a falta de una buena definición en Internet, lo explicaré solo a mi manera: El Look and Feel, se refiere a una forma en concreto de cómo se ven y comportan los componentes SWING en Java (Cualquier JComponent), ya sean botones (JButton), tablas (JTable), combos (JComboBox, dejaré dar los otros nombres a tu cerebro :P), checkbox, labels, botones de radio, etc. Los Look And Feel (L&amp;amp;F en adelante para abreviar) disponibles pueden depender de qué sistema operativo tengas. Esta es una forma muy rápida y fácil para darle un aspecto completamente nuevo a tu GUI sin tener que cambiar el código (excepto claro, la parte donde se selecciona y aplica un L&amp;amp;F). Ahora, las preguntas más frecuentes serán tratadas a continuación (si hay más favor de comentarlas):&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¿Cómo saber de cuales L&amp;amp;F dispongo?&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¿Cómo y dónde aplicar un L&amp;amp;F a mi programa SWING?&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¿Es posible dar a elegir un L&amp;amp;F al usuario final?&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Bueno, son todas las que se me ocurren ahí van las respuestas:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¿Cómo saber de cuales L&amp;amp;F dispongo?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahí va el código que muestra un dialogo con una lista de L&amp;amp;Fs disponibles:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

/**
 * Clase que se encarga de mostrar, aplicar y elegir
 * un aspecto y comportamiento L&amp;F. 
 * @author Gustavo Hernández Salinas
 */
public class PruebaLAF {
 
 static void mostrarNombresLAF(){
  JOptionPane.showMessageDialog(null,
    cargarNombresLAFs(), //Mensaje dentro del dialogo.
    &quot;Nombres de los L&amp;F disponibles&quot;, //Título del dialogo.
    JOptionPane.INFORMATION_MESSAGE); //Tipo de mensaje.
 }
 
 /**
  * Se encarga de devolver una lista (solo los nombres)
  * de los L&amp;Fs disponibles.
  * @return Lista de nombres de L&amp;F.
  */
 static String cargarNombresLAFs(){
  //Aquí se asignan los L&amp;Fs disponibles.
  LookAndFeelInfo[] infoLAF;
  
  //Aquí guardaremos los nombres de L&amp;Fs disponibles:
  StringBuffer nombresLAF = new StringBuffer(); 
  
  //Con &#39;nl&#39; separamos el texto en filas:
  String nl = System.getProperty(&quot;line.separator&quot;);
  
  //Obtenemos los L&amp;Fs instalados:
  infoLAF = UIManager.getInstalledLookAndFeels();
  
  //En este ciclo for, obtenemos los nombres de L&amp;F:
  for(int cont = 0; cont &lt; infoLAF.length; cont ++){
   //Obtenemos el nombre y añadimos un salto de línea:
   nombresLAF.append(infoLAF[cont].getName() + nl);
  }

  //Obtenemos L&amp;F en usuo y añadimos un salto de línea:
  nombresLAF.append(&quot;En uso: &quot; + UIManager.getLookAndFeel().getName() + nl);
  
  //Devolvemos el búfer en forma de String:
  return nombresLAF.toString();
 }
 
 public static void main(String[] args) {
  PruebaLAF.mostrarNombresLAF();
 }

}
]]&gt;&lt;/script&gt;


&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Salida (Puede variar por cada equipo):&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyT6e6RTwGyIPIDT_6GQSLmUB3oGAzQmiqpOL7jGtUeJbwqWMOorcVvY4x-J8nl2SJZ2hvYWCK6LiOWAHkXY2urE49ZJa-DwGMWky4jc-5fJ1f8gy6x2wnF8xQ_kDvoRA5QFBZ6TdW1wmM/s1600/Salida+LyF.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;236&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyT6e6RTwGyIPIDT_6GQSLmUB3oGAzQmiqpOL7jGtUeJbwqWMOorcVvY4x-J8nl2SJZ2hvYWCK6LiOWAHkXY2urE49ZJa-DwGMWky4jc-5fJ1f8gy6x2wnF8xQ_kDvoRA5QFBZ6TdW1wmM/s320/Salida+LyF.png&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Importante:&lt;/b&gt; Esto solamente muestra los nombres en un dialogo, no aplica ningún L&amp;amp;F a nuestra interfaz.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¿Cómo y dónde aplicar un L&amp;amp;F a mi programa SWING? - ¿Es posible dar a elegir un L&amp;amp;F al usuario final?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Responderé las 2 preguntas aquí mismo: En teoría puede aplicarse en cualquier parte con el código adecuado, aquí les va una muestra más o menos decente de cómo hago yo para aplicarlo, y luego dar a elegir cualquier otro L&amp;amp;F disponible al usuario (pondré varios componentes para que noten la diferencia entre un L&amp;amp;F y otro):&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

/**
 * Clase que se encarga de mostrar una interfaz con una lista
 * de los L&amp;F disponibles, con la posibilidad de aplicarlo.
 * (Puede no estar diseñada de la mejor manera pero es solo
 * un ejemplo).
 * @author Gustavo Hernández Salinas
 */
public class AplicadorLAF{
 JFrame ventana;
 JButton bAplicar, bFileChooser;
 JComboBox comboLAF;
 JPanel panelLAF, panelMuestra;
 
 /**
  * Aquí en el constructor ponemos un L&amp;F
  * e iniciamos la interfaz (GUI).
  */
 public AplicadorLAF(){
  try {
   UIManager.setLookAndFeel(obtenerLAF());
  }
  catch (Exception e) {
   /**
    * Como la llamada a este método puede lanzar
    * varios tipos de excepciones lo haré simple,
    * manejaremos todas aquí: 
   */
   e.printStackTrace();
  }
  iniciarGUI();
 }
 
 /**
  * Llama a diferentes métodos para mostrar
  * la GUI de manera correcta.
  */
 void iniciarGUI(){
  instanciarGUI();
  configurarGUI();
  añadirAGUI();
  oyentesGUI();
  configurarVentana();
 }
 
 /**
  * Inicia los componentes a mostrar:
  */
 public void instanciarGUI() {
  ventana = new JFrame(&quot;Demostración/Selección de L&amp;F&quot;);
  bAplicar = new JButton(&quot;Aplicar/Mostrar&quot;);
  bFileChooser = new JButton(&quot;Abrir un JFileChooser...&quot;);
  comboLAF = new JComboBox(cargarLAFsDisponibles());
  panelLAF = new JPanel(new FlowLayout());
  panelMuestra = new JPanel(new FlowLayout());
 }
 
 /**
  * Configura ciertos componentes que lo necesiten.
  */
 public void configurarGUI() {
  //Asignamos un layout a la ventana:
  ventana.setLayout(new GridLayout(0, 1));
  //Le decimos qué hacer al presionar el botón de cerrar:
  ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }
 
 public void añadirAGUI() {
  panelLAF.add(new JLabel(&quot;L&amp;F Disponibles: &quot;));
  panelLAF.add(comboLAF);
  panelLAF.add(bAplicar);
  panelMuestra.add(bFileChooser);
  panelMuestra.add(new JCheckBox(&quot;CheckBox de muestra&quot;));
  panelMuestra.add(new JRadioButton(&quot;RadioButton de muestra&quot;));
  ventana.add(new JLabel(&quot;En uso: &quot; + UIManager.getLookAndFeel().getName()));
  ventana.add(panelLAF);
  ventana.add(panelMuestra);
 }
 
 public void oyentesGUI() {
  bFileChooser.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e) {
    //Ponemos aquí las acciones a realizar si damos click al botón:
    accionesFileChooser();
   }});
  
  bAplicar.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e) {
    //Ponemos aquí las acciones a realizar si damos click al botón:
    accionesAplicar();
   }});
 }
 
 /**
  * Configura algunas cosas más en
  * la ventana.
  */
 private void configurarVentana(){
  ventana.pack();
  ventana.setVisible(true);
  ventana.setLocationRelativeTo(null);
 }
 
 /**
  * Aquí van las acciones que se harán
  * al presionar bAplicar...
  */
 private void accionesAplicar(){
  //Ya vimos para qué es...
  LookAndFeelInfo[] infoLAF;
  //Esto también...
  infoLAF = UIManager.getInstalledLookAndFeels();
  //Aquí guardamos el índice de selección del combo:
  int seleccion = comboLAF.getSelectedIndex();
  
  try {
   //Aquí aplicamos el L&amp;F usando la selección del combo:
   UIManager.setLookAndFeel(infoLAF[seleccion].getClassName());
   //Aquí pedimos actualizar la GUI con el nuevo L&amp;F:
   SwingUtilities.updateComponentTreeUI(ventana);
   //Llamamos a pack para reacomodar los componentes:
   ventana.pack();
  } 
  catch (Exception e) {
   e.printStackTrace();
  }
 }
 
 /**
  * Lanza un filechooser para mostrar los cambios 
  * en su interfaz con cada L&amp;F.
  */
 private void accionesFileChooser(){
  new JFileChooser().showOpenDialog(ventana);
 }
 
 /**
  * Notarán que el código es similar al de PruebaLAF.cargarNombresLAFs()
  * solo que aquí en lugar de devolver texto separado en líneas, 
  * devolveremos un Array de Object para mostrar en el combo.
  * @return Lista de LAFs disponibles.
  */
 static Object[] cargarLAFsDisponibles(){
  //Aquí se asignan los L&amp;Fs disponibles.
  LookAndFeelInfo[] infoLAF;
  
  //Aquí guardaremos los nombres de L&amp;Fs disponibles:
  Object[] nombresLAF; 
  
  //Obtenemos los L&amp;Fs instalados:
  infoLAF = UIManager.getInstalledLookAndFeels();
  
  //Damos un tamaño de array para nombresLAF:
  nombresLAF = new Object[infoLAF.length];
  
  //En este ciclo for, obtenemos los nombres de L&amp;F:
  for(int cont = 0; cont &lt; infoLAF.length; cont ++){
   //Obtenemos el nombre y se lo asignamos a nombresLAF:
   nombresLAF[cont] = infoLAF[cont].getName();
  }

  return nombresLAF;
 }
 
 /**
  * Nota: Este método dependerá de como den persistencia
  * a la selección del look and feel por el usuario (es
  * decir, como lo guarden, ya sea un archivo de texto, 
  *  en base de datos, etc.) En mi caso simplemente
  *  selecciono el primero de la lista.
  * @return L&amp;F Seleccionado por el usuario o programa.
  */
 private static String obtenerLAF() {
  return UIManager.getInstalledLookAndFeels()[0].getClassName();
 }
 
 public static void main(String[] args) {
  //Instanciamos el aplicador:
  new AplicadorLAF();
 }

}
]]&gt;&lt;/script&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;



Un poco largo, pero hace lo que debe de manera correcta, aquí les va una imagen con cada cambio que hago en el L&amp;amp;F:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuQYC5xJsiSeorxRBJppllwbzai6KdeBc-SSWvrWHvXS5mBelpUxNAbfj6FGy-xwLvRzE4J4elN_etQ47z6E7fo3ccfvZbb3lHa9VWrhTY_twTOGd9w1iQ5d0C2y3xzQi8TsEuKvL_U4r-/s1600/LyF.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;190&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuQYC5xJsiSeorxRBJppllwbzai6KdeBc-SSWvrWHvXS5mBelpUxNAbfj6FGy-xwLvRzE4J4elN_etQ47z6E7fo3ccfvZbb3lHa9VWrhTY_twTOGd9w1iQ5d0C2y3xzQi8TsEuKvL_U4r-/s400/LyF.PNG&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¿Grandes diferencias no? Y todo posible cambiando solamente el Look and Feel, las diferencias se notan aún más si abrimos por ejemplo, el JFileChooser, hagan la prueba ;).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para más información pueden visitar: &lt;a href=&quot;http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html&quot; target=&quot;_blank&quot;&gt;http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Eso es todo por hoy queridos lectores, espero hayan disfrutado este artículo porque probablemente me cueste mis empleos… :P no, mentira. Ya saben, cualquier duda, sugerencia, petición, crítica constructiva, favor de ponerla en los comentarios, no olviden suscribirse ya sea por RSS, Atom o por correo electrónico y si gustan, marcar alguna casilla de la sección “Mi opinión” para saber qué tal lo hago, hasta luego :D.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;Artículos relacionados:&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/11/creando-una-gui-en-java.html&quot; target=&quot;_blank&quot;&gt;Cómo crear una GUI en Java&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/12/syntaxhighlighter.html&quot; target=&quot;_blank&quot;&gt;Cómo crear una GUI en Java - Parte 2&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/7732291273710463826/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2013/01/como-usar-look-and-feel-en-java.html#comment-form' title='3 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/7732291273710463826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/7732291273710463826'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2013/01/como-usar-look-and-feel-en-java.html' title='Como usar Look And Feel en Java'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAlD8G9iB4A4BNCpsQ9mH40b9Vyffajp-9FcuxSF_eZKZi3pX4fiFUo6d_6wEZwPDaWkkSMdQejkXXlqDSsMh0QsBOtApg7vVYzzFVAmZYemdlmHCi64iWcIXuseS1zQtzvAc0pZunkepg/s72-c/gui.png" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-3611398050720114103</id><published>2012-12-07T12:58:00.000-08:00</published><updated>2012-12-12T14:49:15.565-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Como crear una GUI en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Crear GUI en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse ide"/><category scheme="http://www.blogger.com/atom/ns#" term="ejemplos GUI en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="GUI Java"/><category scheme="http://www.blogger.com/atom/ns#" term="GUI SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><title type='text'>Como crear una GUI en Java - Parte 2</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;



Hola y buen día a todos mis lectores, como les prometí en la &lt;a href=&quot;http://baro3495.blogspot.com/2012/11/creando-una-gui-en-java.html&quot; target=&quot;_blank&quot;&gt;entrada pasada&lt;/a&gt;, hoy seguiremos tratando con el tema de la creación de GUI’s en Java, aquí les va…&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgtkQyh8T6l0vuqdsJhMF0BjhOnVsL7j2X3TEtsK2e0YW72Hp97MZwct9V0Vb-YP05S2scce_leG-t1uy3SfAHw7zbpV7Li9MuN8A-zMXbU0QEfq0pvawVj9B1znINeJ3hH0iwGsl5sRHi/s1600/SWING.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;211&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgtkQyh8T6l0vuqdsJhMF0BjhOnVsL7j2X3TEtsK2e0YW72Hp97MZwct9V0Vb-YP05S2scce_leG-t1uy3SfAHw7zbpV7Li9MuN8A-zMXbU0QEfq0pvawVj9B1znINeJ3hH0iwGsl5sRHi/s320/SWING.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En la &lt;a href=&quot;http://baro3495.blogspot.com/2012/11/creando-una-gui-en-java.html&quot; target=&quot;_blank&quot;&gt;entrada anterior&lt;/a&gt;, vimos varios ejemplos de cómo se pueden crear GUI’s (Graphical User Interface), en el último ejemplo, encontramos (a mi parecer) la mejor forma de hacerlo, aquí está el código:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
/**
 * Ejemplo #3 sobre la creación de GUI&#39;s.
 * @author Gustavo Hernández
 */
public class EjemploGUI {
 //Declaramos los componentes que usaremos:
 JFrame ventana;
 JLabel etiqueta;
 JTextField campo;
 JButton boton;
 
 //En el constructor solo llamamos un método:
 public EjemploGUI(){
  iniciarGUI();
 }
 
 /**
  * Método que se encarga de llamar a todos los métodos
  * encargados de crear la GUI y mostrarla.
  */
 public void iniciarGUI(){
  instanciarGUI();
  configurarGUI();
  añadirAGUI();
  oyentesGUI();
  //La ventana se muestra al llamar este método:
  ventana.setVisible(true);
 }
 
 /**
  * Se encarga de instanciar cada componente que va en 
  * nuestra GUI.
  */
 private void instanciarGUI() {
  ventana = new JFrame(&quot;Ejemplo GUI #3&quot;);
  etiqueta = new JLabel(&quot;Etiqueta de ejemplo #3&quot;);
  campo = new JTextField(10);
  boton = new JButton(&quot;Botón De Ejemplo #3&quot;);
 }
 
 /**
  * Se encarga de configurar a todos los componentes,
  * como por ejemplo dar color a un boton o campo, cambiar
  * tamaños etc.
  */
 private void configurarGUI() {
  //Ponemos una acción de cerrado por default (salir en este caso):
  ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  //Ponemos el layout:
  ventana.setLayout(new FlowLayout());
 }
 
 /**
  * Se encarga de añadir cualquier componente en la GUI.
  */
 private void añadirAGUI() {
  ventana.add(etiqueta);
  ventana.add(campo); 
  ventana.add(boton);
  //Se llama a pack después de haber agregado componenetes a la ventana
  ventana.pack();
 }
 
 /**
  * Se encarga de añadir los oyentes, ya sea de mouse,
  * teclado o similares.
  */
 private void oyentesGUI() {
  
  //Ejemplo de como añadir un oyente de acción a un botón:
  boton.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e) {
    //Ponemos aquí las acciones a realizar si damos click al botón:
    accionesBotón();
   }});
 }
 
 /**
  * Método encargado de dar un mensaje:
  */
 private void accionesBotón(){
  JOptionPane.showMessageDialog(null, &quot;Has dado click en el botón&quot;);
 }
 
 public void llenarCampo(String texto){
  campo.setText(texto);
 }
 
 public static void main(String[] args){
  //Llamamos a una nueva instancia de la clase y a un método en la misma:
  new EjemploGUI().llenarCampo(&quot;¡Hola mundo!&quot;);
 }
 
}
]]&gt;&lt;/script&gt;



&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Una muy buena forma de hacerlo, pero tiene algunas desventajas (yo puse 2, si encuentran más desventajas favor de señalarlas) que vamos a tratar más adelante, son las siguientes:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hay que escribir algo más de código, lo que resulta tedioso.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Si no ponemos los métodos en el orden correcto dentro de &lt;i&gt;iniciarGUI()&lt;/i&gt;, nos puede generar excepciones.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¿Y cómo resolver estos problemas?, bueno, es muy simple, todo empieza con la creación de lo que en Java se llama &lt;i&gt;interface&lt;/i&gt; (&lt;i&gt;interfaz&lt;/i&gt; en español). Pero antes que nada, ¿qué es una interfaz en Java?, ahí les va la definición:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Una interfaz en Java es una colección de métodos abstractos y propiedades. En ellas se especifica qué se debe hacer pero no su implementación. Serán las clases que implementen estas interfaces las que describan la lógica del comportamiento de los métodos.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La principal diferencia entre interface y abstract es que un interface proporciona un mecanismo de encapsulación de los protocolos de los métodos sin forzar al usuario a utilizar la herencia.&lt;/span&gt;&lt;/blockquote&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Gracias &lt;a href=&quot;http://es.wikipedia.org/wiki/Wikipedia:Portada&quot; target=&quot;_blank&quot;&gt;Wikipedia&lt;/a&gt; por la definición, ahora, vamos a ver el código de nuestra interfaz para facilitar la creación de GUI’s, en mí caso se llama &lt;i&gt;GUIBásica&lt;/i&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
/**
 * Define los métodos básicos necesarios para la creación
 * de casi cualquier interfaz gráfica de usuario.
 * @author Gustavo Hernández Salinas
 */
public interface GUIBásica {
 void instanciarGUI();
 void configurarGUI();
 void añadirAGUI();
 void oyentesGUI();
}
]]&gt;&lt;/script&gt;



&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Sencillo, ¿no?, &amp;nbsp;bueno, esto puede ayudar con eso de no tener que escribir el código (los métodos), ya que si al momento de crear nuestra clase agregamos esta interfaz a la lista de las que vamos a implementar, ¡Se escribirán solos! :D. Lo único que debes escribir ahora, es el método &lt;i&gt;iniciarGUI()&lt;/i&gt;, no olvides poner los métodos en el orden correcto.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora, si quieres facilitarte la vida aún más, sigue leyendo y veremos otras formas de facilitar la creación de GUI’s…&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Pasando de la interfaz a la superclase&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Tener nuestros métodos para la creación de GUI’s en una interfaz es bastante bueno, facilita las cosas, yo utilicé esta forma de crear GUI’s mucho tiempo, pero luego me di cuenta de algo, ¡Puede mejorar! ¿Y cómo? Con una superclase, ahora, no solo tendremos los métodos ya escritos, si no que tendremos también un JPanel, JFrame o JDialog (Que son los principales contenedores) listo para trabajar, ahí les va mi código:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;La clase &lt;i&gt;PanelBásico&lt;/i&gt;:&lt;/b&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
/**
 * Clase que define un panel básico con lo necesario
 * para el diseño de una interfaz sencilla.
 * @author Gustavo Hernández Salinas
 */
public abstract class PanelBásico extends JPanel implements GUIBásica {
 private static final long serialVersionUID = 1L;
 
 /**
  * Aquí se llama al método iniciarGUI(), lo que significa que no
  * tenemos que llamarlo nosotros.
  */
 public PanelBásico(){
  super();
  iniciarGUI();
 }
 
 /**
  * Se encarga de iniciar el panel llamando a los métodos
  * necesarios para esto.
  *-Se llama a éste método en el constructor.
  */
 public void iniciarGUI(){
  instanciarGUI();
  configurarGUI();
  añadirAGUI();
  oyentesGUI();
 }
 
}
]]&gt;&lt;/script&gt;



&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;La clase &lt;i&gt;VentanaBásica&lt;/i&gt;:&lt;/b&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
/**
 * Clase que define una ventana básica con
 * lo necesario para el diseño de una interfaz sencilla.
 * @author Gustavo Hernández Salinas
 */
public abstract class VentanaBásica extends JFrame implements GUIBásica {
 private static final long serialVersionUID = 1L;
 
 /**
  * Inicia la interfaz de la ventana y le pone título.
  * @param titulo - Título para la ventana.
  */
 public VentanaBásica(String titulo){
  super();
  iniciarGUI();
  this.setTitle(titulo);
 }
 
 public void iniciarGUI(){
  instanciarGUI();
  configurarGUI();
  añadirAGUI();
  oyentesGUI();
  configVentana();
 }
 
 /**
  * Se encarga de configurar los últimos detalles de la ventana tales como:
   pack();
  setAlwaysOnTop(true);
  setVisible(true);
  setLocationRelativeTo(null);
  setResizable(false);
  * Que se deben poner después de agregar componentes a la ventana.
  */
 abstract void configVentana(); 
}
]]&gt;&lt;/script&gt;



&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;La clase &lt;i&gt;DialogoBásico&lt;/i&gt;:&lt;/b&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
/**
 * Clase que define un dialogo básico con lo necesario
 * para el diseño de una interfaz sencilla.
 * @author Gustavo Hernández Salinas
 */
public abstract class DialogoBásico extends JDialog implements GUIBásica {
 private static final long serialVersionUID = 1L;
 
 /**
  * Inicia la interfaz del dialogo y le pone un título.
  * @param titulo - Título para el dialogo.
  */
 public DialogoBásico(String titulo){
  super();
  iniciarGUI();
  this.setTitle(titulo);
 }
 
 /**
  * Se encarga de iniciar el dialogo llamando a los métodos
  * necesarios para esto.
  *-Se llama a éste método en el constructor.
  */
 public void iniciarGUI(){
  instanciarGUI();
  configurarGUI();
  añadirAGUI();
  oyentesGUI();
  configDialogo();
 }
 
 /**
  * Se encarga de configurar los últimos detalles del dialogo tales como:
   pack();
  setAlwaysOnTop(true);
  setVisible(true);
  setLocationRelativeTo(null);
  setResizable(false);
  * Que se deben poner después de agregar componentes al dialogo.
  */
 public abstract void configDialogo();
}
]]&gt;&lt;/script&gt;



&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Pueden parecer clases bastante sencillas, pero entre más simple mejor, la idea es que queden lo más general posible, ahora, van unos ejemplos de uso (relacionados) seguimos con el ejemplo de la ventana con la etiqueta, el campo de texto y el botón:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ejemplo #1:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Ejemplo #1:
/**
 * Panel para mostrar cómo dar uso a la superclase PanelBásico.
 * @author Gustavo
 */
public final class PanelEjemplo extends PanelBásico {
 private static final long serialVersionUID = 8449202349202307559L;
 JLabel etiqueta;
 JTextField campo;
 JButton boton;
 
 /**
  * No hay que poner nada en el constructor...
  */
 public PanelEjemplo() {
  
 }

 /**
  * Instanciamos los componentes:
  */
 public void instanciarGUI() {
  etiqueta = new JLabel(&quot;Etiqueta de ejemplo&quot;);
  campo = new JTextField(10);
  boton = new JButton(&quot;Botón de ejemplo&quot;);
 }
 
 /**
  * Se configura la GUI:
  */
 public void configurarGUI() {
  //Ponemos el layout al panel principal:
  this.setLayout(new FlowLayout());
 }
 
 /**
  * Se añaden los componentes de la GUI:
  */
 public void añadirAGUI() {
  this.add(etiqueta);
  this.add(campo);
  this.add(boton);
 }
 
 /**
  * Se agregan oyentes a los 
  * componentes de la GUI:
  */
 public void oyentesGUI() {
  
  //Ejemplo de como añadir un oyente de acción a un botón:
  boton.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e) {
    //Ponemos aquí las acciones a realizar si damos click al botón:
    accionesBotón();
   }});
 }
 
 /**
  * Se encarga de dar un mensaje al dar click en el botón.
  */
 private void accionesBotón(){
  JOptionPane.showMessageDialog(null, &quot;Has dado click en el botón&quot;);
 }
 
}
]]&gt;&lt;/script&gt;



&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Ejemplo #2:&lt;/b&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
/**
 * Ventana para mostrar cómo dar uso a la superclase VentanaBásica.
 * @author Gustavo
 */
public final class VentanaEjemplo extends VentanaBásica {
 private static final long serialVersionUID = 1L;
 //Declaramos aquí los componentes a utlizar:
 PanelEjemplo pEjemplo;

 /**
  * Aquí tampoco añadimos código al constructor.
  * @param titulo - El título de la ventana.
  */
 public VentanaEjemplo(String titulo) {
  super(titulo);
 }
 
 /**
  * Instanciamos componentes:
  */
 public void instanciarGUI() {
  pEjemplo = new PanelEjemplo();
 }
 
 /**
  * Se configura la GUI:
  */
 public void configurarGUI() {
  //Ponemos el layout:
  this.setLayout(new FlowLayout());
  //Ponemos la operación de cerrado:
  this.setDefaultCloseOperation(EXIT_ON_CLOSE);
 }
 
 /**
  * Se añaden los componentes de la GUI:
  */
 public void añadirAGUI() {
  this.add(pEjemplo);
 }
 
 /**
  * Se agregan oyentes a los 
  * componentes de la GUI:
  */
 public void oyentesGUI() {
  //En este caso no añadiremos oyentes...
 }
 
 /**
  * Configuramos algunas cosas en la ventana:
  */
 public void configVentana(){
  //Llamamos a pack() cuando hayamos terminado de añadir componentes:
  pack();
  //Le decimos a la ventana que se muestre:
  setVisible(true);
  //Le damos una ubicación a la ventana, centro en este caso:
  setLocationRelativeTo(null);
 }
 
 public static void main(String[] args) {
  //Llamamos a una nueva instancia de esta clase:
  new VentanaEjemplo(&quot;Ejemplo de creación de GUI&#39;s&quot;);
 }

}

]]&gt;&lt;/script&gt;



&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Y la salida es:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEX1PPX6Qd8_bcqtKJBSMXDP4ZVvCgvyRAQWrPXPsSlKKAzSE4dyd_Ko7jaxkCYND8eHq76HAb4sFkl17vgiQ0440_APaBqad-mCEgVE8VqSjzHzTGX1474Dvi7X4OQV4yhTGyR93OfzhO/s1600/EjemploGUI.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;64&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEX1PPX6Qd8_bcqtKJBSMXDP4ZVvCgvyRAQWrPXPsSlKKAzSE4dyd_Ko7jaxkCYND8eHq76HAb4sFkl17vgiQ0440_APaBqad-mCEgVE8VqSjzHzTGX1474Dvi7X4OQV4yhTGyR93OfzhO/s320/EjemploGUI.JPG&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Dos clases para crear una simple ventana, algo laborioso, pero, para quienes hemos batallado por algún tiempo tratando de encontrar una buena forma de crear GUI’s complejas, creo que esta es una gran opción, siéntanse libres de modificar estos ejemplos a su gusto y conveniencia.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Bueno, es todo por hoy, espero que hayan disfrutado leyendo el artículo tanto como yo disfruté al escribirlo, no olviden suscribirse al blog, dejar sus comentarios y su opinión en la sección “Mi opinión” (Justo abajo) nos vemos en la siguiente entrada :D.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/11/creando-una-gui-en-java.html&quot; target=&quot;_blank&quot;&gt;Como crear una GUI en Java&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/3611398050720114103/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/12/syntaxhighlighter.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/3611398050720114103'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/3611398050720114103'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/12/syntaxhighlighter.html' title='Como crear una GUI en Java - Parte 2'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgtkQyh8T6l0vuqdsJhMF0BjhOnVsL7j2X3TEtsK2e0YW72Hp97MZwct9V0Vb-YP05S2scce_leG-t1uy3SfAHw7zbpV7Li9MuN8A-zMXbU0QEfq0pvawVj9B1znINeJ3hH0iwGsl5sRHi/s72-c/SWING.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-5303533316506061076</id><published>2012-11-29T15:32:00.001-08:00</published><updated>2012-12-12T14:46:48.817-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Como crear una GUI en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Crear GUI en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Crear GUI Java"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse ide"/><category scheme="http://www.blogger.com/atom/ns#" term="Eclipse IDE GUI"/><category scheme="http://www.blogger.com/atom/ns#" term="ejemplos GUI en Java"/><category scheme="http://www.blogger.com/atom/ns#" term="GUI Java"/><category scheme="http://www.blogger.com/atom/ns#" term="GUI SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Java SWING"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><title type='text'>Como crear una GUI en Java</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;



&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Buen día a todos mis lectores, después de casi un mes de ausencia he vuelto para ayudarles en uno de mis temas favoritos en cuánto a Java: La creación de GUI´s, aquí les va…&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitiA5FR8daCmqAI-oOgD9P8unFXDClqOikGbrADaMpLhi-2SSHh1dJMN50dwefHmUUAwX6Ye7VdYzWjRyFwusPmylxBzEwpsng14woOdJDoruLgbSPDq0HAhymHqt1brvLBIhv0uk_gzOz/s1600/cmd+vs+gui+2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;107&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitiA5FR8daCmqAI-oOgD9P8unFXDClqOikGbrADaMpLhi-2SSHh1dJMN50dwefHmUUAwX6Ye7VdYzWjRyFwusPmylxBzEwpsng14woOdJDoruLgbSPDq0HAhymHqt1brvLBIhv0uk_gzOz/s1600/cmd+vs+gui+2.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Primero que nada, hay que definir qué significa GUI: Se refiere a la abreviación para Graphical User Interface (Interfaz Gráfica de Usuario), lo que se traduce en ventanas, botones, campos de texto, etiquetas descriptivas, etc. La creación de GUI´s en Java, como en cualquier otro lenguaje de programación es algo fundamental en el diseño de cualquier aplicación, ya que es la parte con la que el usuario final interactúa, y por lógica, este tema ha evolucionado con el tiempo, porque, ¿quién ve ahora una interfaz de línea de comandos?&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitiA5FR8daCmqAI-oOgD9P8unFXDClqOikGbrADaMpLhi-2SSHh1dJMN50dwefHmUUAwX6Ye7VdYzWjRyFwusPmylxBzEwpsng14woOdJDoruLgbSPDq0HAhymHqt1brvLBIhv0uk_gzOz/s1600/cmd+vs+gui+2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span id=&quot;goog_186638240&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En estos tiempos, ¿Con qué programa crees que quiera trabajar el usuario común?, ¿El de línea de comandos, o el que tiene la bonita GUI? Obviamente la mayoría elegiría la GUI ya que es mucho más comprensible y fácil de usar.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora, hay varias formas de diseñar una GUI, a veces depende de la complejidad que tenga la GUI la forma en que lo hacemos, aquí les van 3 ejemplos para una misma situación: Digamos que quiero una ventana, que tenga &amp;nbsp;una etiqueta, un campo de texto y un botón, aquí va el primer ejemplo:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 * Ejemplo #1 sobre la creación de GUI&#39;s.
 * @author Gustavo Hernández
 */
public class EjemploGUI {
 
 public EjemploGUI(){
  //Declaramos e instanciamos nuestra ventana:
  JFrame ventana = new JFrame(&quot;Ejemplo GUI #1&quot;);
  //Ponemos una acción de cerrado por default (salir en este caso):
  ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  //Ponemos el layout:
  ventana.setLayout(new FlowLayout());
  //Agregamos la etiqueta a la ventana:
  ventana.add(new JLabel(&quot;Etiqueta de ejemplo #1&quot;));
  //Agregamos el campo de texto a la ventana:
  ventana.add(new JTextField(10)); //10 = Largo del campo
  //Añadimos el botón a la ventana:
  ventana.add(new JButton(&quot;Botón De Ejemplo #1&quot;));
  //Se llama a pack después de haber agregado componenetes a la ventana
  ventana.pack();
  //La ventana se muestra al llamar este método:
  ventana.setVisible(true);
 }
 
 public static void main(String[] args){
  //Llamamos a una nueva instancia de la clase:
  new EjemploGUI();
 }
 
}
]]&gt;&lt;/script&gt;



&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Algo desordenado, ¿no creen?,&amp;nbsp;quizá para algunos no lo sea, pero pregúntense lo siguiente: ¿Qué pasará cuando tengan que desarrollar una interfaz mucho más compleja? No se trata solo de diseñar la ventana y agregar los componentes, se trata de añadirles oyentes de teclado, de mouse, que realicen acciones en base a eso, posiblemente cambiando fuentes, poniendo tooltips, soporte para tecnologías asistivas, etc.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Aquí va el siguiente ejemplo:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 * Ejemplo #2 sobre la creación de GUI&#39;s.
 * @author Gustavo Hernández
 */
public class EjemploGUI {
 //Declaramos los componentes que usaremos:
 JFrame ventana;
 JLabel etiqueta;
 JTextField campo;
 JButton boton;
 
 public EjemploGUI(){
  //Declaramos e instanciamos nuestra ventana:
  ventana = new JFrame(&quot;Ejemplo GUI #2&quot;);
  //Ponemos una acción de cerrado por default (salir en este caso):
  ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  //Ponemos el layout:
  ventana.setLayout(new FlowLayout());
  //Agregamos la etiqueta a la ventana:
  etiqueta = new JLabel(&quot;Etiqueta de ejemplo #2&quot;);
  ventana.add(etiqueta);
  //Agregamos el campo de texto a la ventana:
  campo = new JTextField(10);
  ventana.add(campo); //10 = Largo del campo
  //Añadimos el botón a la ventana:
  boton = new JButton(&quot;Botón De Ejemplo #2&quot;);
  ventana.add(boton);
  //Se llama a pack después de haber agregado componenetes a la ventana
  ventana.pack();
  //La ventana se muestra al llamar este método:
  ventana.setVisible(true);
 }
 
 public void llenarCampo(String texto){
  campo.setText(texto);
 }
 
 public static void main(String[] args){
  //Llamamos a una nueva instancia de la clase y a un método en la misma:
  new EjemploGUI().llenarCampo(&quot;¡Hola mundo!&quot;);
 }
 
}
]]&gt;&lt;/script&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;



Un poco mejor, ¿no?,&amp;nbsp;aunque algunos dirán, “¿Porqué es mejor si solo generamos más código?” La respuesta es que, ahora, tenemos control sobre la ventana y los componentes fuera del constructor, como se ve en el nuevo método que agregamos en este ejemplo, si hubiéramos intentado escribir un método así en el primer ejemplo, nos habría marcado error, hagan la prueba ;).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora, estas formas de diseñar GUI’s es 100% válida, muchas veces como programadores decimos: “Ahhh, es una aplicación que jamás volveré a usar, por lo tanto no vale la pena esforzarme tanto en el estilo del código” Pero aquí les va algo de mi propia experiencia: Muchas veces, en otros proyectos digamos, de pronto acabamos necesitando extender ese pequeño e insignificante programa a fin de que sea parte de un proyecto de software mucho mayor, ¿y qué pasa? ¡El código es un desastre!, por lo tanto, a mi parecer, queda una solución: Que siempre que diseñemos GUI’s lo hagamos de una misma manera sin importar lo grande o chico que sea lo que pensamos hacer. Les mostraré un ejemplo de cómo lo hago yo, es algo simple y son libres de proponer uno mejor o cambiar un poco mi forma de hacerlo en sus propios códigos:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 * Ejemplo #3 sobre la creación de GUI&#39;s.
 * @author Gustavo Hernández
 */
public class EjemploGUI {
 //Declaramos los componentes que usaremos:
 JFrame ventana;
 JLabel etiqueta;
 JTextField campo;
 JButton boton;
 
 //En el constructor solo llamamos un método:
 public EjemploGUI(){
  iniciarGUI();
 }
 
 /**
  * Método que se encarga de llamar a todos los métodos
  * encargados de crear la GUI y mostrarla.
  */
 public void iniciarGUI(){
  instanciarGUI();
  configurarGUI();
  añadirAGUI();
  oyentesGUI();
  //La ventana se muestra al llamar este método:
  ventana.setVisible(true);
 }
 
 /**
  * Se encarga de instanciar cada componente que va en 
  * nuestra GUI.
  */
 private void instanciarGUI() {
  ventana = new JFrame(&quot;Ejemplo GUI #3&quot;);
  etiqueta = new JLabel(&quot;Etiqueta de ejemplo #3&quot;);
  campo = new JTextField(10);
  boton = new JButton(&quot;Botón De Ejemplo #3&quot;);
 }
 
 /**
  * Se encarga de configurar a todos los componentes,
  * como por ejemplo dar color a un boton o campo, cambiar
  * tamaños etc.
  */
 private void configurarGUI() {
  //Ponemos una acción de cerrado por default (salir en este caso):
  ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  //Ponemos el layout:
  ventana.setLayout(new FlowLayout());
 }
 
 /**
  * Se encarga de añadir cualquier componente en la GUI.
  */
 private void añadirAGUI() {
  ventana.add(etiqueta);
  ventana.add(campo); //10 = Largo del campo
  ventana.add(boton);
  //Se llama a pack después de haber agregado componenetes a la ventana
  ventana.pack();
 }
 
 /**
  * Se encarga de añadir los oyentes, ya sea de mouse,
  * teclado o similares.
  */
 private void oyentesGUI() {
  
  //Ejemplo de como añadir un oyente de acción a un botón:
  boton.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e) {
    //Ponemos aquí las acciones a realizar si damos click al botón:
    accionesBotón();
   }});
 }
 
 /**
  * Método encargado de dar un mensaje:
  */
 private void accionesBotón(){
  JOptionPane.showMessageDialog(null, &quot;Has dado click en el botón&quot;);
 }
 
 public void llenarCampo(String texto){
  campo.setText(texto);
 }
 
 public static void main(String[] args){
  //Llamamos a una nueva instancia de la clase y a un método en la misma:
  new EjemploGUI().llenarCampo(&quot;¡Hola mundo!&quot;);
 }
 
}
]]&gt;&lt;/script&gt;



&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Es un código algo más extenso que el primero&amp;nbsp;pero trae varios beneficios, van algunos a continuación:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;•&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;El código está mucho más organizado.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;•&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Si necesitamos cambiar algo al código es mucho más fácil ya que siempre sabremos dónde está todo.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;•&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Evitamos errores como por ejemplo, agregar un componente a otro antes de instanciarlo.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Un pequeño problema con esta forma de diseñar GUI’s, es que siempre tendremos que escribir los mismos métodos, lo que resulta algo cansado y puede que olvidemos algún método o el orden en el que están, lo que podría generar errores, ¿Puedes pensar en una forma de resolver esto? Si no es así, de todas formas daremos atención a este problema en la siguiente entrada que ya estoy cansado de escribir :P, veremos también esta forma de diseñar GUI’s más a detalle, como el porqué organizar los método de esa forma. Es todo por hoy, no olviden comentar, dar su opinión en las casillas de abajo, suscribirse y todo eso, saludos.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/12/syntaxhighlighter.html&quot; target=&quot;_blank&quot;&gt;Como crear una GUI en Java - Parte 2&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;

&lt;!-- Blogger automated replacement: &quot;https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F3.bp.blogspot.com%2F-ifQ32KV8zww%2FULfuvu0o_nI%2FAAAAAAAAAT8%2F83L_VjuAmkA%2Fs1600%2Fcmd%2Bvs%2Bgui%2B2.jpg&amp;amp;container=blogger&amp;amp;gadget=a&amp;amp;rewriteMime=image%2F*&quot; with &quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitiA5FR8daCmqAI-oOgD9P8unFXDClqOikGbrADaMpLhi-2SSHh1dJMN50dwefHmUUAwX6Ye7VdYzWjRyFwusPmylxBzEwpsng14woOdJDoruLgbSPDq0HAhymHqt1brvLBIhv0uk_gzOz/s1600/cmd+vs+gui+2.jpg&quot; --&gt;</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/5303533316506061076/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/11/creando-una-gui-en-java.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/5303533316506061076'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/5303533316506061076'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/11/creando-una-gui-en-java.html' title='Como crear una GUI en Java'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitiA5FR8daCmqAI-oOgD9P8unFXDClqOikGbrADaMpLhi-2SSHh1dJMN50dwefHmUUAwX6Ye7VdYzWjRyFwusPmylxBzEwpsng14woOdJDoruLgbSPDq0HAhymHqt1brvLBIhv0uk_gzOz/s72-c/cmd+vs+gui+2.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-8218473426429306650</id><published>2012-10-31T15:55:00.000-07:00</published><updated>2012-11-29T15:11:31.840-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="E/S"/><category scheme="http://www.blogger.com/atom/ns#" term="Entradas y Salidas"/><category scheme="http://www.blogger.com/atom/ns#" term="I/O"/><category scheme="http://www.blogger.com/atom/ns#" term="I/O E/S"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java IO"/><category scheme="http://www.blogger.com/atom/ns#" term="Java magazine"/><category scheme="http://www.blogger.com/atom/ns#" term="Java NIO"/><category scheme="http://www.blogger.com/atom/ns#" term="Java NIO.2"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="NIO"/><category scheme="http://www.blogger.com/atom/ns#" term="NIO.2"/><category scheme="http://www.blogger.com/atom/ns#" term="Permisos POSIX"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="POSIX"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><title type='text'>Introducción a Java NIO - Parte 2 (Final)</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s1600/JavaBlack.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s200/JavaBlack.jpg&quot; height=&quot;133&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGIj_p41y2zwBfKgBvCRBHiyw1JB9Fv6YEI4u-spOm0WhYt_tp-Lz9I0TXgmW-j5teJohIdNod4pAm7suB4ojsAuqxbSsTUtrvhnKHpxyve0M2x7lic04C3xqVDxPySP6GFogBAyOzOIe_/s1600/images.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGIj_p41y2zwBfKgBvCRBHiyw1JB9Fv6YEI4u-spOm0WhYt_tp-Lz9I0TXgmW-j5teJohIdNod4pAm7suB4ojsAuqxbSsTUtrvhnKHpxyve0M2x7lic04C3xqVDxPySP6GFogBAyOzOIe_/s200/images.jpg&quot; height=&quot;132&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;



&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Hola y buen día a todos mis lectores :D, hoy, en
lugar de “jugar” a la política o a diseñar sistemas, me decidí por terminar
este tutorial sobre el API NIO (o NIO.2), aquí les va…&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Flujos de carpetas (Directory
streams).&lt;/b&gt; Los &lt;i&gt;FileVisitors&lt;/i&gt; son bastante&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;personalizables, pero cuando todo lo que necesitas mirar es cierto archivo en
una sola&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;carpeta, una solución más simple existe en la forma de los flujos de
carpetas. En una&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;palabra, un flujo es simplemente un objeto &lt;i&gt;iterable&lt;/i&gt; que corre sobre un conjunto de&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;rutas&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;que concuerdan con cierto filtro. Es además una interface &lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;AutoCloseable&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt; para&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;usar en&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;sentencias
try-with-resources, porque los flujos de carpetas necesitan ser&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;cerrados.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;A
continuación se muestra cómo podemos ver todas las entradas en la raíz del JAR
anterior.&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;Y a continuación se muestra cómo podemos pasar
un filtro glob a una lista sólo los archivos de clase Java.&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;Búsquedas más elaboradas&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;pueden ser implementadas pasando un objeto &lt;/span&gt;&lt;i style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;DirectoryStream.Filter&lt;/i&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt; como un flujo
predicado. Por ejemplo, podemos reusar el objeto glob &lt;/span&gt;&lt;i style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;matcher&lt;/i&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt; que usamos antes para listar todas las clases Java, como se
muestra a continuación:&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 15px; line-height: 17px;&quot;&gt;Como en el caso de los visitantes&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;de
archivos, la predicción (&lt;/span&gt;&lt;i style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;predicate&lt;/i&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;)
no necesita estar basada en buscar un &lt;/span&gt;&lt;i style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;PathMatcher&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;.
Podrías, por ejemplo, mirar el tamaño de archivo o los atributos de archivo
para formar consultas como “cualquier archivo ejecutable sobre 1024kilo-octetos
de tamaño.”&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Copiando un árbol de
archivo completo en un archivo zip.&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt; Podemos fácilmente
combinar un árbol de archivo andante, las operaciones de clase Files, y un
sistema de archivo ad hoc para copiar todo el árbol de archivo de carpeta
actual en un archivo zip codificado UTF-8, como se muestra a continuación:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
URI archive = URI.create(&quot;jar:file:/tmp/archive.zip&quot;);
Map&lt;String, String&gt; env = new HashMap&lt;String, String&gt;() {
  {
    put(&quot;create&quot;, &quot;true&quot;);
    put(&quot;encoding&quot;, &quot;UTF-8&quot;);
  }
};

try (FileSystem fs = FileSystems.newFileSystem(archive, env)) {
  final Path here = Paths.get(&quot;.&quot;);
  final Path fsRoot = fs.getPath(&quot;/&quot;);
  Files.walkFileTree(here, new SimpleFileVisitor&lt;path&gt;() {
  
    @Override
    public FileVisitResult visitFile(Path file, 
        BasicFileAttributes attrs) throws IOException {
      Files.copy(file, fsRoot.resolve(file.toString()),
          StandardCopyOption.REPLACE_EXISTING);
      return FileVisitResult.CONTINUE;
    }

    @Override
    public FileVisitResult preVisitDirectory(Path dir,
        BasicFileAttributes attrs) throws IOException {
      Files.createDirectories(fsRoot.resolve(dir.toString()));
      return FileVisitResult.CONTINUE;
    }
  });
}
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Si en lugar de copiar archivos en un archivo zip,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;tuviéramos
un sistema de archivos FTP para copiar archivos a un servidor remoto FTP, el
código de arriba no debería cambiar mucho, excepto por la creación del sistema
de archivo. El método &lt;/span&gt;&lt;i style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Files.createDirectories()&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;
cubre la creación de todos los directorios que necesiten existir con el fin de
llevar a que la carpeta sea creada.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Manipulando metadatos&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Una
de las características más interesantes del API NIO.2 es la habilidad de
manipular&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;metadatos a nivel del sistema de archivos. Anteriormente, información
como el dueño del&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;archivo, grupo y permisos de acceso no estaban disponibles en
el estándar Java runtime&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;sin recurrir a ejecución de procesos externos o
integración de código nativo, ambos de los&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;cuales agregan so propio conjunto de
problemas. Mientras tal información ha dejado de estar&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp;escondida, el código
necesita adaptarse a las capacidades del entorno de ejecución,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;porque los
sistemas operativos y los sistemas de archivos varían grandemente.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El
paquete &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;java.nio.file.attribute&lt;/span&gt;&lt;/i&gt;
provee soporte para accesar a tales metadatos, en su&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;mayoría usando una
jerarquía de &lt;i&gt;file attribute views&lt;/i&gt;.
Cada vista representa un conjunto de&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;metadatos que pueden ser manipulados
dependiendo de lo que provee el sistema de archivos&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;subyacente.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La
interfaz &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;BasicFileAttributeView&lt;/span&gt;&lt;/i&gt; define
los atributos que son comunes para los&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;sistemas de archivos existentes, como el
tamaño del archivo, fecha de última&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;modificación, y fecha de creación.
Instancias de &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;DosFileAttributeView&lt;/span&gt;&lt;/i&gt; define
atributos de&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;los sistemas de archivos tipo DOS, como&amp;nbsp; si un archivo está oculto, un archivo de
sistema o&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;un archivo. En el mismo espíritu, &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;PosixFileAttributeView&lt;/span&gt;&lt;/i&gt;
define atributos para los&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;sistemas POSIX, mientras &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;AclFileAttributeView&lt;/span&gt;&lt;/i&gt;
permite accesar a las listas de control de&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;accesos (ACLs) en los sistemas de
archivo que los soportan.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El
Javadoc para el paquete &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;java.nio.file.attribute&lt;/span&gt;&lt;/i&gt;
a fondo describe estas vistas. Vamos&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;a ver algunos patrones de uso común.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Atributos de archivo.&lt;/b&gt; Los atributos de archivos más
comunes son accesibles&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;directamente desde los métodos de clase &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Files&lt;/span&gt;&lt;/i&gt;: &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;size()&lt;/span&gt;&lt;/i&gt;,
&lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;isDirectory()&lt;/span&gt;&lt;/i&gt;, &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;isRegularFile()&lt;/span&gt;&lt;/i&gt;,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;isSymbolicLink()&lt;/span&gt;&lt;/i&gt;, &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;isHidden()&lt;/span&gt;&lt;/i&gt;,
&lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;getLastModifiedTime()&lt;/span&gt;&lt;/i&gt; y más.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para
accesar o modificar un solo atributo, puedes usar los métodos &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;getAttribute()&lt;/span&gt;&lt;/i&gt; y&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;setAttribute()&lt;/span&gt;&lt;/i&gt;.
Ellos toman un solo String que representa el atributo, prefijado con un&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;identificador de la vista de atributo de archivo. Cada interface de la vista de
atributo de&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;archivo define tales Strings y el &lt;i&gt;return type&lt;/i&gt; del atributo en el Javadoc correspondiente.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Podemos
consultar los permisos POSIX para un archivo como se muestra a continuación:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Path asm = Paths.get(&quot;asm-all-2.2.3.jar&quot;);
Set&lt;posixfilepermission&gt; perms = (Set&lt;posixfilepermission&gt;) Files.getAttribute(asm, &quot;posix:permissions&quot;);
System.out.println(&quot;Posix permissions for &quot; + asm);
for (PosixFilePermission perm : perms) {
  System.out.println(&quot;-&gt; &quot; + perm);
}

]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;Lo que resultaría en una salida similar a la
siguiente:&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;Además, podemos accesar a atributos&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;específicos usando el método &lt;/span&gt;&lt;i style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;readAttributes()&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt; en cualquier subclase de &lt;/span&gt;&lt;i style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;BasicFileAttributes&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;, como se muestra a
continuación:&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;Vale la pena que&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;Files.readAttributes(Path, BasicFileAttributes,
LinkOption[])&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;
realice operaciones masivas de lectura. Esta capacidad es útil al rendimiento
cuando múltiples atributos son leídos simultáneamente.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Los
permisos de archivo POSIX pueden ser directamente accesados como se muestra a
continuación:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
for (PosixFilePermission perm : Files.getPosixFilePermissions(asm)) {
  System.out.println(&quot;-&gt; &quot; + perm);
}
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;Casos más generales pueden ser manejados&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;primero accesando a una vista de atributo de
archivo. Por ejemplo, para obtener el dueño de archivo POSIX de un archivo,
puedes usar el código a continuación:&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&amp;nbsp;Los
permisos de archivo POSIX&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;son comúnmente expresados en la forma de una
String como &lt;/span&gt;&lt;i style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;rwxr-xr-x&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;, lo cual significa
que el usuario puede leer, escribir y ejecutar, mientras que los miembros del
grupo y otros pueden solo leer y ejecutar. Podemos mostrar tales permisos y
cambiarlos, como se muestra a continuación:&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;Lo que produce una salida similar a ésta:&lt;/span&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;


&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #0066ff; font-family: Georgia, Times New Roman, serif; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;Old permissions: rw-r--r--&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;New permissions: rwxr-xr-x&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;o:p&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;La clase FileStore.&lt;/b&gt; Cada ruta tiene un objeto &lt;i&gt;file store&lt;/i&gt; asociado que esencialmente&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;representa donde es guardado el correspondiente archivo: volumen, partición y
demás. La&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;clase &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileStore&lt;/span&gt;&lt;/i&gt; es útil para
consultar si el archivo almacenado soporta una dada vista&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;de atributo de
archivo. Es además útil para accesar a las estadísticas de uso de disco.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El
código a continuación nos permite realizar unas cuantas consultas que producen&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;salida similar a lo siguiente en Mac OS X:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Código:&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Path asm = Paths.get(&quot;asm-all-2.2.3.jar&quot;);
    
FileStore fileStore = Files.getFileStore(asm);
System.out.println(fileStore.name());
System.out.println(fileStore.type());
System.out.println(fileStore.getUsableSpace() / 1024 + &quot; / &quot; + fileStore.getTotalSpace() / 1024);

System.out.println (fileStore.supportsFileAttributeView (BasicFileAttributeView.class));
System.out.println (fileStore.supportsFileAttributeView (PosixFileAttributeView.class));
System.out.println (fileStore.supportsFileAttributeView (AclFileAttributeView.class));
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-align: justify; text-autospace: none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm -72pt 0.0001pt 0cm;&quot;&gt;
&lt;div style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;i&gt;Salida:&lt;/i&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #0066ff; font-family: Georgia, Times New Roman, serif; line-height: normal;&quot;&gt;/dev/disk0s2&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #0066ff; font-family: Georgia, Times New Roman, serif; line-height: normal;&quot;&gt;hfs&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #0066ff; font-family: Georgia, Times New Roman, serif; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;169030116 / 244277768&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #0066ff; font-family: Georgia, Times New Roman, serif;&quot;&gt;true&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #0066ff; font-family: Georgia, Times New Roman, serif;&quot;&gt;true&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #0066ff; font-family: Georgia, Times New Roman, serif; font-size: 11pt; line-height: 115%;&quot;&gt;false&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #0066ff; font-size: 15px; line-height: 17px;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #0066ff; font-size: 15px; line-height: 17px;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Atentos a los cambios&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Algunas
aplicaciones necesitan estar atentas a los cambios del sistema de archivos.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Por
ejemplo, un servidor de aplicación quizá esté atento a que los ficheros de
aplicación sean&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp;dejados en cierta carpeta y entonces automáticamente
desplegarlos. Similarmente, los&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;entornos de desarrollo integrado (IDEs) pueden
buscar archivos de proyecto para que&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;sean agregados, eliminados y modificados
por aplicaciones de terceros. Otro ejemplo&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;incluye algunos patrones de
integración de aplicaciones donde las aplicaciones intercambian&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;datos a través
de depósitos de archivo.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Estar
atento a los cambios en el sistema de archivo puede ser implementado fácilmente&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;mirando periódicamente a las entradas de una carpeta y determinando qué
archivos han&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;sido agregados, eliminados o cambiados basados en su fecha de
última modificación. De&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;todas formas, mecanismos más eficientes existen a nivel
de sistema operativo, como &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;inotify&lt;/span&gt;&lt;/i&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;para Linux.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 16pt;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;NIO.2
Provee una API útil que toma ventaja de las facilidades del sistema operativo,
cuando&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;están disponibles claro, y cae de nuevo a votación periódica de otra
manera. &lt;i&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;WatchService&lt;/span&gt;&lt;/i&gt; provee&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;un
servicio que puede ser notificado sobre cambios en un dado objeto &lt;i&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt;. Puedes&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;especificar qué tipos de
eventos deberían ser mirados, saber las adiciones, modificaciones,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;eliminaciones o desbordamiento (falla del sistema de notificaciones o reporte
de todos los&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;eventos). Por ejemplo, el fragmento de código a continuación busca
por cambios en &lt;i&gt;/tmp&lt;/i&gt; e&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;imprime todos
los eventos:&lt;/span&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import static java.nio.file.StandardWatchEventKinds.*;

// (…)

Path tmp = Paths.get(&quot;/tmp&quot;);
try (WatchService watcher = tmp.getFileSystem().newWatchService()) {
  boolean running = true;
  tmp.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); 
  while (running) {        
    WatchKey key = watcher.take();
    for (WatchEvent&lt;?&gt; event : key.pollEvents()) {
      Path path = (Path) event.context();
      WatchEvent.Kind&lt;?&gt; kind = event.kind();
      System.out.println(kind + &quot; =&gt; &quot; + path);
    }        
    running = key.reset();
  }
}
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt; line-height: 80%;&quot;&gt;Un &lt;i&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;WatchService&lt;/span&gt;&lt;/i&gt;
es obtenido&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;del
sistema de archivo de la ruta a ser monitorizada. De&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;nuevo, este es un objeto &lt;/span&gt;&lt;i style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;AutoCloseable&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;, y es una buena idea usarlo
con una&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;sentencia &lt;/span&gt;&lt;b style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;try-with-resources&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;
para asegurar que eventualmente se cerrará. El servicio&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;de vigilancia es
entonces registrado a una ruta, y los eventos se vuelven disponibles desde&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;una
cola.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Un &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;WatchKey&lt;/span&gt;&lt;/i&gt; es usado en conjunto con registro
y es devuelto al momento de registo. Un&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;WatchKey&lt;/span&gt;&lt;/i&gt;
es además obtenido cuando buscamos eventos usando ya sea el método de&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;servicio
de vigilancia &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;poll()&lt;/span&gt;&lt;/i&gt; o &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;take()&lt;/span&gt;&lt;/i&gt;. En el ejemplo de código anterior
(el de arriba),&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;optamos por usar &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;take()&lt;/span&gt;&lt;/i&gt;
porque podemos permitirnos esperar a que un nuevo evento&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;esté disponible. Una
llave de vigilancia (&lt;i&gt;watch key&lt;/i&gt;)
mantiene el estado, así que podemos&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;consultar para determinar dónde es aún
válido y para obtener los últimos eventos de&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;vigilancia.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Una
vez que una llave ha sido usada, necesita ser reseteada si se va a usar de
nuevo. El&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;método &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;reset()&lt;/span&gt;&lt;/i&gt; devuelve un valor
Boolean que será &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;false&lt;/span&gt;&lt;/i&gt; si la llave ya no es
válida, por&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;ejemplo, cuando una carpeta vigilada desaparece. Puedes además
llamar al método &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;cancel()&lt;/span&gt;&lt;/i&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;para cancelar el
registro del servicio de vigilancia.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Finalmente,
la llave tiene información sobre el evento. Por ejemplo, podría sostener&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;información del tipo de evento (más probable desde &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;StandardWatchEventKinds&lt;/span&gt;&lt;/i&gt;)
y un&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;objeto de contexto que es una instancia de &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt;,
el cual corresponde al tipo de eventos&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;que el servicio está buscando &lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;(ENTRY_CREATE&lt;/span&gt;,
&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;ENTRY_MODIFY&lt;/span&gt;
y &lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;ENTRY_DELETE)&lt;/span&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Conclusión&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Este
artículo introdujo la nueva API del sistema de archivo liberado en Java SE 7
como parte&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;del paquete llamado NIO.2. Estos paquetes hacen fácil tratar con
operaciones de archivo ya&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;sean comunes o avanzadas, como lo es un eficiente
monitor de cambios en una carpeta o&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;mover archivos a un archivo comprimido en
zip mientras se preservan los metadatos.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp;Y último pero no menos importante, se
integran bien con las clases existentes &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;java.io&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;
y &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;java.nio&lt;/span&gt;&lt;/i&gt;, y pueden ser extendidas para
tratar uniformemente con nuevos tipos de&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;proveedores de sistemas de archivos.
Para más ejemplos vea el código de muestra NIO.2&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;en la distribución del JDK7
(bajo &lt;i&gt;simple/nio/file&lt;/i&gt;).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Y
bien, este es el final del tutorial sobre Java NIO (ahora sí voy a disfrutar de
mi frappé :P),&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;espero les haya sido de utilidad, no olviden suscribirse
(e-mail, RSS, Atom), comentar, hacer&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;peticiones, plantear sus dudas o críticas
constructivas en la parte de abajo, ahhh y votar también,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;saludos :D.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 16pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Georgia, Times New Roman, serif; font-size: large; line-height: 115%;&quot;&gt;Entradas Relacionadas:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;line-height: 18px;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/introduccion-java-nio.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Introducción a Java NIO&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Calibri, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/8218473426429306650/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/10/introduccion-java-nio-parte-2-final.html#comment-form' title='2 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/8218473426429306650'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/8218473426429306650'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/10/introduccion-java-nio-parte-2-final.html' title='Introducción a Java NIO - Parte 2 (Final)'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s72-c/JavaBlack.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-3918585051731102898</id><published>2012-10-24T13:45:00.000-07:00</published><updated>2012-10-24T13:45:21.631-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="E/S"/><category scheme="http://www.blogger.com/atom/ns#" term="Entradas y Salidas"/><category scheme="http://www.blogger.com/atom/ns#" term="I/O"/><category scheme="http://www.blogger.com/atom/ns#" term="I/O E/S"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java IO"/><category scheme="http://www.blogger.com/atom/ns#" term="Java magazine"/><category scheme="http://www.blogger.com/atom/ns#" term="Java NIO"/><category scheme="http://www.blogger.com/atom/ns#" term="Java NIO.2"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="NIO"/><category scheme="http://www.blogger.com/atom/ns#" term="NIO.2"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><title type='text'>Introducción a Java NIO</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;



&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s1600/JavaBlack.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;213&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s320/JavaBlack.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hola y buen día a
todos mis lectores, hoy, les tengo un artículo (o más bien un tutorial) de 2
partes muy interesante de la &lt;a href=&quot;http://www.oracle.com/technetwork/java/javamagazine/index.html&quot; target=&quot;_blank&quot;&gt;revista Java&lt;/a&gt;, como ya habrán leído en el título,
se trata del nuevo sistema de archivos :D &lt;b&gt;NIO.2&lt;/b&gt;,
espero les guste, aquí les va...&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyCIPfYe1hA0-03H3qibTWOOlEzG1kSis-WMNjBo-eTeg161GzIXDvyCnJBz9lsv0GBx4Q9NJevTDwx1wubF1jP_xq1IaDXBjMTubkEoBWAs5hNlulsHEqmg02w5PUuDsWLITGe6v88UEt/s1600/descarga.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyCIPfYe1hA0-03H3qibTWOOlEzG1kSis-WMNjBo-eTeg161GzIXDvyCnJBz9lsv0GBx4Q9NJevTDwx1wubF1jP_xq1IaDXBjMTubkEoBWAs5hNlulsHEqmg02w5PUuDsWLITGe6v88UEt/s1600/descarga.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot;&gt;Java SE 7 provee
nuevas adiciones a los paquetes NIO&lt;/span&gt;—&lt;span lang=&quot;ES&quot;&gt;las llamadas NIO.2 APIs de &lt;a href=&quot;http://jcp.org/en/jsr/detail?id=203&quot; target=&quot;_blank&quot;&gt;JSR 203&lt;/a&gt;&lt;/span&gt;—muchas de las cuales se concentran en las APIs
del sistema de archivos y canales asincrónicos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En el pasado, la
mayoría de las operaciones del sistema de archivos en Java eran realizadas
usando las clases del paquete &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;java.io&lt;/span&gt;&lt;/i&gt;
que proveen una abstracción de características dependientes del sistema.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Estas clases eran
débiles, por ejemplo, en tratar con permisos de archivo y manejando links
simbólicos. Muchas librerías eran desarrolladas para superar estas debilidades,
pero tienen el gasto adicional de contar ya sea con librerías nativas o
invocaciones a procesos externos. Otras librerías eran además desarrolladas
para tratar mejor con operaciones comunes del sistema de archivos (como copiar,
mover y exploración) o para proveer sistemas de archivos virtuales (como
archivos comprimidos, FTP y HTTP).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En este artículo,
vamos a concentrarnos en las adiciones de NIO relacionadas al sistema de
archivos: operaciones, manipulación de metadatos, y cambiar el monitoreo. Como
veremos, las APIs NIO.2 proveen elegantes adiciones al set de herramientas de
Java.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Primeros pasos&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Las adiciones a
NIO.2 están contenidas en su mayoría en los paquetes &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;java.nio.file&lt;/span&gt;&lt;/i&gt;.
Vamos a empezar con &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Path &lt;/span&gt;&lt;/i&gt;(ruta
en español), una interface clave de las nuevas APIs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;ES&quot;&gt;Paths
y archivos.&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;ES&quot;&gt; La interface &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt; es
una abstracción de un archivo o directorio dentro de un dado sistema de
archivo. Instancias de &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt;
pueden ser obtenidas usando la clase &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt;, que
comprende dos métodos &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;get()&lt;/span&gt;&lt;/i&gt;:
uno que toma una URI y uno que toma un número variable de elementos &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt;. Un ejemplo sería obtener una referencia
&lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt; al archivo &lt;i&gt;/etc/hosts&lt;/i&gt;, como se muestra a continuación:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
// Estas dos llamadas son equivalentes
Path hosts1 = Paths.get(&quot;/etc/hosts&quot;);
Path hosts2 = Paths.get(&quot;/etc&quot;, &quot;hosts&quot;);
// (...)
]]&gt;&lt;/script&gt;


&lt;span lang=&quot;ES&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot;&gt;Una
referencia&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4; mso-bidi-font-family: NeueSansPro-Normal; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt; ofrece métodos para comparar
rutas, resolver rutas contra otras rutas, y demás. La clase &lt;/span&gt;&lt;i style=&quot;line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Files&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt; es comúnmente usada para realizar
operaciones comunes en las rutas, incluyendo lo siguiente:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; line-height: 16pt; text-indent: -18pt;&quot;&gt;Crear
archivos, carpetas, y links simbólicos&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; line-height: 16pt; text-indent: -18pt;&quot;&gt;Copiar,
mover y borrar&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; line-height: 16pt; text-indent: -18pt;&quot;&gt;Consultando
atributos&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; line-height: 16pt; text-indent: -18pt;&quot;&gt;Iterar
sobre un árbol del sistema de archivos&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; line-height: 16pt; text-indent: -18pt;&quot;&gt;Obtener
flujos de lectura y escritura y canales&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; line-height: 16pt; text-indent: -18pt;&quot;&gt;Realizar
operaciones de escritura y lectura directamente.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Listar cada método en &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt; y &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Files&lt;/span&gt;&lt;/i&gt;
sería aburrido, así que en su lugar vamos a mirar algunos&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;ejemplos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Operaciones
simples. &lt;/b&gt;Vamos
a crear un directorio temporal y copiar un archivo en él.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;A
continuación (en el código de abajo) copiamos el archivo &lt;i&gt;asm&lt;/i&gt; a un archivo &lt;i&gt;asm-copy.jar&lt;/i&gt;
bajo una carpeta temporal como &lt;i&gt;/var/folders/cj/h0x5ghcd1tz5s7shyj8txxf00000gn/T/nio2134767717145250358&lt;/i&gt;.
Respectivos parámetros &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;CopyOptions&lt;/span&gt;&lt;/i&gt;
o no pueden ser provistos más probablemente de la enumeración &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;StandardCopyOption&lt;/span&gt;&lt;/i&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Path temp = Files.createTempDirectory(&quot;nio2&quot;);
Path asm = Paths.get(&quot;asm-all-2.2.3.jar&quot;);    
Files.copy(asm, temp.resolve(&quot;asm-copy.jar&quot;),
StandardCopyOption.COPY_ATTRIBUTES);
]]&gt;&lt;/script&gt;



En
el código de arriba&amp;nbsp;pedimos preservar los atributos del sistema de archivos, como el dueño del archivo, grupo y permisos. Otras opciones incluyen la habilidad realizar un movimiento atómico y reemplazar los archivos existentes. Hay además una enumeración LinkOption para prevenir la operación de copia de los siguientes links simbólicos.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hablando de links simbólicos, si un link simbólico al archivo de librería original Java (JAR) ASM no existe, podemos crear uno y consultar el tamaño del JAR, como se muestra a continuación:

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Path symlink = Paths.get(&quot;link&quot;);

if (Files.notExists(symlink)) {
  Files.createSymbolicLink(symlink, asm);
}
System.out.println(Files.size(symlink));
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;b&gt;Lecturas
y escrituras rápidas.&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;Leer y escribir contenidos de
archivo tradicionalmente ha requerido mucho código. La clase Files provee
métodos ayudantes rápidos para lectura y escritura de los contenidos de un
archivo como operaciones de “un tiro”. Ellas operan ya sea en Strings o en
arreglos de bytes “crudos”.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;A
continuación se muestra cómo podemos leer los contenidos de un archivo:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Path readme = Paths.get(&quot;README.txt&quot;);
List&lt;string&gt; lines = Files.readAllLines(readme, StandardCharsets.UTF_8);

for (String line : lines) {
  System.out.println(&quot;&gt;  &quot; + line);
}
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Integración con flujos existentes y APIs NIO.&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;Las APIs NIO.2 no están
destinadas a vivir en una isla desierta, así que proveen medios para
integración con existentes flujos y APIs NIO.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Los flujos (Streams) estilo I/O
&lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;java.io&lt;/span&gt;&lt;/i&gt; y los búfers pueden ser obtenidos
usando la clase &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Files&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;y sus&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;métodos &lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;newInputStream()&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;, &lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;newOutputStream()&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;,
&lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;newBufferedReader()&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt; y&lt;/span&gt;&lt;br /&gt;
&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;newBufferedWriter()&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Los canales NIO pueden ser obtenidos usando el método &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;newByteChannel()&lt;/span&gt;&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Curiosamente,
hay una versión del método &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;copy()&lt;/span&gt;&lt;/i&gt;
que puede ser usada cuando el “blanco” es una instancia de &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;java.io.OutputStream&lt;/span&gt;&lt;/i&gt;.
Un ejemplo de uso sería arrojar el contenido de un archivo al flujo de salida
estándar:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Files.copy(hello, System.out);
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Tratando
con los sistemas de archivos&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm -72pt 0cm 0cm;&quot;&gt;
&lt;div style=&quot;line-height: 16pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Como el nombre lo sugiere, la
clase &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileSystem&lt;/span&gt;&lt;/i&gt; representa una
abstracción de un sistema de&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;archivos.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;Provee muchos servicios útiles,
incluyendo la habilidad&amp;nbsp;&lt;/span&gt;para accesar a&lt;span style=&quot;line-height: 16pt;&quot;&gt;&amp;nbsp;archivos, carpetas,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;usuarios, grupos,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;o notificaciones de cambio del sistema de archivos.&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;line-height: 16pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; line-height: 16pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 16pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Obteniendo
y usando una referencia al sistema de archivos.&lt;/b&gt; &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileSystem&lt;/span&gt;&lt;/i&gt;
es una&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;clase abstracta.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Instancias pueden ser obtenidas usado el correspondiente
objeto de fábrica &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileSystems&lt;/span&gt;&lt;/i&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileSystems&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;contiene un método &lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;getDefault()&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt; que regresa el sistema de
archivos por &lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;default&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;que es, el
sistema de&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;archivos desde el cual la Máquina Virtual de Java fue invocada.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Podemos
obtener una referencia a este sistema de archivos por default así:

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
FileSystem fs = FileSystems.getDefault();
]]&gt;&lt;/script&gt;



No
todos los sistemas&amp;nbsp;de
archivos comparten las mismas propiedades. Mientras los sistemas operativos
derivativos de UNIX comparten una raíz de sistema de archivos unificada (/),
Microsoft Windows tiene una raíz por partición y disco (C:\, D:\ y demás).
Podemos revisar cuántas raíces tiene un dado sistema de archivos invocando el método
&lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;getRootDirectories()&lt;/span&gt;&lt;/i&gt;, el cual regresa un &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Iterable&amp;lt;Path&amp;gt;&lt;/span&gt;&lt;/i&gt;, como se muestra a
continuación:

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
for (Path root : fs.getRootDirectories()) {
  System.out.println(root);
}
]]&gt;&lt;/script&gt;


&lt;br /&gt;
Una
instancia de&amp;nbsp;&lt;i style=&quot;line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4; mso-bidi-font-family: NeueSansPro-Normal; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileSystem&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt; puede ser además usada para
devolver instancias de &lt;/span&gt;&lt;i style=&quot;line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;.
Los métodos en &lt;/span&gt;&lt;i style=&quot;line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt; incluyen manipulación
de métodos para comparar rutas, extraer sub-rutas, computar rutas relativas
entre rutas y demás.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Obteniendo
instancias de &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt; desde un objeto &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileSystem&lt;/span&gt;&lt;/i&gt; se hace invocando al método &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;getPath()&lt;/span&gt;&lt;/i&gt;, que toma un número variable de
argumentos String. Cada String representa una parte de la ruta como se muestra
a continuación:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Path main     = fs.getPath(&quot;src&quot;, &quot;discover&quot;, &quot;nio2&quot;, &quot;fs&quot;, &quot;Main.java&quot;);
Path alsoMain = fs.getPath(&quot;src/discover/nio2&quot;, &quot;fs&quot;, &quot;Main.java&quot;);
Path src      = fs.getPath(&quot;src&quot;);
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Podemos
comparar estas rutas así:

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
assert main.compareTo(alsoMain) == 0;
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;compareTo()&lt;/span&gt;&lt;/i&gt;
devuelve los valores usuales&amp;nbsp;&lt;span style=&quot;line-height: 16pt;&quot;&gt;-1, 0 y 1 para “menor que”,
“igual a” y “más que” respectivamente.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;A
continuación de muestra como una ruta puede ser convertida a una URI o
representación de archivo:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
// Something like 
// file:///Users/user/articles/nio2/code/src/discover/nio2/fs/Main.java
System.out.println(main.toUri());

// Something like &#39;821&#39;
System.out.println(main.toFile().length());

]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm -72pt 0cm 0cm;&quot;&gt;
&lt;div style=&quot;line-height: 16pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Además podemos realizar algunas
manipulaciones de ruta, como se muestra a continuación:

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
// &#39;../../..&#39;
System.out.println(main.getParent().relativize(src));

// &#39;src/discover&#39;
System.out.println(main.subpath(0, 2));

// &#39;discover/nio2/fs/Main.java&#39;
System.out.println(src.relativize(main));
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Escuchando
a los proveedores del sistema de archivos&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hay otros métodos de fábrica en
&lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileSystems&lt;/span&gt;&lt;/i&gt; que pueden construir instancias
de &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileSystem&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;de una URI&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;o ruta en un sistema
de archivos. Esto es especialmente útil cuando proveedores&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;concretos actúan
como&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;sistemas de archivo virtuales sobre archivos zip, conexiones HTTP o&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;FTP, o
unidades de red SMB.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; line-height: 16pt;&quot;&gt;Usando esta capacidad, puedes uniformemente manejar
sistemas de archivos “reales” y&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; line-height: 16pt;&quot;&gt;virtuales.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Es posible consultar el
proveedor del sistema de archivos disponible usando la clase&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileSystemProvider&lt;/span&gt;&lt;/i&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;una interfaz de
proveedor de servicio (SPI) que es parte del paquete&lt;/span&gt;&lt;br /&gt;
&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;java.nio.spi&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El
código mostrado a continuación (abajo) debe regresar tanto el archivo como los
esquemas&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;JAR URI para&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;muchas instalaciones de Java SE 7:&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;
Aunque
la especificación no requiera&amp;nbsp;&lt;span style=&quot;line-height: 16pt;&quot;&gt;que un proveedor de esquema JAR
esté disponible,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;JDK 7 y&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;OpenJDK proveen uno. Puedes tomar ventaja de la
habilidad de los SPI’s para&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;aportar sus propios&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;proveedores de sistema de
archivos (HTTP, FTP, y demás), aunque&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;hacer eso está más allá de la mira de&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;este artículo.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Vamos ahora más lejos a
investigar las APIs NIO.2 abriendo un archivo zip como un archivo&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;de proveedor&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;de sistema y “caminarlo”.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Caminando
un proveedor de sistema de archivo&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La clase java.io.File tiene
métodos list() y listFiles(). Ellos pueden ser usados para instancias&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;de File
que&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;representan una carpeta, y regresan una lista de archivos y carpetas que
son&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;“hijos directos” (que están&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;dentro de la carpeta).&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Un mecanismo un poco más
poderoso es provisto con la clase java.nio.file.Files: visitores de&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;archivos y&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;flujos de carpeta, los cuales pueden realizar filtros selectivos y
combinaciones&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;(matching) para elementos&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;descubiertos.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Veremos estas capacidades en el
remanente de esta sección.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Abriendo un sistema de archivo zip.&lt;/b&gt;
Vamos a abrir un JAR como sistema de archivo,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;como se muestra a&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;continuación:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
URI asm = URI.create(&quot;file:/tmp/asm-all-2.2.3.jar&quot;);
try (FileSystem fs = FileSystems.newFileSystem(
        Paths.get(asm),
        Main.class.getClassLoader())) { 
  ...
}
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm -72pt 0cm 0cm;&quot;&gt;
&lt;div style=&quot;line-height: 16pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La
clase &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileSystems&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;provee
otros métodos de fábrica &lt;/span&gt;&lt;i style=&quot;line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;newFileSystem&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;,
incluyendo uno que&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;toma un mapa&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;de configuración como parámetro y usa claves
específicas del proveedor. El&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;formato mostrado en el&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;código anterior (arriba),
el cual toma un &lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt; y un &lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;ClassLoader&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;, es el&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;formato preferido para
abrir un&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;sistema de archivo sobre un archivo.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 16pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0cm 0cm;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;A causa de que &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileSystem&lt;/span&gt;&lt;/i&gt; implementa &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;AutoCloseable&lt;/span&gt;&lt;/i&gt;,
podemos usarlo como parte de una&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;sentencia&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;try-&lt;/span&gt;with-resources&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;
que asegura que el método &lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;FileSystem.close()&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;
sea llamado, sin&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;importar si una&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;excepción es lanzada.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 16pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Combinaciones de ruta.&lt;/b&gt; En
este ejemplo, estamos interesados en imprimir todos los&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;archivos &lt;i&gt;.class&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;contenidos dentro del archivo.
Podemos tomar ventaja de &lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;PathMatcher&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;
para&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;combinar (match) objetos&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;Path&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt; ya
sea contra una expresión regular o un archivo de sintaxis&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;glob usando el método
&lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;match()&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;, como se&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;muestra a continuación:&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 16pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;
Una
expresión&amp;nbsp;&lt;i style=&quot;line-height: 16pt;&quot;&gt;path
matcher&lt;/i&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt; tiene
la forma &lt;/span&gt;&lt;i style=&quot;line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;“glob:&amp;lt;glob-expression&amp;gt;”&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;
o &lt;/span&gt;&lt;span style=&quot;color: #548dd4; line-height: 16pt;&quot;&gt;“regexp:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;color: #548dd4; line-height: 16pt;&quot;&gt;&amp;lt;regular-expression&amp;gt;”&lt;/span&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 16pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;Una expresión como &lt;/span&gt;&lt;i style=&quot;line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;“glob:/foo/*.{java,class}”&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;
combina cualquier archivo .java o .class&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt;&quot;&gt;dentro de /foo.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0.0001pt 0cm;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0.0001pt 0cm;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Visitantes
de archivos.&lt;/b&gt;
El patrón de diseño &lt;i&gt;Visitor&lt;/i&gt; encaja
bien con la necesidad de&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;“caminar” un árbol de&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;sistema archivos y tomar
acciones en archivos. La interface&lt;/span&gt;&lt;br /&gt;
&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;FileVisitor&amp;lt;T&amp;gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;
define varios métodos para las&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;siguientes circunstancias:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm -72pt 0.0001pt 0cm;&quot;&gt;
&lt;/div&gt;
&lt;ul style=&quot;line-height: 16pt;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt; text-indent: -18pt;&quot;&gt;Un
&lt;/span&gt;&lt;i style=&quot;line-height: 16pt; text-indent: -18pt;&quot;&gt;visitor&lt;/i&gt;&lt;span style=&quot;line-height: 16pt; text-indent: -18pt;&quot;&gt; que es notificado antes y
después de entrar a una carpeta&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt; text-indent: -18pt;&quot;&gt;Un
&lt;/span&gt;&lt;i style=&quot;line-height: 16pt; text-indent: -18pt;&quot;&gt;visitor&lt;/i&gt;&lt;span style=&quot;line-height: 16pt; text-indent: -18pt;&quot;&gt; que es notificado cuando se
visita un archivo&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;line-height: 16pt; text-indent: -18pt;&quot;&gt;Un
&lt;/span&gt;&lt;i style=&quot;line-height: 16pt; text-indent: -18pt;&quot;&gt;visitor&lt;/i&gt;&lt;span style=&quot;line-height: 16pt; text-indent: -18pt;&quot;&gt; que es notificado cuando se
visita un archivo a través de una excepción&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; line-height: 21.33333396911621px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm -72pt 0.0001pt 0cm;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: -72.0pt; margin-top: 0cm; mso-layout-grid-align: none; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Además, los métodos de &lt;i&gt;FileVisitor&lt;/i&gt; regresan un valor como parte
de la enumeración&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;FileVisitResult&lt;/span&gt;&lt;/i&gt; para&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;encargar que el “caminar” sea continuado, sea terminado, se salte los&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;hermanos
(&lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;siblings&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;), o salte un&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;subtree&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; line-height: 16pt;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hay
además una implementación por default llamada &lt;i&gt;&lt;span style=&quot;color: #548dd4; mso-themecolor: text2; mso-themetint: 153;&quot;&gt;SimpleFileVisitor&amp;lt;T&amp;gt;&lt;/span&gt;&lt;/i&gt;
que puede ser&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;sobreescrita. En&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;nuestro caso, podemos caminar el fichero del
sistema de archivos desde su&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;raíz e imprimir rutas de&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;archivo &lt;/span&gt;&lt;i style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;span style=&quot;color: #548dd4;&quot;&gt;.class&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;, como se muestra a continuación:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm -72pt 0.0001pt 0cm;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Files.walkFileTree(fs.getPath(&quot;/&quot;), new SimpleFileVisitor&lt;path&gt;() {
  @Override
  public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
      throws IOException {
    if (matcher.matches(file)) {
      System.out.println(file);
    }
    return FileVisitResult.CONTINUE;
  }
});
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm -72pt 0.0001pt 0cm;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Podemos
con seguridad ignorar el parámetro attrs del método visitiFile() por el momento;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;vamos a&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;examinar como los atributos de archivos pueden ser manipulados después.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm -72pt 0.0001pt 0cm;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Y bueno, eso es todo por hoy, en la&amp;nbsp;próxima&amp;nbsp;entrada viene la segunda parte de esto, por&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;cierto, si notan&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;las cajas de código algo raras o el texto, creo que es culpa de Blogger, anda&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;raro hoy :S, o quizá me metí&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;demasiado en el HTML :P. Ya saben,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;suscríbanse ya sea por&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;correo o por RSS o Atom, dudas, peticiones,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;comentarios o criticas constructivas&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;son bien&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;recibidas en la parte de abajo, saludos.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 16pt; margin: 0cm -72pt 0.0001pt 0cm;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;line-height: 16.0pt; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: -72.0pt; margin-top: 0cm; mso-add-space: auto; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; mso-pagination: none; tab-stops: right 279.0pt; text-autospace: none; text-indent: -18.0pt;&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/3918585051731102898/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/10/introduccion-java-nio.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/3918585051731102898'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/3918585051731102898'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/10/introduccion-java-nio.html' title='Introducción a Java NIO'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s72-c/JavaBlack.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-6164444923179382843</id><published>2012-10-20T12:49:00.000-07:00</published><updated>2012-10-22T13:24:39.603-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Consola"/><category scheme="http://www.blogger.com/atom/ns#" term="Consola Java"/><category scheme="http://www.blogger.com/atom/ns#" term="E/S"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse ide"/><category scheme="http://www.blogger.com/atom/ns#" term="Entradas y Salidas"/><category scheme="http://www.blogger.com/atom/ns#" term="I/O"/><category scheme="http://www.blogger.com/atom/ns#" term="I/O E/S"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java IO"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><title type='text'>Entradas y Salidas en Java – Lo básico</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;



&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGIj_p41y2zwBfKgBvCRBHiyw1JB9Fv6YEI4u-spOm0WhYt_tp-Lz9I0TXgmW-j5teJohIdNod4pAm7suB4ojsAuqxbSsTUtrvhnKHpxyve0M2x7lic04C3xqVDxPySP6GFogBAyOzOIe_/s1600/images.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGIj_p41y2zwBfKgBvCRBHiyw1JB9Fv6YEI4u-spOm0WhYt_tp-Lz9I0TXgmW-j5teJohIdNod4pAm7suB4ojsAuqxbSsTUtrvhnKHpxyve0M2x7lic04C3xqVDxPySP6GFogBAyOzOIe_/s1600/images.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hola y buen día a
todos mis lectores, hoy, me dieron ganas de escribirles sobre algo que es muy
importante para nosotros los programadores: Las entradas y salidas, como he
dicho antes, esto es algo a lo que muchos “le temen” y más aún si han migrado
de Visual Basic a Java, pero realmente es algo muy extensible y fácil de usar
una vez que aprendemos, aquí les tengo una pequeña cita que me gustaría
compartir…&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;i&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;i&gt;&lt;span lang=&quot;ES&quot;&gt;Entradas y salidas (E/S en español, I/O en inglés,
para abreviar)&amp;nbsp; son fundamentales para
cualquier sistema operativo o lenguaje de programación. Sólo los teoristas
encuentran interesante escribir programas que no requieran entrada o produzcan
salida. Al mismo tiempo, I/O – E/S (Lo llamaré I/O de ahora en adelante)
difícilmente califica como uno de los temas más emocionantes en la ciencia de
la computación. Es algo en el fondo, algo que usas cada día&lt;/span&gt;—pero para muchos desarrolladores,
no es un tema con mucho “sex appeal”.&lt;/i&gt;&lt;/span&gt;&lt;blockquote&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Elliote Rusty
Harold.&lt;/span&gt;&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyCIPfYe1hA0-03H3qibTWOOlEzG1kSis-WMNjBo-eTeg161GzIXDvyCnJBz9lsv0GBx4Q9NJevTDwx1wubF1jP_xq1IaDXBjMTubkEoBWAs5hNlulsHEqmg02w5PUuDsWLITGe6v88UEt/s1600/descarga.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyCIPfYe1hA0-03H3qibTWOOlEzG1kSis-WMNjBo-eTeg161GzIXDvyCnJBz9lsv0GBx4Q9NJevTDwx1wubF1jP_xq1IaDXBjMTubkEoBWAs5hNlulsHEqmg02w5PUuDsWLITGe6v88UEt/s1600/descarga.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot;&gt;Me gustaría
extenderme sobre todo lo relacionado con I/O, comenzar desde InputStream y
OutputStream (lo cubriré en otro tema), pero, ¿quién usa un FileInputStream cuando se tiene un
FileReader (&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/leer-un-archivo-de-texto-en-java.html&quot; target=&quot;_blank&quot;&gt;ver ejemplo de uso&lt;/a&gt;), o igual quién usa un FileOutputStream cuando se tiene un FileWriter&amp;nbsp;&lt;/span&gt;(&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/escribir-un-archivo-de-texto-en-java.html&quot; target=&quot;_blank&quot;&gt;ver ejemplo de uso&lt;/a&gt;)?,
por lo tanto, lo que voy a hacer es saltarme las “partes aburridas” (InputStream
y OutputStream que nadie usa) y pasar a las excepciones, la consola, etc. Aquí
les va:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Excepciones al utilizar I/O&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Todos sabemos que
al escribir código en Java tenemos que tratar muchas veces con las excepciones,
ya sea que dividamos entre 0 (Lanza una excepción del tipo &lt;i&gt;ArithmeticException&lt;/i&gt;), que tratemos de llamar a una posición en un
arreglo que es mayor a su tamaño (&lt;i&gt;ArrayIndexOutOfBoundsException&lt;/i&gt;),
etc, etc. En este tema de las entradas y salidas, esto no cambia, cada que
realizamos alguna operación que tome entrada o dé salida, tendrás que tratar
una excepción del tipo &lt;i&gt;IOException&lt;/i&gt; y
puedes hacer esto de dos formas:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Que declares
&lt;/span&gt;&lt;i style=&quot;text-indent: -18pt;&quot;&gt;throws IOException&lt;/i&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; en el método donde
realizas entradas o salidas.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Que
encierres la operación en un bloque &lt;/span&gt;&lt;i style=&quot;text-indent: -18pt;&quot;&gt;try/catch&lt;/i&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La primera opción
es mejor si quieres que quién llame el método tenga más control sobre qué hacer
si algo sale mal (que se genere la excepción), la segunda es mejor si quieres
que el bloque &lt;i&gt;try/catch&lt;/i&gt; se haga cargo
de todo, por ejemplo, que muestre un mensaje de error con un dialogo y que llame
al método &lt;i&gt;printStackTrace &lt;/i&gt;(seguimiento
de la pila), es importante saber que no hay ninguna diferencia entre tratar una
excepción de este tipo que en la que se trataría cualquier otra excepción.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Tratando con la consola&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Primero que nada
daré una pequeña definición de la consola: Llamamos consola (incorrectamente
por cierto, pero la llamaré así por costumbre y comodidad del lector) a ese
lugar donde normalmente vemos los mensajes que ponemos ya sea en &lt;i&gt;System.out.print&lt;/i&gt; (o &lt;i&gt;println&lt;/i&gt;), &lt;i&gt;System.err.print &lt;/i&gt;(o
&lt;i&gt;println&lt;/i&gt; también) o de donde normalmente
obtenemos la entrada de &lt;i&gt;System.in&lt;/i&gt;. La
veremos en distintas formas dependiendo del entorno de desarrollo o sistema
operativo que usemos, por ejemplo si estás utilizando Eclipse, verás la consola
en una pestaña normalmente en la parte inferior de la ventana de tu IDE (Integrated
Development Environment, Entorno de Desarrollo Integrado en español),&amp;nbsp; si usas Windows como sistema operativo, puede
que veas la consola en una ventana de línea de comandos, igual es para Mac y
Unix.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¿La consola como GUI?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La mayoría de
nosotros (Incluido yo) utilizamos la consola al inicio de nuestro aprendizaje del
lenguaje para ver lo que hacía nuestro código o simplemente comprobar al final
que hacíamos bien las cosas, yo en lo personal aún la uso cuando no sé si mi
error está en la interfaz (GUI) o en otra parte del código, también para probar
código para el cual aún no tengo una GUI, para mí es un método muy útil para
diagnosticar cual método o instrucción falla, pero algo muy importante que
debemos recordar, es que &lt;b&gt;¡La consola no
es una buena GUI!&lt;/b&gt; En estos tiempos, yo no veo casi ninguna razón (por no
decir que ya no la hay en lo absoluto) para pensar en utilizar la consola como
interfaz de usuario, por mínima que sea la interfaz, una cosa es usar la
consola en tiempo de desarrollo para tratar de darte cuenta donde te
equivocaste, y otra muy distinta es que tus programas ya dirigidos al usuario la
utilicen. Algunos quizá piensen ¿No se debe usar la consola solo por cuestión
de estética? Pues no es así, la consola, además de ser una interfaz de usuario
muy fea y poco versátil, tiene aún más desventajas, por ejemplo:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-indent: -18pt;&quot;&gt;Puede
confundir al usuario (incluso hacerle pensar que el programa no funciona bien).&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-indent: -18pt;&quot;&gt;No
puedes mostrar botones, combos, cajas de texto, etc.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-indent: -18pt;&quot;&gt;No es nada fácil &amp;nbsp;de usar para el usuario final.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;En
sistemas operativos como Mac y en algunos navegadores, la consola no admite entradas (&lt;/span&gt;&lt;i style=&quot;text-indent: -18pt;&quot;&gt;System.in&lt;/i&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;), sólo salidas (&lt;/span&gt;&lt;i style=&quot;text-indent: -18pt;&quot;&gt;System.out&lt;/i&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; y &lt;/span&gt;&lt;i style=&quot;text-indent: -18pt;&quot;&gt;System.err&lt;/i&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;).&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Conociendo &lt;i&gt;System.out&lt;/i&gt;
a fondo&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La mayoría
llegamos a utilizar &lt;i&gt;System.out&lt;/i&gt;
incluso antes de saber lo que es una clase o un OutputStream. Específicamente, &lt;i&gt;System.out&lt;/i&gt; es el campo estático de la
clase &lt;i&gt;java.lang.System&lt;/i&gt;. Es una
instancia de &lt;i&gt;java.io.PrintStream&lt;/i&gt;, que
es una subclase de &lt;i&gt;java.io.OutputStream&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;i&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;System.out&lt;/span&gt;&lt;/i&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt; corresponde a &lt;i&gt;stdout&lt;/i&gt;
en Unix o C. Normalmente, la salida enviada a &lt;i&gt;System.out&lt;/i&gt; aparece en la consola. Como regla general, la consola
convierte los datos numéricos byte que envía &lt;i&gt;System.out&lt;/i&gt; en texto ASCII o ISO Latin-1. Por lo tanto, el siguiente
código escribe la cadena “Hello World!” en la consola:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import java.io.IOException;

public class HolaMundo {

 public static void main(String[] args) {
  try {
   byte[] hello = { 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 10, 13 };
   System.out.write(hello);
  }
  catch (IOException e) {
   //Se ejecuta si algo salió mal en la escritura:
   e.printStackTrace();
  }
 }

}

]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Conociendo &lt;i&gt;System.err
&lt;/i&gt;a fondo&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Los programadores
de Unix y C reconocen &lt;i&gt;stderr&lt;/i&gt;, que es comúnmente
usado para mensajes de error. &lt;i&gt;stderr&lt;/i&gt; es
un puntero de archivo separado de &lt;i&gt;stdout&lt;/i&gt;,
pero muchas veces significa lo mismo. Generalmente tanto &lt;i&gt;stderr&lt;/i&gt; como &lt;i&gt;stdout&lt;/i&gt; envían
datos a la consola, cualesquiera que estos sean. De todas formas, &lt;i&gt;stdout&lt;/i&gt; y &lt;i&gt;stderr&lt;/i&gt; pueden ser redireccionados a diferentes lugares. Por
ejemplo, la salida puede ser redireccionada a un archivo mientras los mensajes
de error aún aparecen en la consola.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;i&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;System.err&lt;/span&gt;&lt;/i&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt; es la versión de Java de &lt;i&gt;stderr&lt;/i&gt;. Como &lt;i&gt;System.out&lt;/i&gt;, &lt;i&gt;System.err&lt;/i&gt; es una instancia de &lt;i&gt;java.io.Printstream&lt;/i&gt;, una subclase de &lt;i&gt;java.io.OutputStream&lt;/i&gt;. &lt;i&gt;System.err&lt;/i&gt; es comúnmente más usado
dentro de la clausula &lt;i&gt;catch&lt;/i&gt; de un
bloque &lt;i&gt;try/catch&lt;/i&gt; así:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
try{
 //Hacer algo que quizá lance una excepción.
}
catch(Exception e){
 System.err.println(e);
}

]]&gt;&lt;/script&gt;


&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Conociendo &lt;i&gt;System.in&lt;/i&gt; a fondo&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;i&gt;&lt;span lang=&quot;ES&quot;&gt;Sytem.in&lt;/span&gt;&lt;/i&gt;&lt;span lang=&quot;ES&quot;&gt; es el flujo de entrada conectado a la consola, tanto como &lt;i&gt;System.out&lt;/i&gt; es el flujo de salida
conectado a la consola. En términos Unix o C, &lt;i&gt;System.in&lt;/i&gt; es el campo estático de la clase &lt;i&gt;java.lang.System&lt;/i&gt;. Es una instancia de &lt;i&gt;java.io.InputStream&lt;/i&gt;, al menos hasta donde está documentado.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Pasado lo que
está documentado, &lt;i&gt;System.in&lt;/i&gt; es en
realidad un &lt;i&gt;java.io.BufferedInputStream&lt;/i&gt;.
&lt;i&gt;BufferedInputStream&lt;/i&gt; no declara
métodos nuevos, solo reescribe los que ya están declarados en &lt;i&gt;java.io.InputStream&lt;/i&gt;. &lt;i&gt;BufferedInputStream&lt;/i&gt; lee los datos en grandes
pedazos en dentro de un búfer, entonces reparte los datos en los tamaños
pedidos. Esto puede ser más eficiente que leer un carácter a la vez. De tal manera
que, es completamente transparente para el programador.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La razón
principal de esto es que cada byte no se presentado para ser leído mientras el
usuario lo escribe en &lt;i&gt;System.in&lt;/i&gt;. En
su lugar, la entrada entra en el programa de una línea a la vez. Esto permite
al usuario escribir en la consola la tecla de retroceso para corregir errores.
Java no te permite poner la consola en un “modo sin procesar”, donde cada carácter
se vuelve disponible tan pronto como es escrito, incluyendo caracteres como &lt;i&gt;backspace&lt;/i&gt; (retroceso) y &lt;i&gt;delete&lt;/i&gt; (borrar).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Bien, eso es todo por hoy, no olviden que pueden
suscribirse a mis entradas por medio de su correo (en la parte superior derecha),
RSS o Atom (en la parte inferior derecha), y pues ya saben, dudas, comentarios,
criticas (constructivas) o peticiones son bien recibidas en la parte de abajo,
saludos :D.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;color: blue; font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/escribir-un-archivo-de-texto-en-java.html&quot; target=&quot;_blank&quot;&gt;Escribir un archivo de texto en Java&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/leer-un-archivo-de-texto-en-java.html&quot; target=&quot;_blank&quot;&gt;Leer un archivo de texto en Java&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/6164444923179382843/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/10/entradas-y-salidas-lo-basico.html#comment-form' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/6164444923179382843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/6164444923179382843'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/10/entradas-y-salidas-lo-basico.html' title='Entradas y Salidas en Java – Lo básico'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGIj_p41y2zwBfKgBvCRBHiyw1JB9Fv6YEI4u-spOm0WhYt_tp-Lz9I0TXgmW-j5teJohIdNod4pAm7suB4ojsAuqxbSsTUtrvhnKHpxyve0M2x7lic04C3xqVDxPySP6GFogBAyOzOIe_/s72-c/images.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-2973152028610526675</id><published>2012-10-16T13:07:00.000-07:00</published><updated>2012-10-22T11:33:10.892-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eclipse ide"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Leer archivo de texto"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><category scheme="http://www.blogger.com/atom/ns#" term="sql"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL 92"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL y Java"/><category scheme="http://www.blogger.com/atom/ns#" term="sqlite"/><category scheme="http://www.blogger.com/atom/ns#" term="SQLITE y Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Utilizar SQLITE y Java"/><title type='text'>Utilizando SQLITE en Java</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;



&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhULRnYKzdeMlEYYRPf5PNazWgj67Yo55jIwnE9Uj4t6X9eLDbXbyjd92GYMOpHKfdPWb_RgajF7CLXCxDSI5uvoB4bilkcNKoFiM6Wvijb6_UID1ydQ4DKLraaQ1j7rsnd4GQtnB0-dZU2/s1600/SQLITE+Logo.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhULRnYKzdeMlEYYRPf5PNazWgj67Yo55jIwnE9Uj4t6X9eLDbXbyjd92GYMOpHKfdPWb_RgajF7CLXCxDSI5uvoB4bilkcNKoFiM6Wvijb6_UID1ydQ4DKLraaQ1j7rsnd4GQtnB0-dZU2/s1600/SQLITE+Logo.jpg&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s1600/JavaBlack.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;133&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s200/JavaBlack.jpg&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hola y buen día a
todos mis lectores, después de 8 días sin subir entradas a mi blog, hoy por fin
me decidí a hacerlo. Hace casi un mes publiqué una entrada sobre &lt;a href=&quot;http://baro3495.blogspot.com/2012/09/como-instalar-sqlite-en-eclipse-ide.html&quot; target=&quot;_blank&quot;&gt;cómo instalarSQLITE en Eclipse IDE&lt;/a&gt;, y prometí que publicaría otra sobre cómo utilizar la
librería, así que aquí les va:&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;b&gt;&lt;span lang=&quot;ES&quot;&gt;¿Cómo crear el archivo de la base de datos?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;El archivo de la base de datos se crea automáticamente
cuando realizamos una conexión a la base de datos, aunque no exista, digamos
que realizo una conexión a esta ruta:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
BaseDeDatos.conectarA(&quot;C:\Documentos\nueva.db&quot;);
]]&gt;&lt;/script&gt;


&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Antes
de llamar al método &lt;i&gt;conectarA&lt;/i&gt; no
existía un archivo llamado &lt;i&gt;nueva.db&lt;/i&gt; pero
al momento de que se realiza la conexión tal archivo “se crea solo”.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Realizando la conexión&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;

&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt;&quot;&gt;Lo primero, y lo más importante siempre que hagamos
una consulta, actualización o alguna otra cosa en la base de datos es realizar
la conexión a la misma, para esto, yo recomiendo toda una clase que se encargue
de obtener y devolver la conexión como se muestra a continuación:&lt;/span&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Clase simple que se encarga de pasar la conexión a la base de datos.
 * @author Gustavo Hernández Salinas
 */
public final class BaseDeDatos {
 
 /**
  * Conecta a una base de datos en la ruta pasada como argumento.
  * Si el archivo señalado en la ruta no existe, se crea.
  * @param ruta - La ruta de la DB a conectar.
  * @return La conexión a la ruta.
  */
 private static Connection conectarA(String ruta){
  try {
   //Aquí cargamos el driver de SQLITE.
   Class.forName(&quot;org.sqlite.JDBC&quot;);
  }
  catch (ClassNotFoundException e) {
   //Esto se ejecuta si hay un error con el driver de la base de datos.
   e.printStackTrace();
  }
  
  //Declaramos la conexión:
  Connection conn = null;

  try {
   //Aquí se obtiene la conexión:
   conn = DriverManager.getConnection(&quot;jdbc:sqlite:&quot; + ruta);
   //Un mensaje en la consola para saber si se realizó la conexión y donde está el archivo:
   System.out.println(&quot;Conexión realizada correctamente - Ruta de base de datos: &quot; + ruta);
  }
  catch (SQLException e) {
   //Esto se ejecuta si hay un error en la base de datos:
   e.printStackTrace();
  }
  
  //Devolvemos la conexión:
  return conn;
 }
 
 public static void main(String[] args) {
  //Pasamos una ruta a la cual conectar:
  Connection conn = BaseDeDatos.conectarA(&quot;C:/Documentos/nueva.db&quot;);
  
  /*
   * Aquí se supone que hacemos lo que necesitamos en la base de datos
   * ya sea una consulta, creación de una tabla, actualización de la
   * misma, etc.
   */
  
  try {
   //Y para terminar cerramos la conexión
   conn.close();
  }
  catch (SQLException e) {
   //Esto se ejecuta si hay algún problema al realizar la conexión.
   e.printStackTrace();
  }
 }
}

]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt;&quot;&gt;Esto
puede ser suficiente para la mayoría de las aplicaciones que requieran una base
de datos, pero, para los que requieran algo un poco más complejo, podemos
mejorar este código para cumplir con los siguientes aspectos:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-indent: -18pt;&quot;&gt;Que
el usuario pueda elegir donde guardar el archivo de la base de datos.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-indent: -18pt;&quot;&gt;En
caso de que no elija uno, guardar el archivo en una ubicación por default.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Estos dos puntos
mejorarían mucho nuestra aplicación por varias razones, la más importante es
que la base de datos puede ir en una ubicación extraíble como una memoria USB o
que el usuario podrá recordar donde puso la base de datos (no siempre es
recomendable esto ya que podría modificarla o eliminarla, pero depende del uso
que se le dará a aplicación), etc.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Pero agregar
estas características a nuestro programa va a complicar un poco (mucho la
verdad) el código, les mostraré como lo hice yo, obviamente quizá para ustedes
no sea la mejor forma de hacerlo, siéntanse libres de mejorar el código a su
gusto, pero si lo hacen procuren publicarlo en un comentario, recuerden que
este es un blog para aprender del lenguaje.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Primero necesitamos otra clase, que se encargue de
manejar la ruta en donde estará nuestra base de datos y para comodidad del
usuario, emplearemos un selector de carpetas muy parecido al que usamos en mi
entrada llamada &lt;a href=&quot;http://baro3495.blogspot.com/2012/10/leer-un-archivo-de-texto-en-java.html&quot; target=&quot;_blank&quot;&gt;Leer un archivo de texto en Java&lt;/a&gt;, el selector de carpetas se
encargará de tomar la ruta que el usuario seleccione para guardar la base de
datos y la guardará en un archivo de texto para no tener que hacer esto cada
vez que realicemos una conexión a la base de datos, también vamos a modificar bastante la clase &lt;i&gt;BaseDeDatos&lt;/i&gt; aquí les va el código
completo:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JFileChooser;

/**
 * Clase que se encarga de manejar la dirección de 
 * almacenamiento de la ruta de la base de datos en uso.
 * @author Gustavo Hernández Salinas
 */
public final class RutaDB {
 //Nombre del archivo que guarda dirección de donde esta la base de datos:
 public static final String NOMBRE_ARCHIVO_RUTA = &quot;Ruta.info&quot;;
 
 //Nombre de la base de datos:
 public static final String NOMBRE_DB = &quot;nueva.db&quot;;
 
 
 /**
  * Lanza un selector de carpetas para que el usuario
  * seleccione la carpeta donde irá la base de datos.
  * @throws IOException
  */
 public static void lanzarFolderChooser() throws IOException{
  //Instanciamos un JFileChooser y pasamos como argumento la dirección de inicio (argumento opcional).
  JFileChooser jfc = new JFileChooser(new File(System.getProperty(&quot;user.home&quot;)).toString());
  
  //Le indicamos al JFileChooser que solo queremos seleccionar carpetas.
  jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  
  //Guardamos el resultado de la selección en &#39;resultado&#39;:
  int resultado = jfc.showSaveDialog(null);
  
  //Damos un título al dialogo (opcional):
  jfc.setDialogTitle(&quot;Seleccione una ruta para la base de datos: &quot;);
  
  //Evaluamos el resultado, si el usuario ha seleccionado una carpeta:
  if(resultado == JFileChooser.APPROVE_OPTION){
  
   //Guardamos la carpeta seleccionada en &#39;dir&#39;
   File dir = jfc.getSelectedFile();
   
   //Si el archivo no es nulo:
   if(dir != null){
    //Ponemos en la consola la dirección de lo que el usuario seleccionó:
    System.out.println(&quot;Seleccionado: &quot; + dir.getAbsolutePath());
    
    //Escribimos la ruta seleccionada en un archivo:
    escribirRuta(dir.getAbsolutePath());
   }
   else{
    //Si el usuario no seleccionó nada:
    System.err.println(&quot;Selección nula&quot;);
   }//Fin del if/else
   
  } //Fin del if
 }
 
 /**
  * Escribe en un archivo la ruta de la base de datos, de
  * manera que el usuario pueda elegir donde almacenarla. 
  * @param ruta - La ruta de la base de datos.
  * @throws IOException
  */
 public static void escribirRuta(String ruta) throws IOException{
  //Obtenemos el archivo donde escribiremos la ruta de donde está nuestra base de datos:
  File archivo = obtenerArchivoRutaDB();
  
  //Instanciamos el escritor de archivo:
  FileWriter fw = new FileWriter(archivo);
  
  //Instanciamos la carpeta donde estará nuestra base de datos.
  File archivoDB = new File(ruta);
  
  //Le damos el nombre al archivo que estará dentro de la carpeta seleccionada.
  archivoDB = new File(ruta, NOMBRE_DB);
  
  //Escribimos la ruta completa de donde estará nuestro archivo de la base de datos:
  fw.write(archivoDB.getAbsolutePath());
  
  //Limpiamos el escritor de archivo:
  fw.flush();
  
  //Cerramos el escritor de archivo:
  fw.close();
 }
 
 /**
  * Devuelve la ruta de la base de datos para poder conectar
  * con la misma.
  * @return Ruta de la base de datos.
  * @throws IOException
  */
 public static String leerRuta() throws IOException{
  //Se obtiene el archivo donde tenemos escrita la dirección de la base de datos.
  File archivo = obtenerArchivoRutaDB();
  
  //No se necesita una referencia futura del FileReader, por eso se pone dentro del constructor del búfer.
  BufferedReader bf = new BufferedReader(new FileReader(archivo));
  
  //Ponemos en un String la ruta de la base de datos que está escrita en el archivo:
  String ruta = bf.readLine();
  
  //Devolvemos la ruta de la base de datos:
  return ruta;
 }
 
 /**
  * Devuelve el archivo de la ruta de la base de datos.
  * @return - El archivo de la ruta base de datos.
  */
 public static File obtenerArchivoRutaDB(){
  //Obtenemos la carpeta raíz (la carpeta donde tendremos nuestro archivo de la ruta de la base de datos).
  File f = obtenerCarpetaRaíz();
  
  //Damos nombre al archivo de texto donde está escrita la ruta de la base de datos:
  f = new File(f, NOMBRE_ARCHIVO_RUTA);
  
  //Devolvemos el archivo de texto.
  return f;
 }
 
 /**
  * Ruta que se obtiene por default en caso de que el usuario no defina una ruta alterna para la base de datos.
  * @return La dirección de la base de datos por default.
  */
 public static File obtenerDBDefault(){
  //Obtenemos la carpeta raíz (la carpeta donde tendremos nuestro archivo de la ruta de la base de datos).
  File f = obtenerCarpetaRaíz();
  
  //Damos nombre a la base de datos por default, en este caso &#39;nueva.db&#39;.
  f = new File(f, NOMBRE_DB);
  
  //Devolvemos el archivo de la ruta de la base de datos.
  return f;
 }
 
 /**
  * Representa la carpeta donde se almacenará el archivo
  * de la ruta de base de datos.
  * @return El archivo de la carpeta.
  */
 public static File obtenerCarpetaRaíz(){
  //Nombre de la carpeta, en mi caso, &#39;mi_aplicacion&#39; pero puede llamarse como quieran:
  String carpeta = &quot;mi_aplicacion&quot;;
  
  //Obtenemos la carpeta raíz del usuario, que será donde crearemos otra carpeta
  File f = new File(System.getProperty(&quot;user.home&quot;));
  
  //Agregamos a la carpeta raíz del usuario otra carpeta donde pondremos nuestras cosas:
  f = new File(f, carpeta);
  
  //Si la carpeta existe, no pasa nada, si no existe, la crea:
  f.mkdir();
  
  //Devolvemos la carpeta:
  return f;
 }
 
}


import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author Gustavo Hernández Salinas
 * Clase que se encarga de pasar la conexión a la base de datos, 
 * crearla en cualquier ruta definida por el usuario y guardar
 * un archivo que indica donde se encuentra la DB.
 */
public final class BaseDeDatos {
 
 /**
  * Pone una ruta para la base de datos elegida por el usuario.
  */
 public static void ponerRutaDB(){
  try {
   //Lanza el selector de carpetas en RutaDB:
   RutaDB.lanzarFolderChooser();
   //Un aviso para saber si todo salió bien: (opcional)
   System.out.println(&quot;¡Ruta seleccionada correctamente!&quot;);
   
   //Muestra si se escribió bien la ruta en el archivo de texto:
   System.out.println(&quot;Dirección: &quot; + RutaDB.leerRuta());
  }
  catch (IOException e) {
   //Esto se ejecuta si hay algún error al tratar de guardar o leer la ruta en el archivo de texto.
   e.printStackTrace();
  }
 }
 
 /**
  * Indica si hay una base de datos en la ruta default (la carpeta raíz).
  * @return  True si hay una DB por default, False si no hay una DB por default.
  */
 public static boolean hayDBDefault(){
  //¿Hay base de datos en la ruta default (carpeta raíz)?
  boolean hayDB = false;
  
  if(RutaDB.obtenerDBDefault().exists()){
   //Si el archivo de base de datos por default existe, sí:
   hayDB = true;
  }
  else{
   //De lo contrario, no:
   hayDB = false;
  }
  
  return hayDB;
 }
 
 /**
  * Indica si hay una base de datos en la ruta especificada por el usuario.
  * @return  True si hay una DB elegida por el usuario, False si no hay una DB elegida por el usuario.
  */
 public static boolean hayDB(){
  //¿Hay base de datos en una ruta elegida por el usuario?
  boolean hayDB = false;
  
  if(RutaDB.obtenerArchivoRutaDB().exists()){
   //Si el archivo de ruta de base de datos existe, sí:
   hayDB = true;
  }
  else{
   //De lo contrario, no:
   hayDB = false;
  }
  
  return hayDB;
 }
 
 /**
  * Evalúa a qué base de datos se debe conectar ya sea la elegida por el usuario o la default y la devuelve.
  * @return La conexión a la base de datos elegida.
  */
 public static Connection obtenerConexión(){
  //Representa la conexión a la base de datos:
  Connection conn = null;
  
  //Si hay una ruta de base de datos elegida por el usuario:
  if(hayDB()){
   try {
    //Conectamos a la dirección escrita en el archivo de ruta de base de datos:
    conn = conectarA(RutaDB.leerRuta());
    //Pone en la consola la dirección a la cual nos conectamos:
    System.out.println(&quot;Conectado a: &quot; + RutaDB.leerRuta());
   }
   catch (IOException e) {
    //Si hay algún error, debemos conectarnos a la ruta por default, y dar aviso de esto:
    System.err.println(&quot;Error al tratar de leer el archivo de ruta de DB: &quot; + e.toString());
    //Hacemos la conexión a la ruta por default (en la carpeta raíz):
    conn = conectarA(RutaDB.obtenerDBDefault().toString());
    //Damos aviso de lo que hicimos:
    System.err.println(&quot;Se conectó a la ruta por default: &quot; + RutaDB.obtenerDBDefault().toString());
   }
  }
  //De lo contrario, se conecta a la DB por default:
  else{
   conn = conectarA(RutaDB.obtenerDBDefault().toString());
   }
  
  //Para asegurarnos de salir del sistema si la conexión falla de alguna forma: (opcional)
  if(conn == null){
   //Los mensajes al usuario debería ponerse en un JOptionPane.showMessageDialogo, se los dejo de tarea...
   System.err.println(&quot;Error, la conexión es nula, se cerrará la aplicación: &quot;);
   //Salimos con esta instrucción
   System.exit(0);
  }
  
  //Devolvemos la conexión:
  return conn;
 }
 
 /**
  * Conecta a una base de datos en la ruta pasada como argumento.
  * Si el archivo señalado en la ruta no existe, se crea.
  * @param ruta - La ruta de la DB a conectar.
  * @return La conexión a la ruta.
  */
 private static Connection conectarA(String ruta){
  try {
   //Aquí cargamos el driver de SQLITE.
   Class.forName(&quot;org.sqlite.JDBC&quot;);
  }
  catch (ClassNotFoundException e) {
   //Esto se ejecuta si hay un error con el driver de la base de datos.
   e.printStackTrace();
  }
  
  //Declaramos la conexión:
  Connection conn = null;
  try {
   //Aquí se obtiene la conexión:
   conn = DriverManager.getConnection(&quot;jdbc:sqlite:&quot; + ruta);
   //Un mensaje en la consola para saber si se realizó la conexión y donde está el archivo:
   System.out.println(&quot;Conexión realizada correctamente - Ruta de base de datos: &quot; + ruta);
  }
  catch (SQLException e) {
   //Esto se ejecuta si hay un error en la base de datos:
   e.printStackTrace();
  }
  
  //Devolvemos la conexión:
  return conn;
 }
 
 /**
  * Devuelve la dirección de la base de datos usada
  * por la aplicación.
  * @return Dirección de la base de datos.
  */
 public static String obtenerDirección(){
  String ruta = &quot;&quot;;
  
  //Si hay una ruta de base de datos elegida por el usuario:
  if(hayDB()){
   try {
    //Le damos a &#39;ruta&#39; lo que hay en el archivo de la ruta de base de datos: 
    ruta = RutaDB.leerRuta();
   }
   catch (IOException e) {
    //Si se produce una excepción al leer la ruta, le asignamos un mensaje de error:
    ruta = &quot;Imposible leer la ruta de la base de datos: &quot; + e.toString();
   }
  }
  //De lo contrario, se conecta a la base de datos por default:
  else{
   //Asignamos a ruta la dirección de la base de datos por default:
   ruta = RutaDB.obtenerDBDefault().toString();
  }
  
  //Si la ruta está vacía (que se le asigne a ruta le valor: &quot;&quot;):
  if(ruta.isEmpty()){
   //Asignamos a &#39;ruta&#39; un mensaje de error:
   ruta = &quot;Error: Ruta vacía&quot;;
  }
  
  //Devolvemos la ruta:
  return ruta;
 }
 
 public static void main(String[] args) {
  //La siguiente línea se debe poner en la primera ejecución de tu aplicación, o en un instalador, de ti depende:
  BaseDeDatos.ponerRutaDB();
  
  //Asignamos a &#39;conn&#39; la conexión de la base de datos
  Connection conn = BaseDeDatos.obtenerConexión();
  
  /*
   * Aquí se supone que hacemos lo que necesitamos en la base de datos
   * ya sea una consulta, creación de una tabla, actualización de la
   * misma, etc.
   */
  
  try {
   //Y para terminar cerramos la conexión:
   conn.close();
  }
  catch (SQLException e) {
   //Esto se ejecuta si hay algún problema al realizar la conexión.
   e.printStackTrace();
  }
 }
}

]]&gt;&lt;/script&gt;


&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Si
el código fue ejecutado de la manera correcta, verán 5 mensajes en la consola&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;, estos son opcionales, pero también muy importantes para saber
que todo se hizo de la manera correcta, al estar seguros de que todo funciona
bien, pueden quitarlos si gustan, así que ahora, tenemos ya el código necesario
para conectarnos a una base de datos, ya sea que el usuario seleccione la
ubicación o se seleccione por default, nos costó un poco más de trabajo, pero
ahora todo lo que hacemos para conectar a nuestra base de datos es llamar al
método BaseDeDatos.obtenerConexión y listo, podemos hacer una consulta,
actualización o cualquier otra cosa que nos permita SQLITE.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;


&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En la próxima entrada,
les mostraré algo un poco más interesante: Cómo hacer consultas, eliminar
tablas, obtener todos los datos de alguna, y algunas otras cosas útiles, pero
por ahora, ya me cansé de teclear, así que es todo por hoy, no olviden dejar
sus peticiones, dudas, comentarios o criticas en la parte de abajo, ahh y votar
en la sección “Mi opinión”, también pueden suscribirse en la parte superior
derecha, saludos :D.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/como-instalar-sqlite-en-eclipse-ide.html&quot; target=&quot;_blank&quot;&gt;Como instalar SQLITE en Eclipse IDE&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/2973152028610526675/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/10/utilizando-sqlite-en-java.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/2973152028610526675'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/2973152028610526675'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/10/utilizando-sqlite-en-java.html' title='Utilizando SQLITE en Java'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhULRnYKzdeMlEYYRPf5PNazWgj67Yo55jIwnE9Uj4t6X9eLDbXbyjd92GYMOpHKfdPWb_RgajF7CLXCxDSI5uvoB4bilkcNKoFiM6Wvijb6_UID1ydQ4DKLraaQ1j7rsnd4GQtnB0-dZU2/s72-c/SQLITE+Logo.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-3820250956299556594</id><published>2012-10-08T15:21:00.001-07:00</published><updated>2013-06-28T07:37:05.808-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Archivo de texto en java"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse ide"/><category scheme="http://www.blogger.com/atom/ns#" term="Entradas y Salidas"/><category scheme="http://www.blogger.com/atom/ns#" term="I/O"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Leer archivo de texto"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><title type='text'>Leer un archivo de texto en Java</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;



&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4JK4P6ppno93KpGKKe6v5N0iDkADrA_Hb8Oo2FTBNIkKEXqOqXcgm_8Sd_YvQz-NiGDPxLWcn9Xg47YAsi56YKSi3UcPPbkVkbjQRWZrkuZ0dU3n3d_6i4FTEBoM_pxs3pHN6lQl1kzYI/s1600/nota.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s1600/JavaBlack.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;133&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s200/JavaBlack.jpg&quot; width=&quot;200&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4JK4P6ppno93KpGKKe6v5N0iDkADrA_Hb8Oo2FTBNIkKEXqOqXcgm_8Sd_YvQz-NiGDPxLWcn9Xg47YAsi56YKSi3UcPPbkVkbjQRWZrkuZ0dU3n3d_6i4FTEBoM_pxs3pHN6lQl1kzYI/s200/nota.png&quot; width=&quot;200&quot; /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;Hola y
buen día a todos mis lectores, al revisar mis entradas hoy, me di cuenta de
algo, tengo una que se trata sobre &lt;/span&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/escribir-un-archivo-de-texto-en-java.html&quot; style=&quot;font-size: 11pt;&quot; target=&quot;_blank&quot;&gt;cómo escribir archivos de texto en Java&lt;/a&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;,
pero no tengo una sobre como leerlos, quizá para algunos esto sea muy fácil de
hacer, pero puede que a otros se les dificulte un poco, así que bueno, aquí les
diré como:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;ES&quot;&gt;“Directo al grano”&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Esto es para quienes simplemente quieren saber cómo
hacerlo sin más explicación, yo no recomendaría simplemente copiar el código y “a
lo que sigue”, siempre es bueno saber el porqué usamos tal clase o ponemos las
instrucciones de cierta forma, ya saben, para el futuro, de todos modos, aquí les va el código:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public final class LectorTexto {
 
 /**
  * Devuelve el texto del archivo en la ruta pasada como argumento, ejemplo:
  * &quot;C:\Documentos\nota.txt&quot;
  * @param ruta - La ruta del archivo.
  * @return - El texto dentro del archivo.
  */
 public static String leerTexto(String ruta){
  //Representa el texto dentro del archivo, por ahora, vacío.
  String texto = &quot;&quot;;
  
  //El archivo de donde sacamos el texto.
  File archivo = new File(ruta);
  
  try {
   //Le ponemos al lector de archivo &#39;fr&#39; el atributo &#39;archivo&#39; en su constructor para leerlo después.
   FileReader fr = new FileReader(archivo);
   
   //Esta parte ayuda a la eficiencia de la lectura.
   BufferedReader buffer = new BufferedReader(fr);
   
   //Nos indica cuando es el fin del archivo.
   boolean fin = false;
   
   //Búfer para guardar las líneas de texto.
   StringBuffer sbf = new StringBuffer();
   
   //Salto de línea para que el texto salga en líneas separadas (opcional)
   String nl = System.getProperty(&quot;line.separator&quot;);
   
   //Mientras no sea el fin del archivo:
   while(fin == false){
    
    //Leemos una línea del archivo.
    String linea = buffer.readLine();
    
    //Si la línea no está vacía...
    if(linea != null){
     //Agregamos al búfer la línea y el salto de línea &#39;nl&#39; (opcional)
     sbf.append(linea + nl);
    }
    else{
     //De lo contrario damos fin al ciclo while.
     fin = true;
    }
   }
   
   //Asignamos a &#39;texto&#39; lo que se agregó al búfer:
   texto = sbf.toString();
   
  } 
  catch (FileNotFoundException e) {
   //Esto se ejecuta si el archivo no fue encontrado.
   e.printStackTrace();
  }
  catch (IOException e) {
   //Esto se ejecuta si hay un error en la lectura del archivo.
   e.printStackTrace();
  }
  
  //Devolvemos el texto.
  return texto;
 } 

 //Una pequeña prueba:
 public static void main(String[] args) {
  //Asignamos a &#39;nota&#39; lo que hay en el archivo:
  String nota = LectorTexto.leerTexto(&quot;C:/nota.txt&quot;);
  
  //Mostramos el contenido del archivo en la consola:
  System.out.println(nota);
 }
}

]]&gt;&lt;/script&gt;


&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;span style=&quot;font-size: 10.0pt; mso-ansi-language: ES-MX; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;Obviamente para la
prueba hay que escribir y guardar algo de texto en un archivo llamado &lt;i&gt;nota.txt&lt;/i&gt; en &lt;i&gt;C:/&lt;/i&gt; de lo contrario nos lanzará una excepción del tipo &lt;i&gt;FileNotFoundException&lt;/i&gt; en el bloque &lt;i&gt;try/catch &lt;/i&gt;(el primer catch en el bloque
de arriba). La salida en consola que obtuve al correr el código fue la
siguiente:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 10.0pt; line-height: 115%;&quot;&gt;ESTÁS&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b style=&quot;font-size: 11pt;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 10.0pt; line-height: 115%;&quot;&gt;EN&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 10.0pt; line-height: 115%;&quot;&gt;EL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 10.0pt; line-height: 115%;&quot;&gt;BLOG&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 10.0pt; line-height: 115%;&quot;&gt;DE&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 10.0pt; line-height: 115%;&quot;&gt;BARO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span lang=&quot;ES&quot;&gt;
&lt;/span&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt;&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 10.0pt; line-height: 115%;&quot;&gt;:D&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span lang=&quot;ES&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 10.0pt; line-height: 115%;&quot;&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10.0pt; line-height: 115%;&quot;&gt;¿Quiere
saber más?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10.0pt; line-height: 115%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 10.0pt; line-height: 115%;&quot;&gt;Para quienes les interese, en esta sección veremos paso a paso
el código de arriba y le daremos algunas mejoras (se aceptan sugerencias abajo)
así que aquí va la revisión y explicación del código.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 10.0pt; line-height: 115%;&quot;&gt;Primero que nada vemos varias
líneas que inician con la palabra reservada &lt;i&gt;import&lt;/i&gt;,
para quienes no saben, la palabra reservada import es para utilizar la clase o
paquete escrito después del mismo, en este caso: &lt;i&gt;java.io.BufferedReader&lt;/i&gt;, &lt;i&gt;java.io.File&lt;/i&gt;,
&lt;i&gt;java.io.FileNotFoundException&lt;/i&gt;, etc.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Después vemos el nombre de la clase, que es &lt;i&gt;LectorTexto&lt;/i&gt;, claro que podemos ponerle el nombre que queramos, no
importa, después vemos el comentario para el método &lt;i&gt;leerTexto&lt;/i&gt;, ahí normalmente ponemos una breve descripción de lo que
hace el método, el o los parámetros y lo que regresa (si no es &lt;i&gt;void&lt;/i&gt;).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;ES&quot;&gt;El método leerTexto&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para empezar el método &lt;i&gt;leerTexto&lt;/i&gt;,
pide como argumento un String, en el cual pondremos la ruta del archivo que
queremos leer, y lo que devuelve (como lo dice el comentario del método) es el
texto dentro del archivo. Ahora, para convertir el texto pasado como argumento
en un archivo que se pueda leer, lo ponemos en el constructor de &lt;i&gt;File&lt;/i&gt; de esta forma: &lt;b&gt;File archivo = new File(ruta);&lt;/b&gt; Y listo, la ruta que fue pasada como
argumento ahora es un archivo que apunta a nuestro texto. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Pero tener un archivo apuntando a nuestra nota no es suficiente, se
necesita de alguien que lo lea, en este caso utilizamos la clase &lt;i&gt;FileReader&lt;/i&gt; la cual nos permite leer el
archivo que pasemos como argumento en su constructor: &lt;b&gt;FileReader fr = new FileReader(archivo);&lt;/b&gt; Y con esto tenemos el
lector, el cual por desgracia solo nos devuelve enteros al leer el archivo, que
se podrían convertir en texto, pero “¿No podría hacerlo otro?” En este caso,
sí, utilizamos &lt;i&gt;BufferedReader&lt;/i&gt; para
hacer más eficiente la lectura y que se haga en líneas, lo cual nos facilita
mucho las cosas, para poner un búfer a nuestro lector de archivo (&lt;i&gt;FileReader&lt;/i&gt;) hacemos esto: &lt;b&gt;BufferedReader bf = new BufferedReader(fr);&lt;/b&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¡Perfecto! Ahora tenemos el búfer que nos ayudará mucho en la lectura del
archivo, pero no es suficiente, ¿Qué pasa si el archivo contiene varias líneas?
Para eso tenemos el ciclo &lt;i&gt;while&lt;/i&gt; en
nuestro código y escribimos las sentencias necesarias para hacer que el búfer
haga la lectura de todas las líneas en el archivo (ver el código de arriba) y
opcionalmente, devolverlas en líneas separadas gracias a la propiedad &lt;i&gt;line.separator&lt;/i&gt;, utilizamos también la
clase &lt;i&gt;StringBuffer&lt;/i&gt; para ir agregándole
el texto por cada línea que sea leída por el búfer (y que no sea &lt;i&gt;null&lt;/i&gt;). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Al finalizar el ciclo &lt;i&gt;while&lt;/i&gt;
asignamos a nuestro atributo &lt;i&gt;texto&lt;/i&gt; lo
que hay dentro del StringBuffer, así: &lt;b&gt;texto
= sbf.toString();&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;ES&quot;&gt;Mejorando el lector de
archivo&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Nuestra pequeña y simple clase lee los archivos de texto de manera muy
eficiente, pero, lo que no es tan eficiente, es la forma en que señalamos que
archivo queremos leer, en especial con rutas muy largas, pero afortunadamente
hay una solución, ¡Un selector de archivo! Que permitirá al usuario elegir el
archivo que se quiere leer de una forma mucho más cómoda y fácil.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;ES&quot;&gt;Agregando un selector de
archivo&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Agregar un selector de archivo a nuestro lector de texto será algo muy
fácil, crearemos un nuevo método llamado &lt;i&gt;lanzarSelector()&lt;/i&gt;
que mostrará el selector de archivo que va a devolver la ruta del archivo que
se ha seleccionado para después leer el texto dentro de él y mostrarlo ya sea
en la consola o en una interfaz con JTextField, JLabel o quizá un JTextArea (ese
proyecto de la interfaz te lo dejo a ti).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;A continuación se muestra el nuevo código ya con el selector de archivo:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 11pt; text-align: justify;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JFileChooser;

public final class LectorTexto {
 
 /**
  * Devuelve el texto de la nota en la ruta pasada como argumento, ejemplo:
  * &quot;C:\Documentos\nota.txt&quot;
  * @param ruta - La ruta del archivo.
  * @return - El texto dentro de la nota.
  */
 public static String leerTexto(String ruta){
  //Representa el texto dentro de la nota, por ahora, vacío.
  String texto = &quot;&quot;;
  
  //El archivo de donde sacamos el texto.
  File archivo = new File(ruta);
  
  try {
   //Le ponemos al lector de archivo &#39;fr&#39; el atributo &#39;archivo&#39; en su constructor para leerlo después.
   FileReader fr = new FileReader(archivo);
   
   //Esta parte ayuda a la eficiencia de la lectura.
   BufferedReader buffer = new BufferedReader(fr);
   
   //Nos indica cuando es el fin del archivo.
   boolean fin = false;
   
   //Búfer para guardar las líneas de texto.
   StringBuffer sbf = new StringBuffer();
   
   //Salto de línea para que el texto salga en líneas separadas (opcional)
   String nl = System.getProperty(&quot;line.separator&quot;);
   
   //Mientras no sea el fin del archivo:
   while(fin == false){
    
    //Leemos una línea del archivo.
    String linea = buffer.readLine();
    
    //Si la línea no está vacía...
    if(linea != null){
     //Agregamos al búfer la línea y el salto de línea &#39;nl&#39; (opcional)
     sbf.append(linea + nl);
    }
    else{
     //De lo contrario damos fin al ciclo while.
     fin = true;
    }
   }
   
   //Asignamos a &#39;texto&#39; lo que se agregó al búfer:
   texto = sbf.toString();
   
  } 
  catch (FileNotFoundException e) {
   //Esto se ejecuta si el archivo no fue encontrado.
   e.printStackTrace();
  }
  catch (IOException e) {
   //Esto se ejecuta hay un error en la lectura del archivo.
   e.printStackTrace();
  }
  
  //Devolvemos el texto.
  return texto;
 }
 
 /**
  * Lanza JFileChooser para manejar la selección de la ruta del archivo que vamos a leer.
  */
 public static void lanzarSelector(){
  //Ruta del archivo a leer.
  String ruta = &quot;&quot;;
  
  //Carpeta de inicio (opcional).
  File carpetaInicio = new File(System.getProperty(&quot;user.home&quot;));

  //Selector de archivo (carpetaIncio opcional).
  JFileChooser jfc = new JFileChooser(carpetaInicio.toString());
  
  //Asignamos al atributo &#39;resultado&#39; el valor de la selección del usuario:
  int resultado = jfc.showOpenDialog(null);
  
  //Le damos un título al dialogo (opcional)
  jfc.setDialogTitle(&quot;Seleccione un archivo para leer: &quot;);
  
  //Si se ha seleccionado un archivo:
  if(resultado == JFileChooser.APPROVE_OPTION){
   
   //Asignamos a &#39;ruta&#39; la dirección de archivo seleccionado:
   ruta = jfc.getSelectedFile().toString();
   
   //Si la ruta no es nula:
   if(ruta != null){
    //Leemos el archivo y lo mostramos en consola.
    System.out.println(leerTexto(ruta));
   }
   else{
    //De lo contrario, no leemos el archivo:
    System.err.println(&quot;Selección nula&quot;);
   }
   
  }
 }
 
 //Una pequeña prueba:
 public static void main(String[] args) {
  //Llamamos al método lanzarSelector y él se hace cargo desde ahí:
  LectorTexto.lanzarSelector();
 }
}

]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;div style=&quot;font-size: 11pt;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Esto
facilita muchísimo las cosas, ahora el método &lt;i&gt;lanzarSelector&lt;/i&gt; lo hace todo, lo mejor es que podemos usar este
código para muchas cosas, tanto el lector de texto, como el selector de
archivo. Otra cosa muy importante, es que, el lector de archivo no lee
solamente archivos con extensión &lt;i&gt;*.txt&lt;/i&gt;,
puede leer cualquier archivo y mostrarlo en forma de texto, pruébalo.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 11pt;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Y bien, esto es todo por este artículo, espero les
haya gustado, y ya saben, suscríbanse en la parte superior derecha con su email
si les gustan mis entradas, dudas, peticiones, comentarios o criticas son bien
recibidas en la parte de abajo, saludos a todos :D.&lt;/span&gt;&lt;span style=&quot;font-family: Calibri, sans-serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 11pt;&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 11pt;&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue; font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-size: 11pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/escribir-un-archivo-de-texto-en-java.html&quot; target=&quot;_blank&quot;&gt;Escribir un archivo de texto en Java&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 11pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/entradas-y-salidas-lo-basico.html&quot; target=&quot;_blank&quot;&gt;Entradas y Salidas en Java - Lo básico&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 11pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 11pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/3820250956299556594/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/10/leer-un-archivo-de-texto-en-java.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/3820250956299556594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/3820250956299556594'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/10/leer-un-archivo-de-texto-en-java.html' title='Leer un archivo de texto en Java'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s72-c/JavaBlack.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-7779365752162947780</id><published>2012-10-04T15:33:00.002-07:00</published><updated>2012-10-22T11:57:58.230-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aprender java creando un juego"/><category scheme="http://www.blogger.com/atom/ns#" term="Greenfoot"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java Greenfoot"/><category scheme="http://www.blogger.com/atom/ns#" term="Java magazine"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Juegos"/><category scheme="http://www.blogger.com/atom/ns#" term="Juegos en java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><category scheme="http://www.blogger.com/atom/ns#" term="Video juegos"/><category scheme="http://www.blogger.com/atom/ns#" term="Video juegos Greenfoot"/><title type='text'>Aprender Java creando un juego (Parte 6) - Final</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvSF54ZXD2qpjDa1d-OgD_z-IPXDz8PIobu0CURGQ-41mqO6pxu1h4PwBQ4UnLfBXkAd3lHxyBd3L-DpUgC9dfNYVz_-W13Jik_NcW_cSChOT9BsBBloA2gMftDqbN2A3co09vOjlkux4e/s1600/Greenfoot+logo.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;169&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvSF54ZXD2qpjDa1d-OgD_z-IPXDz8PIobu0CURGQ-41mqO6pxu1h4PwBQ4UnLfBXkAd3lHxyBd3L-DpUgC9dfNYVz_-W13Jik_NcW_cSChOT9BsBBloA2gMftDqbN2A3co09vOjlkux4e/s320/Greenfoot+logo.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;



&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Hola y
buen día a todos mis lectores, les tengo la parte final de este gran proyecto
de la tortuga en el entorno Greenfoot, si se han perdido de todas las demás
partes ya publicadas aquí ¡qué esperan!, visítenlas y entérense de qué se trata
este proyecto:&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-1.html&quot; target=&quot;_blank&quot;&gt;Parte 1&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-2.html&quot; target=&quot;_blank&quot;&gt;Parte 2&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-3.html&quot; target=&quot;_blank&quot;&gt;Parte 3&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-4.html&quot; target=&quot;_blank&quot;&gt;Parte 4&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.mx/2012/10/aprender-java-creando-un-juego-parte-5.html&quot; target=&quot;_blank&quot;&gt;Parte 5&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;El
juego que continuamos creando en previas entradas se acerca más y más a estar
completo, pero algunas partes siguen perdidas. Hoy, te mostraré como terminar
el juego y&lt;/span&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;—lo
más importante—como compartirlo con tus amigos. Si no nos has acompañado en
este proyecto, revisa cada una de sus partes en este blog (links arriba),
&lt;a href=&quot;http://www.greenfoot.org/home&quot; target=&quot;_blank&quot;&gt;descarga Greenfoot&lt;/a&gt; y únete a la diversión.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;ES&quot;&gt;Finalizando el juego&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot;&gt;Actualmente, no
hay forma de ganar este juego. Comes todas las rebanadas de pizza, y nada pasa.
No hay trompeteo, ni un gran anuncio de “¡GANASTE!”. Igualmente, cuando las
serpientes te atrapan, el juego solamente sigue corriendo en silencio.&amp;nbsp;&lt;/span&gt;Queremos arreglar
ambas situaciones. Vamos a decir que cuando logres comer 12 rebanadas de pizza,
ganas. El juego se detiene, y oímos un victorioso trompeteo. De todas formas,
cuando las serpientes te atrapan, pierdes. Obtenemos de igual forma un sonido,
y el juego se detiene.&amp;nbsp;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt;&quot;&gt;El segundo escenario (perder) es fácil de hacer&lt;/span&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;—tenemos
casi todo para eso ya. Así que haremos eso primero, y entonces mirar a la
funcionalidad necesaria para ganar.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Perder (Ser comido por las
serpientes)&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Tenemos
ya un efecto de sonido para cuando la serpiente se come a la tortuga (en el
método &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;eat &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;de la serpiente&lt;/span&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;),
el cual usa el método Greenfoot &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;playSound&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;. La primera cosa que haremos es solo cambiar&lt;/span&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt; el
sonido a un nuevo archivo de sonido (el cual puedes &lt;a href=&quot;https://docs.google.com/open?id=0BysLlaOg7wsWQ3lOdGt6VzI5NkU&quot; target=&quot;_blank&quot;&gt;descargar aquí&lt;/a&gt;) nombrado
trombone.wav.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Entonces
añade una nueva línea: una llamada al método Greenfoot &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;stop&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; para detener el juego en este punto. Juntos, el código se ve así:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Greenfoot.playSound(&quot;trombone.wav&quot;);
Greenfoot.stop();
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Nota
que ambos métodos son métodos estáticos de la clase &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Greenfoot&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;, así que tenemos que escribir el nombre de la clase &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Greenfoot&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; y un punto antes del nombre del método en la llamada
al método.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para descubrir que otros métodos ofrece la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Greenfoot&lt;/span&gt;&lt;/b&gt;, elige &lt;b&gt;Greenfoot Class Documentation&lt;/b&gt; del menú &lt;b&gt;Help&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Otra alternativa es, usar &lt;i&gt;code
completion&lt;/i&gt;. Por ejemplo, después de escribir&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt; Greenfoot.&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; (eso es, después del punto), presiona &lt;b&gt;Ctr-Space&lt;/b&gt; en tu teclado, y verás una lista de todos los métodos que
puedas llamar hasta ese punto, como se muestra a continuación:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1xlp04SBWE2Yjnrb_7ny_VbPUXpy-_WrDGQQIUcyZvnej3-x4v1vaWdyFJc7J_HM_z_HAjrRPvigYhkQ8qMdaQo82JFuiIp9DBJa49XgCq4YwI1kVEGpf4gQWNxt4VWro1_lRYyySSjXG/s1600/Imagen1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;274&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1xlp04SBWE2Yjnrb_7ny_VbPUXpy-_WrDGQQIUcyZvnej3-x4v1vaWdyFJc7J_HM_z_HAjrRPvigYhkQ8qMdaQo82JFuiIp9DBJa49XgCq4YwI1kVEGpf4gQWNxt4VWro1_lRYyySSjXG/s320/Imagen1.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Al empezar a escribir un nombre de un método va a reducir las opciones. Entonces elige
cualquiera de los métodos de la lista. Implementar este fin del juego fue
bastante fácil. Hacer una cosa similar para ganar es un poco más de trabajo.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Ganando (Terminando tu pizza)&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Queremos
que nuestra funcionalidad de ganar (trompeteo y detener el juego) ocurra cuando
hayamos comido toda nuestra pizza (12 rebanadas). Escogiendo este criterio,
tenemos dos problemas. Primero, actualmente tenemos solo 7 rebanadas de pizza
en nuestro juego. Podemos, por supuesto, simplemente poner 12 rebanadas desde
el inicio, pero eso haría el juego demasiado fácil. En su lugar, quiero hacer
que aparezca una nueva rebanada cada vez que una es comida. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Y
segundo, ahora necesitamos contar cuando hemos comido, de manera que sepamos
cuando parar. Nosotros no sabemos aún como hacer eso.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Haremos
estas dos cosas.&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;La pizza que aparece
mágicamente&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Las rebanadas de pizza que se comen en la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Turtle&lt;/span&gt;&lt;/b&gt;—para ser
específico, en el método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;eat&lt;/span&gt;&lt;/b&gt; de la tortuga. Así que ahí es donde comenzamos a trabajar. Para
mantener el código limpio, ponemos las instrucciones para crear una nueva
rebanada de pizza en un método separado y llamar a ese método desde aquí. Así
que ponemos una llamada a &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;placeNewPizza() &lt;/span&gt;&lt;/b&gt;en nuestro método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;eat&lt;/span&gt;&lt;/b&gt;, justo debajo de
la reproducción del sonido:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Greenfoot.playSound(&quot;slurp.wav&quot;);
placeNewPizza();
]]&gt;&lt;/script&gt;


&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;placeNewPizza() &lt;/span&gt;&lt;/b&gt;va a poner una nueva rebanada en el mundo cada
vez que otra rebanada es comida. Este método no existe—vamos a tener que
escribirlo ahora.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;El código completo para este método se muestra a continuación:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
/**
* Look for pizza and eat it if we see some.
*/
public void eat(){
 Actor pizza = getOneIntersectingObject(Pizza.class);

 if(pizza != null) {
  getWorld().removeObject(pizza);
  Greenfoot.playSound(&quot;slurp.wav&quot;);
  placeNewPizza();
 }
}

/**
* Place a new pizza slice at a random location into the world.
*/
public void placeNewPizza(){
 World myWorld = getWorld();
 int x = Greenfoot.getRandomNumber(myWorld.getWidth());
 int y = Greenfoot.getRandomNumber(myWorld.getHeight());
 myWorld.addObject(new Pizza(), x, y);
}
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Veremos que el método &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;eat() &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;llama al método &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;placeNewPizza() &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;y la definición para este nuevo método.&amp;nbsp;&lt;/span&gt;Vamos a analizar esto línea por línea.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para poner una nueva rebanada de pizza al azar
en el mundo, tenemos que lograr tres cosas:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-indent: -18pt;&quot;&gt;Crear un nuevo objeto pizza.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-indent: -18pt;&quot;&gt;Generar coordenadas al azar.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;Poner la pizza en esas coordenadas en el mundo.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;La primera línea en nuestro nuevo método pone:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
World myWorld = getWorld();
]]&gt;&lt;/script&gt;


&lt;/span&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;Hemos visto antes que la llamada a &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;getWorld() &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;nos da una referencia a nuestro objeto mundo actual.&amp;nbsp;&lt;/span&gt;Esta vez, vamos a declarar una variable local
llamada &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;myWorld &lt;/span&gt;&lt;/b&gt;(es de tipo &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;World&lt;/span&gt;&lt;/b&gt;) y almacena el objeto mundo en sí. Esto, por su cuenta, no logra
mucho todavía, a parte del hecho de que ahora podemos usar la variable &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;myWorld &lt;/span&gt;&lt;/b&gt;para “hablar” con
nuestro mundo.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;En las siguientes dos líneas, vamos a generar las coordenadas al azar y
almacenarlas en dos variables locales de tipo enteras (&lt;i&gt;int&lt;/i&gt;):&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
int x = Greenfoot.getRandomNumber(myWorld.getWidth());
int y = Greenfoot.getRandomNumber(myWorld.getHeight());
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Hemos visto ya antes llamadas a los métodos &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;getRandomNumber&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;getWidth&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;, y &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;getHeight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;.&amp;nbsp;&lt;/span&gt;Aquí, vamos a generar un número aleatorio entre 0 y el ancho del mundo y almacenarlo en la variable &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;x&lt;/span&gt;&lt;/b&gt;. Entonces haremos
lo mismo para &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;y&lt;/span&gt;&lt;/b&gt; usando el alto del mundo como límite. Esto nos da coordenadas &lt;i&gt;x&lt;/i&gt; y &lt;i&gt;y&lt;/i&gt;
al azar que concuerdan con el tamaño exacto del mundo.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;La última línea hace la magia:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
myWorld.addObject(new Pizza(), x, y);
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Aquí, ponemos el nuevo objeto pizza en el mundo.&amp;nbsp;&lt;/span&gt;Para hacer esto, estamos usando el método del
mundo &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;addObject&lt;/span&gt;&lt;/b&gt;. Este método espera tres parámetros: el objeto a ser ubicado, la
coordenada &lt;i&gt;x&lt;/i&gt;, y la coordenada &lt;i&gt;y&lt;/i&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Podemos&amp;nbsp;
escribir &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;new Pizza() &lt;/span&gt;&lt;/b&gt;para crear un nuevo objeto de tipo &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Pizza&lt;/span&gt;&lt;/b&gt;, y podemos usar
éste en el lugar del objeto para ser ubicado en el mundo. Entonces podemos usar
nuestras variables &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;x&lt;/span&gt;&lt;/b&gt; y &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;y&lt;/span&gt;&lt;/b&gt; (las cuales acabamos de llenar con nuestros valores aleatorios)
en el lugar de las coordenadas.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Lee el código de arriba completo (el que
incluye el método &lt;i&gt;eat&lt;/i&gt; y &lt;i&gt;placeNewPizza&lt;/i&gt;) nuevamente y asegúrate de
entenderlo. Entones inténtalo por ti mismo.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Contando
la pizza&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La funcionalidad hasta ahora nos da un
suministro sin fin de rebanadas de pizza. La siguiente tarea que se debe hacer
es contar cuando hemos comido. Hacemos esto creando un &lt;i&gt;campo&lt;/i&gt; (también conocido como una variable &lt;i&gt;instancia&lt;/i&gt;) nombrada &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;slices &lt;/span&gt;&lt;/b&gt;(rebanadas) que se usarán para contar. (Aún
estamos trabajando en la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Turtle&lt;/span&gt;&lt;/b&gt;.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Así es como se ve:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
public class Turtle extends Actor {
 private int slices = 0;
 ...
}
]]&gt;&lt;/script&gt;


&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;La declaración de campo consiste de la palabra clave &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;private&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;, seguida por el tipo y el nombre para nuestra variable, y un valor
opcional de inicialización.&amp;nbsp;&lt;/span&gt;El tipo y nombre (&lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;int slices&lt;/span&gt;&lt;/b&gt;) es el mismo que
hemos visto para una variable local. La inicialización (&lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;= 0&lt;/span&gt;&lt;/b&gt;) asigna cero a la
variable para empezar. Poner esta línea es importante. Las declaraciones de
campo deben hacerse fuera de las definiciones de métodos, así que escribimos
esta línea inmediatamente después de la cabecera de clase (antes de nuestro
método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act&lt;/span&gt;&lt;/b&gt;).&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El campo &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;slices&lt;/span&gt;&lt;/b&gt; puede almacenar enteros (eso es, números
enteros). Actualmente almacena cero. Podemos ahora usar este campo para contar
nuestras rebanadas de pizza. Cada vez que comemos algo de pizza, incrementamos
este campo en 1. Cuando hayamos llegado a 12, reproducimos el trompeteo (el
archivo de sonido fanfare.wav, el cual puedes &lt;a href=&quot;https://docs.google.com/open?id=0BysLlaOg7wsWRTJ0bWVVeXpnc0U&quot; target=&quot;_blank&quot;&gt;descargar aquí&lt;/a&gt;) y detenemos el
juego.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;A continuación se muestra la implementación completa:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
/**
* Look for pizza and eat it if we see some.
*/
public void eat() {
 Actor pizza = getOneIntersectingObject(Pizza.class);
 
 if(pizza != null) {
  getWorld().removeObject(pizza);
  slices ++;

  if(slices == 12) {
   Greenfoot.playSound(&quot;fanfare.wav&quot;);
   Greenfoot.stop();
  }
  else {
   Greenfoot.playSound(&quot;slurp.wav&quot;);
   placeNewPizza();
  }
 }
}
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;Vamos brevemente a examinar los aspectos interesantes.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Tenemos adjunta la siguiente línea:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
slices ++;
]]&gt;&lt;/script&gt;


&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;El operador &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;++&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;, escrito después de una variable &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;, incrementa (eso es, contar hacia arriba) esta variable en 1.&amp;nbsp;&lt;/span&gt;Así que podemos ver que estamos contando hacia
arriba cada vez después de eliminar una rebanada de pizza del mundo.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;A continuación, tenemos las siguientes líneas (con
algunas instrucciones en el lugar de los tres puntos):&lt;o:p&gt;&lt;/o:p&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
if(slices == 12) {
 ...
}
else {
 ...
}
]]&gt;&lt;/script&gt;


&lt;span style=&quot;font-size: 11pt;&quot;&gt;Este código revisa si la variable &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;slices &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;es ahora igual a 12 y, si lo es, ejecuta las instrucciones entre el
primer par de llaves.&amp;nbsp;&lt;/span&gt;De otra forma (si la variable no es igual a 12),
las instrucciones después de la palabra clave &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;else &lt;/span&gt;&lt;/b&gt;son ejecutadas. Nota que necesitamos usar un símbolo
de igual doble (&lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;==&lt;/span&gt;&lt;/b&gt;) para revisar si hay igualdad.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Lee el código completo de arriba con cuidado (donde
está el método &lt;i&gt;eat&lt;/i&gt; completo). Verás
que este código es usado para reproducir nuestro sonido de sorber y pone una
nueva rebanada de pizza mientras no se hayan comido 12 rebanadas aún. Entonces
reproduce el sonido de las trompetas y termina el juego cuando hayamos comido
12 rebanadas. Intenta el código en tu propia versión del juego.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Compartiendo
tu juego&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora que nuestro juego está “completo” en
algún sentido—por
su puesto, ningún juego está realmente terminado nunca—sería grandioso si pudiéramos
hacer que todos nuestros amigos lo probaran. Afortunadamente, podemos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Greenfoot tiene una función llamada “share” (compartir) que
nos permite subir nuestro programa al sitio web de Greenfoot, donde otros
usuarios pueden jugarlo y darte algo de retroalimentación. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Tú puedes ver todos los &lt;i&gt;scenarios&lt;/i&gt;
que otros usuarios Greenfoot han creado dirigiéndote al sitio Greenfoot y
mirando alrededor.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para subir tu propio juego, da click en el botón &lt;b&gt;Share&lt;/b&gt; en la parte superior derecha de la ventana principal de
Greenfoot. Al dar click aparece una caja de dialogo que nos permite especificar
algunos detalles para subirlo como se muestra en la siguiente imagen:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6Zwbs0gZOAJ9hDxFltTwjuLEF8ZKJrvEtrdhmpiVfu-WHfVH8J_aBBec5NqoON3zzELLZRmDbf14TluArtmPnoVGd9PMZcDR3gX8GPYfxakEexEB7GKIr-hmLRIF0o3XnxykwPEIHf8Yd/s1600/Imagen2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6Zwbs0gZOAJ9hDxFltTwjuLEF8ZKJrvEtrdhmpiVfu-WHfVH8J_aBBec5NqoON3zzELLZRmDbf14TluArtmPnoVGd9PMZcDR3gX8GPYfxakEexEB7GKIr-hmLRIF0o3XnxykwPEIHf8Yd/s320/Imagen2.jpg&quot; width=&quot;286&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: left;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para poder subir tu juego, debes tener una
cuenta en el sitio Greenfoot. (Si no la tienes, da click en el link &lt;b&gt;Create account&lt;/b&gt;.) Puedes explorar y
jugar juegos de otras personas sin registrarte, pero para subir tu propio
juego, necesitas una cuenta. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Una vez que tengas una cuenta, esta caja de
dialogo te deja añadir un título, una descripción, un ícono, y algunas
etiquetas, y entonces puedes subir tu juego. Cuando subes un juego, puedes
elegir si quieres subir el código fuente también. Si lo haces, otros pueden
mirar el código fuente y posiblemente aprender de él o modificarlo por ellos
mismos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Tu proyecto tendrá una URL única en el sitio
web Greenfoot. ¡Envía ésta a tus amigos para mostrarles las cosas ‘chidas’ (&lt;i&gt;cool&lt;/i&gt;) que has hecho!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Pues bien, se terminaron las entradas sobre el proyecto
de la tortuga en Greenfoot, pero quizá vengan algunos otros diferentes, espero
que hayan disfrutado de estas entradas tanto como yo disfrute subiéndolas, ya
saben, pueden suscribirse en la parte superior derecha con solo poner su email
y les llegarán las noticias de mi blog a su bandeja de entrada, los
comentarios, peticiones, dudas o criticas van abajo, saludos :D.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Traducción: El Blog De Baro.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Escrito por: Michael Kölling.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Fuente: &lt;a href=&quot;http://www.oracle.com/technetwork/java/javamagazine/index.html&quot; target=&quot;_blank&quot;&gt;Java Magazine&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-5.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 5)&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-4.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 4)&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/7779365752162947780/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-6.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/7779365752162947780'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/7779365752162947780'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-6.html' title='Aprender Java creando un juego (Parte 6) - Final'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvSF54ZXD2qpjDa1d-OgD_z-IPXDz8PIobu0CURGQ-41mqO6pxu1h4PwBQ4UnLfBXkAd3lHxyBd3L-DpUgC9dfNYVz_-W13Jik_NcW_cSChOT9BsBBloA2gMftDqbN2A3co09vOjlkux4e/s72-c/Greenfoot+logo.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-5169286066613113742</id><published>2012-10-02T11:11:00.000-07:00</published><updated>2012-10-22T13:10:42.975-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aprender java creando un juego"/><category scheme="http://www.blogger.com/atom/ns#" term="Greenfoot"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java magazine"/><category scheme="http://www.blogger.com/atom/ns#" term="Juegos"/><category scheme="http://www.blogger.com/atom/ns#" term="Juegos en java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><category scheme="http://www.blogger.com/atom/ns#" term="Video juegos"/><title type='text'>Aprender Java creando un juego (Parte 5)</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;



&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hola y buen día
para todos mis lectores, les tengo aquí la quinta parte del proyecto de la
tortuga en el entorno Greenfoot, estamos muy cerca de concluirlo, así que ¡A
programar! (obviamente antes de programar hay que leer lo que sigue)…&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Cuando dejamos nuestro proyecto Java en la entrada
previa, obtuvimos un pequeño y divertido juego en el cual una tortuga estaba
comiendo pizza mientras trataba que las serpientes no se la comieran como se
muestra en la siguiente imagen:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRDXlEXwHrWI9Rgm-g_f_AHMVxHFTUx5QvyTX8o-BC6lZrUGkTedpRxWBQmodwBamuvp1TU1Op9O5Di_Z84qkyfXuf0XJUe8RLMVbQLDLs4nQy8qu9zEdC7oMoSMkC8Qg6krLRRFkDKW-n/s1600/Imagen1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;201&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRDXlEXwHrWI9Rgm-g_f_AHMVxHFTUx5QvyTX8o-BC6lZrUGkTedpRxWBQmodwBamuvp1TU1Op9O5Di_Z84qkyfXuf0XJUe8RLMVbQLDLs4nQy8qu9zEdC7oMoSMkC8Qg6krLRRFkDKW-n/s320/Imagen1.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Si no
has estado escribiendo los códigos de este proyecto hasta ahora, &lt;a href=&quot;http://www.greenfoot.org/download/&quot; target=&quot;_blank&quot;&gt;descarga e instala Greenfoot&lt;/a&gt;, y entonces visita las otras entradas de este blog (&lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-1.html&quot; target=&quot;_blank&quot;&gt;Parte 1&lt;/a&gt;,
&lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-2.html&quot; target=&quot;_blank&quot;&gt;Parte 2&lt;/a&gt;, &lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-3.html&quot; target=&quot;_blank&quot;&gt;Parte 3&lt;/a&gt;, &lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-4.html&quot; target=&quot;_blank&quot;&gt;Parte 4&lt;/a&gt;) y únete en esta sesión.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Mejorando las
serpientes&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;En nuestra versión actual, el movimiento de las
serpientes está controlado por estas 2 líneas de código:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
move(4);
turn(Greenfoot.getRandomNumber(40)-20);
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11.0pt; mso-ansi-language: ES; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;El efecto es que las serpientes siempre se
mueven hacia adelante, y giran en un ángulo aleatorio (20 grados a la derecha o
izquierda) a cada paso.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;Esto trabaja bastante
bien cuando una serpiente está en medio de la pantalla. De todas formas, cuando
esta golpea la orilla de nuestro mundo, queda atorada ahí por un rato antes de
lograr dar la vuelta y cazar a la tortuga de nuevo. Podemos mejorar esto
haciendo que las serpientes siempre giren cuando lleguen a la orilla del mundo.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;(Esto además me da una oportunidad para
enseñarte dos cosas: Podemos usar una sentencia &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;if &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;para tener un poco más de practica con esto, y tendremos una oportunidad
para llamar métodos desde el objeto &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;world&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Girando a la orilla del mundo&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Si queremos hacer que la serpiente gire a la
orilla del mundo, primero debemos reconocer cuando estamos en la orilla.
Podemos hacer esto definiendo un nuevo método llamado&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt; atWorldEdge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; que se encargue de revisar esto. Este método regresa un resultado &lt;i&gt;Boolean&lt;/i&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;true&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; si estamos cerca de la orilla, y &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;false&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; si no es así. El formato se ve así:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
public boolean atWorldEdge()
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Entre este método, queremos escribir algo de
código que exprese algo como esto:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Si estamos cerca del borde izquierdo o derecho, &lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;devuelve &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;true&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Si estamos cerca del borde superior o inferior, devuelve &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;true&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;De otra forma, &lt;/span&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;devuelve &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;false&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para la primera prueba
mencionada aquí, necesitamos saber nuestra coordenada &lt;i&gt;x&lt;/i&gt;. Para la segunda prueba, necesitamos nuestra coordenada &lt;i&gt;y&lt;/i&gt;. Podemos obtener ambas usando los
métodos &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;getX()&lt;/span&gt;&lt;/b&gt; y &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;getY()&lt;/span&gt;&lt;/b&gt; de la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Actor&lt;/span&gt;&lt;/b&gt;. Estos dos métodos
devuelven como su resultado nuestra posición actual.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;Revisar si estamos en el borde izquierdo es bastante fácil, porque
sabemos que la coordenada del borde izquierdo siempre es cero. Así que podemos
escribir lo siguiente:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
if (getX()==0) ...
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;De hecho, queremos comenzar a girar no solo
cuando demos con el borde, si no que cuando estemos cerca de él. Vamos a
definir “cerca” en 10 pixeles. Así, podemos escribir lo siguiente:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
if (getX() &lt; 10) ...
]]&gt;&lt;/script&gt;


&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Eso trabajará bien.&amp;nbsp;&lt;/span&gt;Revisar si estamos en el
borde derecho, de todas formas, es un poco más complicado, porque la coordenada
del borde derecho de un mundo puede variar.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Una opción es mirar en
el código fuente de la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;TurtleWorld&lt;/span&gt;&lt;/b&gt; para ver el tamaño actual de nuestro mundo. Si hacemos esto,
podemos ver que nuestro mundo tiene un tamaño de 600 x 400 pixeles, así que la
posición más a la derecha posible está en la coordenada &lt;i&gt;x&lt;/i&gt; 599.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Agregando nuevamente, un búfer de 10 pixeles, podemos ahora extender
nuestra sentencia &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;if &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;desde arriba para además revisar el borde derecho:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
if (getX() &lt; 10 || getX() &gt;589) ...
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;La doble barra vertical (&lt;/span&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;) es un operador &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;or &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;(‘o’ en español), así que podemos leer esto de
la siguiente forma (en español, el código claro que va en inglés, pero lo que
sigue es pseudocódigo):&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
si (x es menos que 10 o x es mayor que 589) ...
]]&gt;&lt;/script&gt;


&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Esto va a trabajar para este mundo en
particular, pero solo mientras no decidamos en algún punto cambiar el tamaño de
nuestro mundo.&amp;nbsp;&lt;/span&gt;Una mejor solución sería
sólo llamar a un método y preguntarle qué tan ancho es el mundo.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Podemos hacer eso cambiando nuestra sentencia &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;if &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;a esto:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
if (getX() &lt; 10 || getX() &gt; getWorld().getWidth()-10) ...
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;En esta condición, &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;getWorld() &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;llama a un método para que devuelva el objeto &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;world&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; en sí.&lt;/span&gt;&amp;nbsp;Este objeto será devuelto desde esta llamada
al método. Nosotros entonces llamamos a un segundo método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;getWidth()&lt;/span&gt;&lt;/b&gt;, en este objeto &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;world&lt;/span&gt;&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Esta técnica es mucho mejor que poner el tamaño
actual del mundo en nuestra clase, porque se adaptará flexiblemente a los
cambios en el tamaño de nuestro mundo.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;El método completo, después de que completamos la sentencia &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;if &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;y además añadimos otra para revisar la
coordenada &lt;i&gt;y&lt;/i&gt; se muestra a
continuación:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
/**
* Test if we are close to an edge of the world. Return true if we are.
*/
public boolean atWorldEdge() {

 if(getX() &lt; 10 || getX() &gt; getWorld().getWidth() - 10) {
  return true;
 }

 if(getY() &lt; 10 || getY() &gt; getWorld().getHeight() - 10) {
  return true;
 }

 else {
  return false;
 }
}
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Sentencias if/else&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Otra nueva construcción
que vemos en el código anterior es un ejemplo de una sentencia &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;/&lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;else&lt;/span&gt;&lt;/b&gt;. Ya hemos visto
antes sentencias &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;, consisten de una condición y un cuerpo. El cuerpo fue ejecutado
solo cuando la condición era &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;true&lt;/span&gt;&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Esta nueva forma de la sentencia &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;if&lt;/span&gt;&lt;/b&gt; tiene una palabra
clave adicional, &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;else&lt;/span&gt;&lt;/b&gt;, y un segundo bloque de código adjunto (ver el código de arriba).
Este segundo bloque es ejecutado cuando la condición &lt;i&gt;no&lt;/i&gt; es &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;true&lt;/span&gt;&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Completando
el giro&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora tenemos un método que nos permite revisar
donde estamos cerca del borde del mundo. Lo siguiente que debemos hacer es
girar si estamos al borde. Esto es ahora bastante fácil.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Añadimos una sentencia &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;if&lt;/span&gt;&lt;/b&gt; a nuestro método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;moveAndTurn()&lt;/span&gt;&lt;/b&gt;, usando &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;atWorldEdge&lt;/span&gt;&lt;/b&gt; como condición y
giramos cuando notemos que estamos en el borde.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;A continuación se muestra la nueva versión del
método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;moveAndTurn()&lt;/span&gt;&lt;/b&gt; con esta mejora.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Intenta esto en tu propio &lt;i&gt;scenario&lt;/i&gt;. Deberías notar que las serpientes ahora giran muy
efectivamente una vez que llegan al borde del mundo.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
/**
* Move forward and turn if the control keys are pressed.
*/
public void moveAndTurn(){
 move(4);
 turn(Greenfoot.getRandomNumber(40)-20);

 if (atWorldEdge()){
  turn(13);
 }
}
]]&gt;&lt;/script&gt;


&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;Una lección importante&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La lección más importante que aprendimos de
esto es: El mundo es un objeto también, y tiene métodos útiles.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Podemos investigar los métodos del mundo de dos
formas: Podemos solo llamarlos o también podemos leer su documentación.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;Podemos llamar a un método del mundo dando click derecho a la imagen de
fondo del mundo y seleccionando un método heredado del submenú mundo como se
muestra a continuación:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1FnrduLemEoFGG0vj0oX8gzKC98inLItuGhkZUUtTRKPfFFhT-y2oTsgfKG1Kx8pdEDOQotesSdjfZS9_bNWs7WDMsGEAnwRyYNS9yWK-Q_LNMDDzusNRnsOORbLQ1cEy7VcmsYey14pU/s1600/Imagen2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1FnrduLemEoFGG0vj0oX8gzKC98inLItuGhkZUUtTRKPfFFhT-y2oTsgfKG1Kx8pdEDOQotesSdjfZS9_bNWs7WDMsGEAnwRyYNS9yWK-Q_LNMDDzusNRnsOORbLQ1cEy7VcmsYey14pU/s320/Imagen2.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Deberías intentar, por ejemplo, llamando a los
métodos &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;getWidth() &lt;/span&gt;&lt;/b&gt;y &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;numberOfObjects() &lt;/span&gt;&lt;/b&gt;para ver lo que hacen.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para investigar los métodos del mundo, leyendo
su documentación, ve a la ventana principal de Greenfoot y selecciona &lt;b&gt;Greenfoot Class Documentation&lt;/b&gt; del menú &lt;b&gt;Help&lt;/b&gt;. Esto abre un explorador web con
la documentación para todas las seis clases API. Selecciona la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;World &lt;/span&gt;&lt;/b&gt;y podrás ver una
lista de métodos disponibles y sus descripciones.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Añadiendo
sonido&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Otra cosa que podemos hacer para mejorar
nuestro pequeño juego es añadir efectos de sonido.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Descarga los archivos &lt;i&gt;&lt;a href=&quot;https://docs.google.com/open?id=0BysLlaOg7wsWYnU4d3lXUjFUQXc&quot; target=&quot;_blank&quot;&gt;slurp.wav&lt;/a&gt;&lt;/i&gt; (slurp = sorber) y &lt;i&gt;&lt;a href=&quot;https://docs.google.com/open?id=0BysLlaOg7wsWLTFyZ1pVUU1JeXM&quot; target=&quot;_blank&quot;&gt;au.wav&lt;/a&gt;&lt;/i&gt;
y guárdalos en tu carpeta del proyecto de la tortuga, ejemplo:&amp;nbsp; &lt;i&gt;C:\Greenfoot\scenarios\turtle\sounds\&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;La clase &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Greenfoot &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;tiene un método estático &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;playSound &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;que toma el nombre y reproduce el sonido. Así que podemos reproducir el
sonido &lt;i&gt;slurp&lt;/i&gt; simplemente escribiendo
lo siguiente:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Greenfoot.playSound(&quot;slurp.wav&quot;);
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Trata de añadir esta sentencia al código de tu tortuga, de manera que
este sonido sea reproducido cuando la tortuga coma algo de pizza. A
continuación se muestra el método &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;eat() &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;resultante:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
/**
* Look for pizza and eat it if we see some.
*/
public void eat(){
 Actor pizza = getOneIntersectingObject(Pizza.class);

 if(pizza != null) {
  getWorld().removeObject(pizza);
  Greenfoot.playSound(&quot;slurp.wav&quot;);
 }
}
]]&gt;&lt;/script&gt;


&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;Si esto funciona, haz un cambio similar al código del actor &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Snake&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;, de manera que la serpiente reproduzca el sonido &lt;i&gt;au.wav&lt;/i&gt; cuando se coma la tortuga.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Grabando
tus propios sonidos&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Añadir efectos de sonido reproduciendo sonidos
pregrabados es fácil, y eso añade un poco de diversión al proyecto. Pero
podemos hacer esto aún mejor creando nuestros propios sonidos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Mientras se pueden encontrar librerías de
efectos de sonido gratuitas en el internet y usar los efectos descargados de
ahí, por mucho la manera más fácil (y la más divertida) de añadir efectos es
grabándolos tú mismo. Puedes hacer esto en cualquier computadora con un
micrófono integrado.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;Greenfoot tiene un grabador de sonidos integrado que hace realmente
fácil hacer esto. Usando el menú principal, elige &lt;b&gt;Show sound recorder&lt;/b&gt; desde el menú &lt;b&gt;Controls&lt;/b&gt;. Esto traerá la interfaz del grabador de sonidos en una
ventana separada como se muestra a continuación:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAeErUu015byvUmmXtiw6z0EKYdhF6BDl3jGkeZYfJRk_6AgLFop0iRAN0CFKQGGGGBmuxLSxBb_1s0AuLMdG15u2_z8HpDsdEkLEulqF75mPtkYX7GRwFgJUG1ayab6ftfgiXynguGjPf/s1600/Imagen3.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;269&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAeErUu015byvUmmXtiw6z0EKYdhF6BDl3jGkeZYfJRk_6AgLFop0iRAN0CFKQGGGGBmuxLSxBb_1s0AuLMdG15u2_z8HpDsdEkLEulqF75mPtkYX7GRwFgJUG1ayab6ftfgiXynguGjPf/s320/Imagen3.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Este grabador de sonidos te permite grabar tu
propia voz, o cualquier otro efecto de sonido, y recortarlo para eliminar
sobresalientes no deseados o ruido de fondo o silencio. Puedes entonces guardar
el sonido bajo el nombre de tu elección. Nota que Greenfoot siempre añadirá el
sufijo &lt;i&gt;.wav&lt;/i&gt; al nombre tu tu archivo.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Esto es importante porque se debe usar el
nombre de archivo completo cuando se usa el sonido en tu código.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Por ejemplo, si se especifica “bark” como el nombre para tu sonido,
Greenfoot nombrará el archivo como &lt;i&gt;bark.wav&lt;/i&gt;,
y podrás reproducirlo en el &lt;i&gt;scenario&lt;/i&gt;
usando la siguiente sentencia en tu código fuente:&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Greenfoot.playSound(&quot;bark.wav&quot;);
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 15px;&quot;&gt;Añadiendo tus propios efectos de sonido es una manera muy efectiva y muy fácil para personalizar tu &lt;i&gt;scenario&lt;/i&gt; y hacerlo mucho más atractivo y divertido de jugar.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;La
clase Greenfoot&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Aquí hay una lección general para llevar de
esto: Vale la pena estar familiarizado con los métodos disponibles en la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Greenfoot&lt;/span&gt;&lt;/b&gt;. Abre de nuevo la
documentación de clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Greenfoot &lt;/span&gt;&lt;/b&gt;(como se describe arriba, usando la función del menú &lt;b&gt;Help&lt;/b&gt;) y da un vistazo a los métodos
disponibles en esta clase.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Tenemos ya usados algunos de ellos (para
números aleatorios, control de teclado, y sonido), pero ahí hay otros que quizá
encuentres útiles para hacer futuros cambios en tu propio &lt;i&gt;scenario&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El API Greenfoot no es grande, y leer la
documentación es tiempo bien gastado si planeas trabajar más con Greenfoot.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Tip:&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; Maestros e instructores pueden encontrar mucho material de enseñanza en
la &lt;a href=&quot;http://greenroom.greenfoot.org/door&quot; target=&quot;_blank&quot;&gt;comunidad de educadores Greenroom&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Conclusión&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En este articulo, encontramos dos aspectos
fundamentales de Java y la programación en Greenfoot:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El mundo en sí es un objeto Java. Tiene métodos
que tú puedes llamar para interactuar con el mundo. Puedes usar la
documentación del API Greenfoot para encontrar otros métodos existentes.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Greenfoot puede fácilmente grabar y reproducir
sonidos. Esto hace a los &lt;i&gt;scenarios&lt;/i&gt; de
juego mucho más atractivos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El método para reproducir un sonido está en la
clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Greenfoot&lt;/span&gt;&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Bueno, eso es todo por hoy, ya me cansé de escribir, para la próxima
entrada, la parte final de este gran proyecto, no se la pierdan, pueden
suscribirse por email si quieren, en la parte superior derecha de esta página,
comentarios, dudas, peticiones, criticas, abajo, con gusto doy respuesta,
saludos a todos.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Traducción: El Blog De Baro.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Escrito por: Michael Kölling.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Fuente: &lt;a href=&quot;http://www.oracle.com/technetwork/java/javamagazine/index.html&quot; target=&quot;_blank&quot;&gt;Java Magazine&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-6.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 6)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-4.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 4)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-3.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Aprender Java creando un juego (Parte 3)&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-2.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 2)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-1.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 1)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/5169286066613113742/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-5.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/5169286066613113742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/5169286066613113742'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-5.html' title='Aprender Java creando un juego (Parte 5)'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRDXlEXwHrWI9Rgm-g_f_AHMVxHFTUx5QvyTX8o-BC6lZrUGkTedpRxWBQmodwBamuvp1TU1Op9O5Di_Z84qkyfXuf0XJUe8RLMVbQLDLs4nQy8qu9zEdC7oMoSMkC8Qg6krLRRFkDKW-n/s72-c/Imagen1.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-6504791471021757208</id><published>2012-09-29T11:56:00.000-07:00</published><updated>2012-10-22T13:19:45.739-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aprender java creando un juego"/><category scheme="http://www.blogger.com/atom/ns#" term="Greenfoot"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java Greenfoot"/><category scheme="http://www.blogger.com/atom/ns#" term="Java magazine"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Juegos"/><category scheme="http://www.blogger.com/atom/ns#" term="Juegos en java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><category scheme="http://www.blogger.com/atom/ns#" term="Video juegos"/><category scheme="http://www.blogger.com/atom/ns#" term="Video juegos Greenfoot"/><title type='text'>Aprender Java creando un juego (Parte 4)</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;



&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Buen día para
todos mis lectores, después de algunos días de ausencia, aquí les tengo la cuarta
parte del proyecto de la tortuga en el entorno Greenfoot, como les había dicho
ya, nuestra tortuga enfrentará una situación aún más peligrosa (porque ya bastante
riesgo era morir de una sobredosis de pizza), la pondremos en la mira de un
depredador, para ser más precisos, una serpiente, así que aquí les va...&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot;&gt;Hemos creado ya
una tortuga controlada por teclado que camina y come pizza. En este articulo,
empezaremos a hacer las cosas más interesantes introduciendo un depredador que
está tras nuestra tortuga&lt;/span&gt;—nuestra
tortuga no solo debe recolectar las rebanadas de pizza, ¡sino que también debe
evitar ser comida por una serpiente mientras o hace! Vamos a continuar desde
donde dejamos nuestro proyecto la vez anterior, así que si te perdiste los
artículos pasados, quizá sea una buena idea verlos primero para ver cómo
llegamos hasta aquí (&lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-1.html&quot; target=&quot;_blank&quot;&gt;Parte 1&lt;/a&gt;, &lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-2.html&quot; target=&quot;_blank&quot;&gt;Parte 2&lt;/a&gt;, &lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-3.html&quot; target=&quot;_blank&quot;&gt;Parte 3&lt;/a&gt;).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Limpiando Nuestro Código&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El
método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act &lt;/span&gt;&lt;/b&gt;de
nuestra tortuga, como lo dejamos la última vez, se muestra a continuación:&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
public void act(){
  move(4);
 
  if(Greenfoot.isKeyDown(&quot;left&quot;)) {
   turn(-3);
  }
  if(Greenfoot.isKeyDown(&quot;right&quot;)) {
   turn(3);
  }
 
  Actor pizza = getOneIntersectingObject(Pizza.class);
  
  if(pizza != null) {
   getWorld().removeObject(pizza);
  }
  
}
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Antes
de que vayamos a añadir más funcionalidad a nuestro programa (y, en el proceso,
hacer nuestro código más complejo), es una buena idea tomarse un minuto para
mejorar la estructura de nuestro código.&amp;nbsp;&lt;/span&gt;Especialmente,
nuestro método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act &lt;/span&gt;&lt;/b&gt;se
está volviendo un poco largo, y está comenzando a tomar algo de esfuerzo para
leerlo y darse cuenta de lo que hace.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;En
general, deberíamos apegarnos a mantener nuestros métodos cortos y claros (o
como diría Steve Oualline, apegarnos al principio KISS: “&lt;i&gt;Keep It Simple, Stupid&lt;/i&gt;”). Podemos hacer esto rompiendo el método &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;act &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;en
múltiples métodos, cada uno definiendo una tarea lógica. En nuestro ejemplo,
nuestro método &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;act &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;hace
dos tareas lógicas distintas:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-indent: -18pt;&quot;&gt;Movimiento
(moverse hacia adelante y posiblemente girando)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-indent: -18pt;&quot;&gt;Buscar
pizza (y posiblemente comiéndola)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Podemos mover cada una de estas dos tareas en un método por
separado, y entonces llamar a cada método desde el método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act&lt;/span&gt;&lt;/b&gt;. En esta versión del código,
hemos definido dos métodos adicionales, &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold; mso-fareast-font-family: ZapfDingbatsITC;&quot;&gt;moveAndTurn
&lt;/span&gt;&lt;/b&gt;y &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold; mso-fareast-font-family: ZapfDingbatsITC;&quot;&gt;eat&lt;/span&gt;&lt;/b&gt;. Da una buena mirada a continuación para ver cómo fue hecho esto:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
 /**
  * Act: move around (keyboard controlled) and eat pizza if we find any.
  */
 public void act() {
  moveAndTurn();
  eat();
 }

 /**
  * Move forward and turn if the control keys are pressed.
  */
 public void moveAndTurn(){
  move(4);
  
     if(Greenfoot.isKeyDown(&quot;left&quot;)){
         turn(-3);
     }

     if(Greenfoot.isKeyDown(&quot;right&quot;)){
         turn(3);
     }
 }

 /**
  * Look for pizza and eat it if we see some
  */
 public void eat(){
     Actor pizza = getOneIntersectingObject(Pizza.class);
     
     if(pizza != null) {
         getWorld().removeObject(pizza);
     }
 }
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Cada una
de las definiciones de método tiene una sección al inicio conteniendo algunos
asteriscos. Por ejemplo, el método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold; mso-fareast-font-family: ZapfDingbatsITC;&quot;&gt;eat&lt;/span&gt;&lt;/b&gt; comienza con esto:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
 /**
 * Look for pizza and eat it
 * if we see some.
 */
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Este es un &lt;i&gt;comentario de método&lt;/i&gt;.&lt;/span&gt;Un
comentario es escrito para el programador (no para la computadora). El
comentario explica, en tus palabras, (o las de otro programador si estás viendo
el comentario de alguien más) el propósito del método que está debajo. Las
líneas siguientes al comentario definen el método. Te darás cuenta que los
cuerpos de los métodos contienen exactamente el mismo código que estaba
previamente en el cuerpo del método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold; mso-fareast-font-family: ZapfDingbatsITC;&quot;&gt;act&lt;/span&gt;&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora, el
método&lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold; mso-fareast-font-family: ZapfDingbatsITC;&quot;&gt; act&lt;/span&gt;&lt;/b&gt; contiene sólo llamadas a los dos nuevos métodos:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
 public void act(){
  moveAndTurn();
  eat();
 }
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Nota que esta versión de nuestro código hace exactamente lo mismo que la
versión anterior&lt;/span&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;—es funcionalmente equivalente.&amp;nbsp;&lt;/span&gt;De todas formas, a causa de que lo hemos
cortado en partes más pequeñas, es ahora más fácil de leer, y podemos reconocer
más fácilmente qué hace el método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold; mso-fareast-font-family: ZapfDingbatsITC;&quot;&gt;act&lt;/span&gt;&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Deberías
hacer los mismos cambios en tu propio código.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;¡Serpientes Abordo!&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora que
hemos mejorado la estructura de nuestro código, podemos seguir adelante
añadiendo cosas a nuestro proyecto. Queremos introducir un enemigo de nuestra
tortuga: serpientes.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Comienza por crear otra
subclase de &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Actor&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;, llamada&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt; Snake&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;, con la imagen de una serpiente. Recuerda, puedes crear una subclase de
&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Actor&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; dando click derecho a la clase &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Actor&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; y eligiendo &lt;b&gt;New subclass&lt;/b&gt;.
Nombra a la clase &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Snake&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; y elige una imagen de serpiente de la categoría &lt;b&gt;Animals&lt;/b&gt; como se muestra a continuación:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQvHf9M_tPCUmfHFeCHgNMDEVYBqNRWZ2hovNO1IMmj0FOpqJHmh8rNcFXPcmk5lkFxHlL5X3uKDus36isCdUywLfesRblvmwSlme3-B2R49JtCq5yNIEqfxak_doM5LIjiOKPf9F7AqTE/s1600/Imagen1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;292&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQvHf9M_tPCUmfHFeCHgNMDEVYBqNRWZ2hovNO1IMmj0FOpqJHmh8rNcFXPcmk5lkFxHlL5X3uKDus36isCdUywLfesRblvmwSlme3-B2R49JtCq5yNIEqfxak_doM5LIjiOKPf9F7AqTE/s320/Imagen1.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: left;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Compila tu
&lt;i&gt;scenario&lt;/i&gt; y pon unas cuantas
serpientes en el mundo como se muestra a continuación:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4bdICj6bfIJFa053gqFpBNI4WlAi9S2Ujg-rU0u7O7oLETDnRAWaFCQUoHpGi3ARrZ0DlqnE9LIf4nt8aS7RpFcwcM3l0fbWzvBezr4JYpKuzPAGt21rkTu5eUxylner0843XOKYaGr3Z/s1600/Imagen2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;201&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4bdICj6bfIJFa053gqFpBNI4WlAi9S2Ujg-rU0u7O7oLETDnRAWaFCQUoHpGi3ARrZ0DlqnE9LIf4nt8aS7RpFcwcM3l0fbWzvBezr4JYpKuzPAGt21rkTu5eUxylner0843XOKYaGr3Z/s320/Imagen2.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Quizá
quieras salvar el mundo de nuevo (click derecho en la imagen de fondo del mundo
y elige &lt;b&gt;Save the World&lt;/b&gt;) agrega tus
serpientes al mundo salvado.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Comportamiento de la serpiente&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Inicialmente,
nuestra serpiente no hace nada.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Nos
gustaría que ellas se movieran en toda la pantalla al azar y trataran de
comerse a la tortuga.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La meta
para el jugador, entonces, es controlar a la tortuga y comer todas las
rebanadas de pizza mientras evade las serpientes.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Podemos
empezar copiando todos los tres métodos de la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Turtle &lt;/span&gt;&lt;/b&gt;(&lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act&lt;/span&gt;&lt;/b&gt;, &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;moveAndTurn&lt;/span&gt;&lt;/b&gt;, &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;eat&lt;/span&gt;&lt;/b&gt;) en la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Snake&lt;/span&gt;&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Haz esto usando &lt;i&gt;copy&lt;/i&gt; y &lt;i&gt;paste&lt;/i&gt; para
remplazar el método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act&lt;/span&gt;&lt;/b&gt; que está vacío por default en la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Snake&lt;/span&gt;&lt;/b&gt;. Asegúrate de ver
las llaves { } —El cuerpo de la clase aún necesita una llave que abra ‘{’ y
otra que cierre ‘}’. En este punto, quizá quieras compilar y correr tu &lt;i&gt;scenario&lt;/i&gt; para probar lo que hace. No es
exactamente lo que queremos aún, pero hace algo. (Verás que las serpientes
siguen tus presiones de tecla, exactamente como lo hace la tortuga.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hay dos cosas que nos gustaría cambiar en la
clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Snake&lt;/span&gt;&lt;/b&gt; del comportamiento copiado de la tortuga. Primero, las serpientes
deberían comer tortugas, no pizza. Y segundo, las serpientes deberían moverse
por su cuenta (al azar), en lugar de ser controladas por el teclado.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Podemos hacer el primer cambio dirigiéndonos al método &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;eat&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; de la serpiente y reemplazando todas las menciones de “&lt;i&gt;pizza&lt;/i&gt;” con “&lt;i&gt;turtle&lt;/i&gt;”, como se muestra a continuación:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Actor turtle = getOneIntersectingObject(Turtle.class);

if(turtle != null) {
    getWorld().removeObject(turtle);
}

]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Presta atención a la capitalización: Letras mayúsculas y minúsculas
deben ser usadas exactamente como se muestran.&amp;nbsp;&lt;/span&gt;Cuando escribimos &lt;i&gt;Turtle&lt;/i&gt; (con T mayúscula), nos estamos refiriendo a la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Turtle&lt;/span&gt;&lt;/b&gt;. Cuando escribimos
en minúsculas (&lt;i&gt;turtle&lt;/i&gt;), nos estamos
refiriendo a una &lt;i&gt;variable&lt;/i&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Prueba tu &lt;i&gt;scenario&lt;/i&gt;.
Las serpientes deberían comer tortugas, no pizza.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Caminando
al azar&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En este momento, las serpientes siguen
controladas por las mismas teclas que dirigen a las tortugas. Eso no es bueno.
Podemos cambiar esto, primer haciendo a la serpiente correr en círculos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Elimina el código del cuerpo del método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;moveAndTurn&lt;/span&gt;&lt;/b&gt; de la serpiente
que implementa un giro controlado por teclado, y reemplazalo con una simple
sentencia &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;turn(3)&lt;/span&gt;&lt;/b&gt;. El método debería verse ahora así:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
public void moveAndTurn(){
 move(4);
 turn(3);
}
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11pt;&quot;&gt;Inténtalo. Las serpientes ahora se mueven por su cuenta (aún cuando es
en un patrón muy predecible).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Ahora queremos hacer el movimiento más aleatorio. Para hacer esto,
podemos usar un método de la clase &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Greenfoot &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;llamado &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;getRandomNumber&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;. Este método va a darnos
un número aleatorio entre 0 y el límite especificado. Por ejemplo, lo siguiente
nos dará un número aleatorio entre 0 y 19 (el límite especificado en sí siempre
es excluido):&lt;/span&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
 Greenfoot.getRandomNumber(20);
]]&gt;&lt;/script&gt;


&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;Podemos usar este método para hacer las vueltas de las serpientes menos
predecibles.&lt;/span&gt;Si usamos un número
aleatorio como parámetro para el método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;turn &lt;/span&gt;&lt;/b&gt;(en lugar del número 3 que usábamos
anteriormente), la serpiente debería caminar más aleatoriamente:

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
 turn(Greenfoot.getRandomNumber(20));
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Si intentas esto, te darás cuenta de que la serpiente sigue moviéndose
en círculo, aunque es un círculo algo irregular.&amp;nbsp;&lt;/span&gt;La razón es que las
vueltas—aún cuando
tienen algo de aleatorias—son siempre vueltas a la derecha.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para arreglar esto, necesitamos
hacer a la serpiente girar a la izquierda también. Girar a la izquierda puede
hacerse girando en un ángulo negativo. En lugar de girar entre 0 y 20 grados,
nos gustaría girar entre menos 20 grados y 20 grados.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;Podemos
lograr esto con el siguiente cambio:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 11.0pt; mso-ansi-language: ES-MX; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
 turn(Greenfoot.getRandomNumber(40)-20);
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;Eso es, primero obtenemos un número aleatorio usando 40 como el límite especificado, y entonces restamos 20 de él.&amp;nbsp;&lt;/span&gt;El resultado estará entre -20 y 20. (En realidad, si
piensas con cuidado sobre ello, esto es un tanto incorrecto. El resultado sería
entre -20 y 19. ¿Puedes descubrir por qué? ¿Puedes corregirlo? No es realmente
muy importante en nuestro contexto corregir esta ligera imprecisión—la
serpiente se mueve erráticamente, así que un poco de tendencia no duele mucho.)&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Intenta esta instrucción de giro (en lugar del anterior &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;turn(3)&lt;/span&gt;&lt;/b&gt;) en tu propio código.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¡Verás que el juego de pronto se vuelve mucho más
interesante!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Mejorando el
juego&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hay muchas formas en las cuales podrías mejorar este juego.
En lugar de hablarlo deberías probar algo de eso ahora mismo, te mostraré algo
más útil: cómo puedes averiguar más por tu cuenta.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hasta ahora, introdujimos varios métodos útiles que podemos
usar, como &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;move&lt;/span&gt;&lt;/b&gt;
y&lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;
turn&lt;/span&gt;&lt;/b&gt; en la
clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Actor&lt;/span&gt;&lt;/b&gt;
y &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;getRandomNumber&lt;/span&gt;&lt;/b&gt; de la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Greenfoot&lt;/span&gt;&lt;/b&gt;. Así que, ¿cómo descubrir que
otros métodos están para usarlos?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La respuesta está en buscar la &lt;i&gt;documentación de clase&lt;/i&gt;. Elige &lt;b&gt;Greenfoot
Class Documentation&lt;/b&gt; del menú &lt;b&gt;Help&lt;/b&gt;
de Greenfoot. Esto abrirá un explorador web que enlista todas las clases en el
sistema Greenfoot. (Verás que hay seis clases: &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Actor&lt;/span&gt;&lt;/b&gt;, &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;World&lt;/span&gt;&lt;/b&gt;, &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Greenfoot&lt;/span&gt;&lt;/b&gt;, &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;GreenfootImage&lt;/span&gt;&lt;/b&gt;, &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;GreenfootSound&lt;/span&gt;&lt;/b&gt; y &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;MouseInfo&lt;/span&gt;&lt;/b&gt;.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Da click en la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Greenfoot&lt;/span&gt;&lt;/b&gt; para ver la documentación para esta clase. Si tú te
desplazas un poco en la página, verás una lista d métodos disponibles en la
clase. Están los métodos &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;getRandomNumber&lt;/span&gt;&lt;/b&gt; e &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;isKeyDown&lt;/span&gt;&lt;/b&gt;
que ya hemos usado y un buen número de otros tantos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El formato mostrado está en el llamado &lt;i&gt;javadoc&lt;/i&gt;. Es un formato estándar para documentar métodos Java, y
esto ayuda a determinar lo que clases particulares pueden hacer. La
documentación incluye el tipo devuelto (lo que el método regresa cuando lo
llamas), la firma (que es, el nombre y parámetros), y un comentario explicando
lo que hace el método. Aquí, puedes averiguar todo acerca de otros métodos
disponibles y cómo puedes llamarlos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Por ahora, te dejaré explorar estos métodos por tu cuenta.
(Las clases más interesantes para mirar inicialmente son &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Actor &lt;/span&gt;&lt;/b&gt;y &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Greenfoot&lt;/span&gt;&lt;/b&gt;.) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;Tip:&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; Puedes ver y descargar muchos programas
Greenfoot Java en el &lt;a href=&quot;http://www.greenfoot.org/home&quot; target=&quot;_blank&quot;&gt;sitio web de Greenfoot&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Conclusión&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En este artículo, aprendiste unas cuantas cosas
específicas acerca del código Java y algunos principios generales:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;El código debe ser estructurado de manera que
tengas métodos pequeños y cada uno haga una tarea lógica. (El método &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;en sí debería
muchas veces contener sólo llamadas a otros métodos.&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Los números aleatorios se pueden usar para crear
comportamiento aleatorio en nuestro programa (como movimiento aleatorio).&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Puedes encontrar acerca de los métodos
disponibles en las clases &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Greenfoot&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; buscando en la documentación de clase &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Greenfoot&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La documentación de clase es provista en formato javadoc, el cual te
muestra información acerca de todas las clases disponibles y acerca de cada
método dentro de cada clase.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Y bien, eso es todo por
este artículo, espero lo hayan disfrutado, no se pierdan los siguientes porque
se añadirá más “inteligencia” a la serpiente y en el camino aprenderemos más de
la clase &lt;b&gt;World&lt;/b&gt; de Greenfoot.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Si no quieren perderse
lo que sigue, pero tampoco pueden venir a revisar mis entradas cada que
recuerden, lo ideal sería suscribirse vía mail, ¿cómo? Escribiendo su correo en
la parte superior derecha de mi blog, donde dice “Noticias del blog a tu Email”
dan click en “Submit” y de esa forma cada que suba una entrada tendrán un aviso
en su bandeja de correo, y pues ya saben, criticas, dudas, peticiones o
comentarios abajo, saludos.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Traducción: El Blog De Baro.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Escrito por: Michael Kölling.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Fuente: &lt;a href=&quot;http://www.oracle.com/technetwork/java/javamagazine/index.html&quot; target=&quot;_blank&quot;&gt;Java Magazine&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 15px;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-6.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 6)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-5.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 5)&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-3.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 3)&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-2.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 2)&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-1.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 1)&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18.0pt;&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/6504791471021757208/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-4.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/6504791471021757208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/6504791471021757208'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-4.html' title='Aprender Java creando un juego (Parte 4)'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQvHf9M_tPCUmfHFeCHgNMDEVYBqNRWZ2hovNO1IMmj0FOpqJHmh8rNcFXPcmk5lkFxHlL5X3uKDus36isCdUywLfesRblvmwSlme3-B2R49JtCq5yNIEqfxak_doM5LIjiOKPf9F7AqTE/s72-c/Imagen1.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-2027659437285469331</id><published>2012-09-25T14:26:00.000-07:00</published><updated>2012-10-22T13:22:32.124-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aprender java creando un juego"/><category scheme="http://www.blogger.com/atom/ns#" term="Greenfoot"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java Greenfoot"/><category scheme="http://www.blogger.com/atom/ns#" term="Java magazine"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Juegos"/><category scheme="http://www.blogger.com/atom/ns#" term="Juegos en java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><category scheme="http://www.blogger.com/atom/ns#" term="Video juegos"/><category scheme="http://www.blogger.com/atom/ns#" term="Video juegos Greenfoot"/><title type='text'>Aprender Java creando un juego (Parte 3)</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;



&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hola y buen día a
todos mis lectores, esta es la tercera parte del proyecto para desarrollar el
inicio de un juego para PC en lenguaje Java utilizando el entorno &lt;a href=&quot;http://www.greenfoot.org/about/&quot; target=&quot;_blank&quot;&gt;Greenfoot&lt;/a&gt;, (&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-1.html&quot; target=&quot;_blank&quot;&gt;Parte1&lt;/a&gt;, &lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-2.html&quot; target=&quot;_blank&quot;&gt;Parte 2&lt;/a&gt;) aquí les va...&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¿Qué comen las tortugas? ¡Pizza!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot;&gt;Lo siguiente,
queremos dar a la tortuga algo que hacer: recolectar algo de comida y comerla.
Para hacer esto, necesitamos algunos nuevos objetos en nuestro mundo: rebanadas
de pizza.&amp;nbsp; (Así es, nuestra tortuga come
pizza. Ésta no es una lección de biología&lt;/span&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;—&lt;/span&gt;&lt;span lang=&quot;ES&quot;&gt;Es un juego de computadora.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot;&gt;¿De dónde vienen
los objetos? De una clase. Así que primero, necesitamos crear una clase &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Pizza&lt;/span&gt;&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Damos click derecho en la clase &lt;b&gt;Actor&lt;/b&gt; y seleccionar la función &lt;b&gt;New
Subclass&lt;/b&gt;. En la caja de dialogo resultante, ingresa &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Pizza&lt;/span&gt;&lt;/b&gt; como el nombre de
la clase, y busca la imagen de la rebanada de pizza en la categoría &lt;b&gt;food&lt;/b&gt;. Da click en &lt;b&gt;OK&lt;/b&gt;.&lt;b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Tan pronto como las clases son compiladas de nuevo, puedes añadir
unas cuantas rebanadas de pizza (al igual que tortugas) a tu mundo.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Inténtalo. Deja a tu tortuga correr alrededor para recolectar
pizza. Te darás cuenta, sin embargo, que la tortuga no come la pizza (aún).
Solamente atraviesa la pizza. Arreglaremos eso ahora.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Dos tips&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Si estás trabajando y experimentando en Greenfoot un poco, te
habrás dado cuenta que necesitas re-crear todos los objetos en el mundo después
de cada compilación. Esto se puede volver un poco tedioso después de un tiempo,
especialmente si tenemos muchos objetos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Aquí hay dos tips rápidos para hacer tu vida en Greenfoot un poco
más fácil.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-indent: -18pt;&quot;&gt;Puedes dar click + shift en el mundo. Éste es un atajo para crear
un objeto de la clase que esté actualmente seleccionada en el diagrama de clase
a la derecha.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Cuando todos los objetos están en el mundo como quieres que estén
al inicio de tu juego, puedes dar click derecho en el fondo del mundo y
seleccionar &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;Save the World&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; para
guardar este estado del mundo. Este estado va entonces a ser re-creado
automáticamente después de cada compilación o &lt;/span&gt;&lt;i style=&quot;text-indent: -18pt;&quot;&gt;reset&lt;/i&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18.0pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Detección de colisión&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;OK, tenemos pizza. Tenemos una tortuga. La tortuga está
hambrienta.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La última parte qué hacer por hoy es hacer que la tortuga se dé
cuenta cuando pasa por alguna pizza y hacer a la tortuga comer la pizza. Para
esto vamos a necesitar lo que se llama &lt;i&gt;collision
detection&lt;/i&gt; (detección de colisión) para detectar cuando hemos pasado por
alguna rebanada de pizza. El código completo para hacer esto se encuentra a continuación:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Actor pizza = getOneIntersectingObject(Pizza.class);
if(pizza != null) {
   getWorld().removeObject(pizza);
}
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Este código debería ser agregado al final del método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act &lt;/span&gt;&lt;/b&gt;en la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Turtle&lt;/span&gt;&lt;/b&gt;. Hay varios nuevos
elementos en este segmento de código. Vamos a verlos uno por uno.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La primera línea llama a un método Greenfoot: &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;getOneIntersectingObject(Pizza.class)&lt;/span&gt;&lt;/b&gt;. Este método
revisa donde la tortuga interseca un objeto de la clase &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;pizza &lt;/span&gt;&lt;/b&gt;(o, en otras
palabras, pregunta, “¿Estamos tocando una rebanada de pizza?”). Si estamos
tocando una rebanada de pizza, este método regresa el objeto &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;pizza &lt;/span&gt;&lt;/b&gt;que encontramos. Si
no, regresa un valor especial, &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;null&lt;/span&gt;&lt;/b&gt;, que nos dice que no estamos tocando nada.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;El símbolo de igual ( = ) en la primera línea es un operador de &lt;i&gt;asignación&lt;/i&gt;. Almacena el resultado de
nuestra revisión de colisión (el objeto &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11pt;&quot;&gt;pizza &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;o &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 11pt;&quot;&gt;null&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;) en una &lt;i&gt;variable&lt;/i&gt;. Una
variable es una parte de almacenamiento donde podemos guardar objetos. En
nuestro caso, la variable ha sido declarada usando la siguiente sentencia al
inicio de la primera línea:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Actor pizza
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Esto declara una variable llamada &lt;b&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;pizza&lt;/span&gt;&lt;/b&gt; que puede sostener objetos &lt;b&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;Actor&lt;/span&gt;&lt;/b&gt; (objetos que viven en el mundo Greenfoot).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Después de la primera línea, la variable &lt;b&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;pizza&lt;/span&gt;&lt;/b&gt; sostiene el objeto &lt;b&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;pizza&lt;/span&gt;&lt;/b&gt; sobre el que pasamos, o sostiene &lt;b&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;null&lt;/span&gt;&lt;/b&gt; si no hemos pasado sobre una rebanada de pizza en este paso.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora sigue otro ejemplo de una sentencia &lt;b&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;. En pseudocódigo, el estado de las siguientes líneas sería el siguiente:&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
if(hemos-pasado-sobre-pizza) {
eliminar-el-objeto-pizza-de-nuestro-mundo;
}
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La revisión de condición es hecha con la siguiente expresión:&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
if(pizza != null) {
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El símbolo &lt;b&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;!=&lt;/span&gt;&lt;/b&gt; &amp;nbsp;significa &lt;i&gt;no igual&lt;/i&gt;. Por lo tanto, aquí estamos diciendo, “Si nuestra variable &lt;b&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;pizza&lt;/span&gt;&lt;/b&gt; no es igual a null…” El efecto es que la instrucción en el cuerpo de la sentencia if es ejecutada sólo si la variable pizza no es igual a null, eso es, si hemos pasado sobre alguna pizza.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La siguiente línea entonces elimina el objeto &lt;b&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;pizza&lt;/span&gt;&lt;/b&gt; del mundo. Se muestra a continuación la versión completa de nuestro método &lt;b&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;act&lt;/span&gt;&lt;/b&gt; en esta etapa.&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
public void act() 
{
    move(4);
    
    if(Greenfoot.isKeyDown(&quot;left&quot;)) {
        turn(-3);
    }
    
    if(Greenfoot.isKeyDown(&quot;right&quot;)) {
        turn(3);
    }

    Actor pizza = getOneIntersectingObject(Pizza.class);
    if(pizza != null) {
        getWorld().removeObject(pizza);
    }
}

]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Inténtalo. Una vez que hayas escrito este código, tu tortuga puede caminar alrededor y comer pizza:&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPQS-qyBdlQk0wrmtGRkOaSD1xNQcQUD0G3EIutwz58tYJ-Pa-0UmgJKv8JRUgTrCtPnADv0ApgW85OHG2Yzf3_wAbrhWLTfM7zW2xEZjTwtdXW30mcZstUUfCEURvtoXl1EUd8FtD_Pib/s1600/Imagen1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;201&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPQS-qyBdlQk0wrmtGRkOaSD1xNQcQUD0G3EIutwz58tYJ-Pa-0UmgJKv8JRUgTrCtPnADv0ApgW85OHG2Yzf3_wAbrhWLTfM7zW2xEZjTwtdXW30mcZstUUfCEURvtoXl1EUd8FtD_Pib/s320/Imagen1.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Conclusión&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En este artículo, aprendiste un poco más sobre escribir código
Java, y acerca de algunos métodos útiles de Greenfoot.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Las sentencias &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;if &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;pueden ser usadas para ejecutar una acción solo bajo cierta condición.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Las sentencias &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;if &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;tienen una condición y un cuerpo. El cuerpo es ejecutado solamente
si la condición es &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;true&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;El método &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Greenfoot.isKeyDown&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; puede ser usado para revisar presiones de
tecla.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;El método &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Greenfoot.isKeyDown&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; puede ser usado como la condición en una
sentencia &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La detección de colisión puede ser usada para revisar donde un
objeto toca a otro.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Las variables son usadas para almacenar objetos.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;El valor especial &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;null &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;es usado para indica que no tenemos un objeto.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18.0pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Bien, eso es todo por ahora, pero próximamente tendremos mucho más
de este interesante proyecto, no se lo pierdan porque pondremos a nuestra
tortuga en la mira de un predador. No olviden comentar, compartir, hacer
peticiones, plantear sus dudas o criticas abajo, con gusto daré respuesta,
saludos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Traducción: El Blog De Baro.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Escrito por: Michael Kölling.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Fuente: &lt;a href=&quot;http://www.oracle.com/technetwork/java/javamagazine/index.html&quot; target=&quot;_blank&quot;&gt;Java Magazine&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-6.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 6)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-5.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 5)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-4.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 4)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-2.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 2)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-1.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 1)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/2027659437285469331/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-3.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/2027659437285469331'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/2027659437285469331'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-3.html' title='Aprender Java creando un juego (Parte 3)'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPQS-qyBdlQk0wrmtGRkOaSD1xNQcQUD0G3EIutwz58tYJ-Pa-0UmgJKv8JRUgTrCtPnADv0ApgW85OHG2Yzf3_wAbrhWLTfM7zW2xEZjTwtdXW30mcZstUUfCEURvtoXl1EUd8FtD_Pib/s72-c/Imagen1.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-3463565122397689987</id><published>2012-09-25T10:07:00.000-07:00</published><updated>2012-10-22T13:30:32.584-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aprender java creando un juego"/><category scheme="http://www.blogger.com/atom/ns#" term="Greenfoot"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java Greenfoot"/><category scheme="http://www.blogger.com/atom/ns#" term="Java magazine"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Juegos"/><category scheme="http://www.blogger.com/atom/ns#" term="Juegos en java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><category scheme="http://www.blogger.com/atom/ns#" term="Video juegos"/><category scheme="http://www.blogger.com/atom/ns#" term="Video juegos Greenfoot"/><title type='text'>Aprender Java creando un juego (Parte 2)</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;


&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;Buen día a todos mis lectores, hoy, les tengo un tema muy
interesante, como ya habrán visto en las letras grandes de arriba, se trata de
cómo iniciar nuestro primer juego de computadora en Java en el entorno
Greenfoot, este articulo es la segunda parte de un proyecto de varias partes,
para ver la primera&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-1.html&quot; target=&quot;_blank&quot;&gt;click aquí&lt;/a&gt;&amp;nbsp;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;, les dejo la información...&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;Tener
un gráfico animado en pantalla en la primera parte es bastante bueno, pero se
pone aburrido después de un rato si no puedes hacer nada más con él, así que
hoy, te diré como añadir interacción con el teclado (eso es, cómo controlar el
movimiento de tu tortuga usando teclas), que quizá sea el primer paso en un
pequeño juego de computadora.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;Comenzando&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;Cuando dejamos el método &lt;b&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;act&lt;/span&gt;&lt;/b&gt; de nuestra tortuga la última
vez, se miraba así:&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
public void act() {
  move(4);
  turn(2);
 }

]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Observamos que esto causaba que la tortuga corriera en un círculo,
porque el método &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;act &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;es repetidamente ejecutado cuando el programa corre:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjtgTMO_zNkhzBYYGCGzrfPCALVscbYsXK3jpYewB2assc6Cj_8phIzkcu3UQit6E4sQpYNilbgnIiWZyyHQOuO0h6rw8OagS64FCRxFlX3M43grakPVxPst4ePFkIdRj1yrrvjlmyPICF/s1600/Imagen1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjtgTMO_zNkhzBYYGCGzrfPCALVscbYsXK3jpYewB2assc6Cj_8phIzkcu3UQit6E4sQpYNilbgnIiWZyyHQOuO0h6rw8OagS64FCRxFlX3M43grakPVxPst4ePFkIdRj1yrrvjlmyPICF/s320/Imagen1.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;Ahora,
queremos que cada tortuga vaya en línea recta cuando no presionamos nada en
nuestro teclado y que gire a la derecha o izquierda si presionamos las teclas
de dirección de derecha o izquierda.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;Para
lograr esto, necesitamos dos cosas:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12pt; text-indent: -18pt;&quot;&gt;Necesitamos poder revisar cuando una
tecla ha sido presionada.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12pt; text-indent: -18pt;&quot;&gt;Necesitamos tener una sentencia en
Java que nos permita ordenar que queremos girar la tortuga sólo si la tecla de
dirección derecha o izquierda ha sido presionada.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;b style=&quot;text-indent: -24px;&quot;&gt;&lt;span style=&quot;font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;Revisando si se ha presionado una
tecla&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%; text-indent: -24px;&quot;&gt;Greenfoot tiene un método, llamado &lt;/span&gt;&lt;b style=&quot;text-indent: -24px;&quot;&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;isKeyDown&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%; text-indent: -24px;&quot;&gt;,
que nos permite revisar cuando se ha presionado cierta tecla. Éste método está
en la clase &lt;/span&gt;&lt;b style=&quot;text-indent: -24px;&quot;&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;Greenfoot&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%; text-indent: -24px;&quot;&gt;. Podemos, por ejemplo, escribir lo siguiente para
revisar cuando la tecla de dirección izquierda está siendo presionada:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
Greenfoot.isKeyDown(&quot;left&quot;)
]]&gt;&lt;/script&gt;


&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;El parámetro (dentro del paréntesis) es el nombre de la tecla que
queremos revisar. Las teclas alfabéticas tienen el nombre de su carácter como
su nombre (por ejemplo, la tecla A es llamada &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;a&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;, la tecla B es llamada &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;b&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;, y así sucesivamente). Las teclas especiales de control tienen
nombres indicando lo que son; por ejemplo, &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;left&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt; (izquierda en español) es
el nombre de la tecla de dirección izquierda y—como habrás adivinado—&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;right&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt; (derecha en español) es el nombre de la tecla de dirección
derecha. El método &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;isKeyDown&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;, cuando se le llama, va a responder con un
valor ya sea &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;true &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;(verdadero, la tecla de dirección izquierda se
ha presionado) o &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;false &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;(falso, la tecla no está siendo presionada).&lt;/span&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12pt;&quot;&gt;Una Sentencia if&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;La segunda parte que necesitamos para hacer que
nuestro plan funcione es una sentencia que nos permita ejecutar una acción (en
nuestro caso, girar) sólo durante ciertas condiciones (cuando la tecla de
dirección derecha o izquierda es presionada). Esto es llamado una sentencia &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;. Una sentencia &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;if &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;tiene la siguiente forma general:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
if (condición) {
   sentencias;
   }
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Cuando una sentencia &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;if &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;es ejecutada, revisa la &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-NormalItalic;&quot;&gt;condición&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;, y entonces ejecuta solamente las &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-NormalItalic;&quot;&gt;sentencias&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt; que están entre sus llaves &lt;/span&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;{ }&lt;/span&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt; si la condición es &lt;i&gt;true&lt;/i&gt;.
(Incidentalmente, quizá sea bueno introducir una terminología más profesional:
La parte de la sentencia &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;if &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;que contiene las sentencias—sus llaves { } y
todo lo que esté entre ellas—se llama el &lt;i&gt;cuerpo&lt;/i&gt;
de la sentencia &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;.) El cuerpo quizá contenga una secuencia
completa de sentencias si eso es lo que queremos.&lt;/span&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Si la condición es &lt;i&gt;false&lt;/i&gt;,
el cuerpo es solo ignorado, y la ejecución continúa después de la sentencia &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;if &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;(y sus llaves).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-Bold;&quot;&gt;Girando la tortuga al presionar una tecla&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;Con estos dos puntos reunidos, ahora podemos hacer lo
que necesitamos. Necesitamos escribir lo siguiente:&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
if (la-tecla-left-está-siendo-presionada) {
  girar-un-poco-a-la-izquierda;
}
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;Este
no es código Java real (se llama pseudocódigo).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;Ahora podemos llenar el pseudocódigo con código Java
real:&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
if (Greenfoot.isKeyDown(&quot;left&quot;)) {
   turn(-3);
  }
]]&gt;&lt;/script&gt;


&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;Este código ahora
indica que vamos a girar menos 3 grados durante cada ciclo &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;act&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt; en el cual la tecla de dirección izquierda (&lt;i&gt;left&lt;/i&gt;) esté siendo presionada. (Noten que podemos usar un ángulo
negativo para girar a la derecha.)&lt;/span&gt;&lt;span style=&quot;font-size: 12.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;

&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;Haciendo lo mismo
para la tecla de dirección derecha (&lt;i&gt;right&lt;/i&gt;)
para girar a la derecha es ahora simple. Solamente escribimos una sentencia
similar nuevamente, pero esta vez girando 3 grados para la tecla de dirección
derecha. El nuevo método completo &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-bidi-font-family: NeueSansPro-SemiBold; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;act &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;se muestra a
continuación:&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
public void act() {
  move(4);

  if (Greenfoot.isKeyDown(&quot;left&quot;)) {
   turn(-3);
  }

  if (Greenfoot.isKeyDown(&quot;right&quot;)) {
   turn(3);
  }
 }
]]&gt;&lt;/script&gt;

&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12.0pt; line-height: 115%; mso-ansi-language: ES-MX; mso-bidi-font-family: NeueSansPro-Normal; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;Pruébalo. Compila tus
clases, pon una tortuga en el &lt;i&gt;mundo&lt;/i&gt;,
y corre el &lt;i&gt;scenario&lt;/i&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12pt;&quot;&gt;Ahora puedes controlar una tortuga en tu pantalla con las teclas
de dirección. ¡Bastante divertido hasta ahora!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Actualmente, la tortuga continuamente va a caminar hacia adelante.
Si tú quieres, puedes cambiar tu código para que la tortuga se mueva hacia
adelante sólo cuando presiones la tecla de dirección arriba. Podrías hacer eso
añadiendo otra sentencia &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;if &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;alrededor de la sentencia &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;move(4)&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;. El nombre de la tecla de dirección arriba es &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; font-size: 12.0pt; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;up&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12pt;&quot;&gt;Y bueno, eso es todo por esta entrada, pero no para el proyecto,
en la siguiente entrada veremos cómo darle algo que hacer a nuestra tortuga:
¡Comer! Espero hayan disfrutado este artículo y “nos vemos” en el siguiente,
saludos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12.0pt; line-height: 115%;&quot;&gt;Traducción: El Blog De Baro.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; font-size: 12.0pt; line-height: 115%;&quot;&gt;Escrito por: Michael Kölling.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 12.0pt; line-height: 115%;&quot;&gt;Fuente:&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.oracle.com/technetwork/java/javamagazine/index.html&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot; target=&quot;_blank&quot;&gt;Java Magazine&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-6.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 6)&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-5.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 5)&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-4.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 4)&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-3.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 3)&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-1.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 1)&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/3463565122397689987/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-2.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/3463565122397689987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/3463565122397689987'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-2.html' title='Aprender Java creando un juego (Parte 2)'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjtgTMO_zNkhzBYYGCGzrfPCALVscbYsXK3jpYewB2assc6Cj_8phIzkcu3UQit6E4sQpYNilbgnIiWZyyHQOuO0h6rw8OagS64FCRxFlX3M43grakPVxPst4ePFkIdRj1yrrvjlmyPICF/s72-c/Imagen1.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-3491593113761966112</id><published>2012-09-24T14:50:00.000-07:00</published><updated>2012-10-22T13:33:46.145-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aprender java creando un juego"/><category scheme="http://www.blogger.com/atom/ns#" term="Greenfoot"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java Greenfoot"/><category scheme="http://www.blogger.com/atom/ns#" term="Java magazine"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Juegos"/><category scheme="http://www.blogger.com/atom/ns#" term="Juegos en java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><category scheme="http://www.blogger.com/atom/ns#" term="Video juegos"/><category scheme="http://www.blogger.com/atom/ns#" term="Video juegos Greenfoot"/><title type='text'>Aprender Java creando un juego (Parte 1)</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;


&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Buen día a todos
mis lectores, hoy les tengo la primera parte (&lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/aprender-java-creando-un-juego-parte-2.html&quot; target=&quot;_blank&quot;&gt;Parte 2 aquí&lt;/a&gt;) de un interesante proyecto de varias
partes, se trata del inicio de un pequeño juego para computadora, lo mejor de
todo, es que está diseñado para aprender los conceptos básicos de la
programación orientada a objetos, así que si eres principiante en Java ¡Esto es
perfecto para ti! No se necesitan conocimientos avanzados del lenguaje ni de la
programación orientada a objetos (POO) en general, aquí les va...&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En este articulo,
vamos a saltar directos a comenzar nuestra propia clase. En el proceso, vamos a
aprender acerca de objetos, métodos y parámetros.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Prerrequisitos&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Para poder
continuar, necesitarás que el siguiente software esté instalado en tu
computadora:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Plataforma
Java (&lt;/span&gt;&lt;a href=&quot;http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html&quot; target=&quot;_blank&quot;&gt;Descargar&lt;/a&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;), Edición estándar (Java SE por sus siglas en inglés)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://www.greenfoot.org/about/&quot; target=&quot;_blank&quot;&gt;Greenfoot&lt;/a&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&amp;nbsp;versión 2.1.0 o una más nueva.
Asegúrate de que tengas una versión suficientemente buena de Greenfoot. Puedes
revisar la versión que tienes usando el artículo de menú &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;About Greenfoot&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Creando nuestro propio proyecto&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Greenfoot llama a
sus proyectos &lt;i&gt;scenarios&lt;/i&gt;. Así que la
primera cosa que haremos, es crear un nuevo &lt;i&gt;scenario&lt;/i&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Inicia
Greenfoot.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;Greenfoot
usualmente abre el último &lt;/span&gt;&lt;i style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;scenario&lt;/i&gt;&lt;span style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt; en
el que trabajaste. Ciérralo seleccionando la función&amp;nbsp;&lt;b&gt;C&lt;/b&gt;&lt;/span&gt;&lt;b style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;lose&lt;/b&gt;&lt;span style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt; del menú &lt;/span&gt;&lt;b style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;Scenario&lt;/b&gt;&lt;span style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;Selecciona
&lt;/span&gt;&lt;b style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;New&lt;/b&gt;&lt;span style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt; del menú &lt;/span&gt;&lt;b style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;Scenario&lt;/b&gt;&lt;span style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;En la
caja de dialogo &lt;i&gt;New Scenario&lt;/i&gt;, pon de
nombre &lt;/span&gt;&lt;b style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;turtle&lt;/span&gt;&lt;/b&gt;&lt;b style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;
&lt;/b&gt;&lt;span style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;al nuevo &lt;/span&gt;&lt;i style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;scenario&lt;/i&gt;&lt;span style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt; y da click en
&lt;/span&gt;&lt;b style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;OK&lt;/b&gt;&lt;span style=&quot;text-align: justify; text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Deberías ahora tener una nueva ventana &lt;i&gt;scenario&lt;/i&gt;
que es principalmente gris, como se muestra a continuación:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaU7h_RaSXUDDrTFFhthX1GBNhdFYBm4Q-6-7SW5N2pWe074A-YJnwN9hvKM3pKBLQny6hQL1eOUXhdvEnKxRYIjlKnsZ-L141N9y4y7toqkwcp9jSHPHm7ssvdd9j6egZ0xR7vGrNBlLY/s1600/Imagen1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;149&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaU7h_RaSXUDDrTFFhthX1GBNhdFYBm4Q-6-7SW5N2pWe074A-YJnwN9hvKM3pKBLQny6hQL1eOUXhdvEnKxRYIjlKnsZ-L141N9y4y7toqkwcp9jSHPHm7ssvdd9j6egZ0xR7vGrNBlLY/s320/Imagen1.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;text-align: center;&quot;&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shapetype
 id=&quot;_x0000_t75&quot; coordsize=&quot;21600,21600&quot; o:spt=&quot;75&quot; o:preferrelative=&quot;t&quot;
 path=&quot;m@4@5l@4@11@9@11@9@5xe&quot; filled=&quot;f&quot; stroked=&quot;f&quot;&gt;
 &lt;v:stroke joinstyle=&quot;miter&quot;/&gt;
 &lt;v:formulas&gt;
  &lt;v:f eqn=&quot;if lineDrawn pixelLineWidth 0&quot;/&gt;
  &lt;v:f eqn=&quot;sum @0 1 0&quot;/&gt;
  &lt;v:f eqn=&quot;sum 0 0 @1&quot;/&gt;
  &lt;v:f eqn=&quot;prod @2 1 2&quot;/&gt;
  &lt;v:f eqn=&quot;prod @3 21600 pixelWidth&quot;/&gt;
  &lt;v:f eqn=&quot;prod @3 21600 pixelHeight&quot;/&gt;
  &lt;v:f eqn=&quot;sum @0 0 1&quot;/&gt;
  &lt;v:f eqn=&quot;prod @6 1 2&quot;/&gt;
  &lt;v:f eqn=&quot;prod @7 21600 pixelWidth&quot;/&gt;
  &lt;v:f eqn=&quot;sum @8 21600 0&quot;/&gt;
  &lt;v:f eqn=&quot;prod @7 21600 pixelHeight&quot;/&gt;
  &lt;v:f eqn=&quot;sum @10 21600 0&quot;/&gt;
 &lt;/v:formulas&gt;
 &lt;v:path o:extrusionok=&quot;f&quot; gradientshapeok=&quot;t&quot; o:connecttype=&quot;rect&quot;/&gt;
 &lt;o:lock v:ext=&quot;edit&quot; aspectratio=&quot;t&quot;/&gt;
&lt;/v:shapetype&gt;&lt;v:shape id=&quot;_x0000_i1031&quot; type=&quot;#_x0000_t75&quot; style=&#39;width:441.75pt;
 height:207pt;visibility:visible;mso-wrap-style:square&#39;&gt;
 &lt;v:imagedata src=&quot;file:///D:\DOCUME~1\Gustavo\CONFIG~1\Temp\msohtmlclip1\01\clip_image001.emz&quot;
  o:title=&quot;&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora tenemos el
caparazón de un nuevo &lt;i&gt;scenario&lt;/i&gt;, un
lugar donde podemos empezar a trabajar. No tenemos un mundo aún para hacer que
cosas pasen en él, y no tenemos actores que puedan hacer cosas.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot;&gt;Las dos clases
que se ven en el lado derecho de la ventana, &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;World&lt;/span&gt;&lt;/b&gt; (Mundo en inglés) y &lt;b&gt;&lt;span style=&quot;color: #0066ff;&quot;&gt;Actor&lt;/span&gt;&lt;/b&gt;, son &lt;i&gt;superclases&lt;/i&gt;.
Ellas no son ni un mundo especifico ni un actor especifico, son mejor dicho
descripciones de todos los mundos y actores posibles.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Vamos a crear un mundo específico y actores creando &lt;i&gt;subclasses&lt;/i&gt; de éstas. Las subclases
representan especializaciones de las superclases. Vamos a comenzar haciendo un
mundo.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Creando
un nuevo mundo&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Da click derecho en la clase &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;World&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; (La caja
color beige) y selecciona la función &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;New Subclass&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Una caja de dialogo nos pide un nombre y una imagen
para la nueva clase como se muestra a continuación:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIQ60VMhsjE1jBaYASJkhEYw_a6Q9qUJM02XraHQsHJR-iWTk-s1i-MuduIGCoA_eZ_DwGOT17NRdHsaiaiKgGFO1KDD6FdQlbJajehqV7xCKIO6DlobykpDMmmEl-kN6Yff4-ynxkb90T/s1600/Imagen2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;256&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIQ60VMhsjE1jBaYASJkhEYw_a6Q9qUJM02XraHQsHJR-iWTk-s1i-MuduIGCoA_eZ_DwGOT17NRdHsaiaiKgGFO1KDD6FdQlbJajehqV7xCKIO6DlobykpDMmmEl-kN6Yff4-ynxkb90T/s320/Imagen2.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Nombra a tu clase &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff;&quot;&gt;TurtleWorld&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;, y selecciona una
imagen de la categoría &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;Backgrounds&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;
de la librería de imágenes. Para los pantallazos en este artículo, se
seleccionó una imagen de fondo llamada weave.jpg.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Da click en &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;OK&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; entonces
click en el botón &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;Compile&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; en la
ventana principal de Greenfoot. Deberías ver aparecer un mundo en la ventana
Greenfoot con tu fondo seleccionado como se ve a continuación:&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;text-align: center; text-indent: -18pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF2JGZn47L6MfmLRkLrN9yPJA8ZRzdYooHIwGHVCabr8XjkxRzGO1C6Ecj3EQoE9Fwopz_YHgYFjuzs7WGs_jKQ52hLTGQ9B0iN7p8RqFeeFTp0hUjMQRVB4tW7oDiAX3jugQbPdIKJyEC/s1600/Imagen3.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;144&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF2JGZn47L6MfmLRkLrN9yPJA8ZRzdYooHIwGHVCabr8XjkxRzGO1C6Ecj3EQoE9Fwopz_YHgYFjuzs7WGs_jKQ52hLTGQ9B0iN7p8RqFeeFTp0hUjMQRVB4tW7oDiAX3jugQbPdIKJyEC/s320/Imagen3.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;text-align: center; text-indent: -18pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;text-align: center; text-indent: -18pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;text-align: center;&quot;&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shape id=&quot;Imagen_x0020_3&quot; o:spid=&quot;_x0000_i1029&quot;
 type=&quot;#_x0000_t75&quot; style=&#39;width:441.75pt;height:198pt;visibility:visible;
 mso-wrap-style:square&#39;&gt;
 &lt;v:imagedata src=&quot;file:///D:\DOCUME~1\Gustavo\CONFIG~1\Temp\msohtmlclip1\01\clip_image005.emz&quot;
  o:title=&quot;&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora que hemos creado un mundo, estamos listos para
crear actores para ponerlos dentro del mundo.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Una
Nota Lateral Sobre Compilar&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Cuando programamos, escribimos código Java.
Desafortunadamente, las computadoras no pueden ejecutar el código Java
directamente. Necesitan sus instrucciones en un lenguaje de máquina
especializado. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Afortunadamente, hay una solución fácil: El
compilador. Un compilador es un software que puede trasladar código Java en
lenguaje máquina. Cada vez que creamos una nueva clase o haces cambios al
código fuente de una clase existente, la clase necesita ser trasladada
nuevamente a lenguaje máquina. Puedes hacer esto fácilmente dando click en el
botón &lt;b&gt;Compile&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En Greenfoot, una clase aparece a rayas si no ha
sido compilada desde el último cambio como se muestra a continuación:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFfW1ZpvlVYpY0-vc-qtLe-0N8z5GonYUZw46q9CXERRxp03WwZmV_MdKdIAjWtoFLdFUnYn3B4RQ_SAfnT6OLYbDTyZ-P524ibSzq2qbkqUWC2g4C6jcxgzadcTeEXfHO0yf0j5HcwDv-/s1600/Imagen4.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;196&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFfW1ZpvlVYpY0-vc-qtLe-0N8z5GonYUZw46q9CXERRxp03WwZmV_MdKdIAjWtoFLdFUnYn3B4RQ_SAfnT6OLYbDTyZ-P524ibSzq2qbkqUWC2g4C6jcxgzadcTeEXfHO0yf0j5HcwDv-/s320/Imagen4.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Una vez que damos click en el botón &lt;b&gt;Compile&lt;/b&gt; y
la clase es trasladada, las rayas desaparecen, y la clase está lista para usar:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCaykJXs4GjNpIiV8Q8VRhnrJ04twtyugeYKGg4oS0NjlukNF3imSPsKt0vfrGE91g-Wfl_ltI1-oeZZ9TM406vxn1r4UVeQ3NzxocbDsJ_kS4vKfh-jxc49KFHaGe0Ss2PD0ahP9x8Nn6/s1600/Imagen5.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;196&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCaykJXs4GjNpIiV8Q8VRhnrJ04twtyugeYKGg4oS0NjlukNF3imSPsKt0vfrGE91g-Wfl_ltI1-oeZZ9TM406vxn1r4UVeQ3NzxocbDsJ_kS4vKfh-jxc49KFHaGe0Ss2PD0ahP9x8Nn6/s320/Imagen5.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Creando
un actor&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora tenemos un mundo en el que nuestros actores
pueden vivir. De todas formas, no tenemos un actor para hacer nada aún. Así que
vamos a hacer un actor.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 7pt; text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 7pt; text-indent: -18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Click derecho en la clase &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;Actor&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; y selecciona
la función &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;New subclass&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 7pt; text-indent: -18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;En la caja de dialogo resultante, nombre la nueva
clase &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff;&quot;&gt;Turtle&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;, y selecciona la
imagen &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;turtle2.png&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; de la categoría &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;Animals&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; como se muestra en la imagen (bajo el punto 4).&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Click &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;OK&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&amp;nbsp;&lt;/span&gt;Ahora tenemos una nueva clase&lt;b&gt;&lt;span style=&quot;color: #0066ff;&quot;&gt; Turtle &lt;/span&gt;&lt;/b&gt;en nuestro &lt;i&gt;scenario&lt;/i&gt;.
Nota que esta clase está inicialmente rayada (eso significa, sin compilar).&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Click en el botón &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;Compile&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;
para compilar la clase.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoListParagraph&quot; style=&quot;mso-list: l5 level1 lfo5; text-indent: -18.0pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdx9BKBc-N168-TllizfFiWcvEIXm-O3E5TboLjnNjQALwve66E5WlLOkwSm0MMe1W2Z9FbK8bLoKyuLo62A5_YE2k05KHMeUt9qtAuKwuMYMnyyBbuv9Jph7Ni2vLcIhuDzblue7Tgc2s/s1600/Imagen6.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;290&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdx9BKBc-N168-TllizfFiWcvEIXm-O3E5TboLjnNjQALwve66E5WlLOkwSm0MMe1W2Z9FbK8bLoKyuLo62A5_YE2k05KHMeUt9qtAuKwuMYMnyyBbuv9Jph7Ni2vLcIhuDzblue7Tgc2s/s320/Imagen6.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Nota que por convención, los nombres de las clases Java siempre comienzan
con letra mayúscula.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Creando Objetos&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora tenemos una clase actor (&lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Turtle&lt;/span&gt;&lt;/b&gt;), pero no tenemos &lt;i&gt;objetos&lt;/i&gt; actor todavía. Click derecho en la clase &lt;b&gt;Turtle&lt;/b&gt; y selecciona &lt;b&gt;new Turtle()&lt;/b&gt;. Esto crea un objeto
tortuga—que es, un actor real—el cual se puede poner entonces en el mundo.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Eso es. Acabas de crear tu primera tortuga. Nota que se pueden
crear tantas tortugas como quieras. Haz la prueba.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Programando tus
objetos&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-indent: 0px;&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Click en el botón &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;Run&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&amp;nbsp;&lt;/span&gt;Notarás que nada pasa al presionar tal botón,
nuestra tortuga sólo se sienta ahí, sin hacer nada. Eso es porque no hemos
programado a nuestra tortuga para que haga algo. Así que aquí es donde la diversión
comienza. Vamos ahora a comenzar a programar en Java para hacer a la tortuga
actuar.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Abre el editor para &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Turtle &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;haciendo doble click en la caja de clase &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;Turtle&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;. Verás algo de código para la
clase &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;Turtle &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;como se muestra a continuación:&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Turtle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Turtle extends Actor {

 /**
  * Act - do whatever the Turtle wants to do. This method is called whenever
  * the &#39;Act&#39; or &#39;Run&#39; button gets pressed in the environment.
  */
 public void act() {
  // Add your action code here.
 }
}
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Nos vamos a concentrar en el método &lt;b&gt;act&lt;/b&gt;. Ésa es la parte
del código que se ve así:


&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
public void act() {
  // Add your action code here.
 }
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Esta parte del código especifica lo que la tortuga hace cuando actúa.
El código entre las llaves {&amp;nbsp; } es
ejecutado cada vez que la tortuga actúa. En este caso, todo lo que está escrito
aquí es lo siguiente:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-Normal;&quot;&gt;// Add your action code here.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;La doble barra al inicio de la línea marca esta línea como un
comentario. Es ignorado por el sistema Java y es sólo un recordatorio para el
programador humano. En otras palabras, este método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act&lt;/span&gt;&lt;/b&gt; no contiene código
alguno. Ése es el porqué de que nuestra tortuga no haga nada.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Vamos a cambiar eso.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Reemplazar el comentario con una instrucción de tal manera que
nuestro método &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; se mire así:&amp;nbsp;&lt;/span&gt;


&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
public void act() {
  move(2);
 }
]]&gt;&lt;/script&gt;


&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Compila, crea una nueva tortuga, y trata de dar click en el botón &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;Act&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; y en el botón &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;Run&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&amp;nbsp;&lt;/span&gt;
&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;Así que, ¿qué acabamos de hacer?&amp;nbsp;
&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;La instrucción &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;move(2);&lt;/span&gt;&lt;/b&gt; &amp;nbsp;le dice a la tortuga que se mueva 2 pixeles
adelante. La tortuga hace esto cada vez que actúa. Cuando das click en el botón
&lt;b&gt;Act&lt;/b&gt;, el método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act&lt;/span&gt;&lt;/b&gt; es ejecutado una
sola vez, así que la tortuga se mueve un poquito (2 pixeles) a la derecha.
Dando click al botón &lt;b&gt;Run&lt;/b&gt; se llama al
método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act&lt;/span&gt;&lt;/b&gt; una y otra vez (hasta que lo pauses otra vez), así que la tortuga
se sigue moviendo.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Experimenta con valores diferentes de 2. ¿Qué pasa cuando usamos
20 en lugar de 2?&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Trata con otra instrucción reemplazando la instrucción &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;move(2);&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; &amp;nbsp;con esta instrucción:&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l1 level1 lfo6; text-indent: -18.0pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
  turn(2);
]]&gt;&lt;/script&gt;


&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Recuerda:&lt;/b&gt; Cambia el código,
compila, crea una nueva tortuga, y entonces ejecuta (&lt;b&gt;Run&lt;/b&gt;). Experimenta con diferentes valores aquí también.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Métodos y Parámetros&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Así que, ¿qué acabamos de hacer?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hemos llamado (o invocado) a un método llamado &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;move&lt;/span&gt;&lt;/b&gt; y a un método
llamado &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;turn&lt;/span&gt;&lt;/b&gt;, y hemos pasado un parámetro, &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;2&lt;/span&gt;&lt;/b&gt;, para cada uno de ellos.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Un método es un poco del comportamiento que un objeto sabe ejecutar,
y todos los actores conocen los métodos &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;move&lt;/span&gt;&lt;/b&gt; y &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;turn &lt;/span&gt;&lt;/b&gt;(quiere decir que ellos saben cómo moverse y
girar).&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ambos métodos esperan un &lt;i&gt;parámetro&lt;/i&gt;,
el cual es un poco de información adicional que les dice exactamente qué tan
lejos moverse o qué tanto girar. Amos métodos esperan un numero como parámetro,
y nosotros suplimos ése número escribiéndolo entre paréntesis después del
nombre del método. Y cada instrucción en Java es finalizada con un punto y coma
(&lt;b&gt;;&lt;/b&gt;).&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Errores&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Quizá te hayas dado cuenta que necesitas escribir el código muy
precisamente. Teniendo siquiera un carácter mal hace que el programa completo
no trabaje. El compilador entonces reporta un mensaje de error, y necesitas
arreglar el código. Si no has visto un mensaje de error aún, trata ahora. Por
ejemplo, borra el punto y coma (&lt;b&gt;;&lt;/b&gt;)
después de tu instrucción y trata de compilar. Verás a lo que me refiero.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Secuencias de
instrucciones&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Puedes escribir múltiples instrucciones, tantas como quieras, en
el método &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act&lt;/span&gt;&lt;/b&gt;. De hecho, puedes escribir una tras otra:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
 public void act() {
  move(4);
  turn(2);
 }
]]&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Intenta esto. Además, pon varias tortugas en el mundo, y
experimenta con diferentes valores en los parámetros para los métodos &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;move&lt;/span&gt;&lt;/b&gt; y &lt;b&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;turn&lt;/span&gt;&lt;/b&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;text-align: center;&quot;&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shape id=&quot;Imagen_x0020_1&quot; o:spid=&quot;_x0000_i1025&quot;
 type=&quot;#_x0000_t75&quot; style=&#39;width:441.75pt;height:294pt;visibility:visible;
 mso-wrap-style:square&#39;&gt;
 &lt;v:imagedata src=&quot;file:///D:\DOCUME~1\Gustavo\CONFIG~1\Temp\msohtmlclip1\01\clip_image013.emz&quot;
  o:title=&quot;&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;text-align: center;&quot;&gt;
&lt;o:p&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWonddnGA2YZrbUPPvWPvjuRvc0s2DrpGTq44CIITGkajsQKU67hlIAXLI52JSazFnJgJsma5GCoxJYMAH4Tve85LXINUsmSYxzlLE13Ds0EElsgGl1RFqMiZtTqapPyjZ1RbbwdDu5fft/s1600/Imagen7.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;213&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWonddnGA2YZrbUPPvWPvjuRvc0s2DrpGTq44CIITGkajsQKU67hlIAXLI52JSazFnJgJsma5GCoxJYMAH4Tve85LXINUsmSYxzlLE13Ds0EElsgGl1RFqMiZtTqapPyjZ1RbbwdDu5fft/s320/Imagen7.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;text-align: center;&quot;&gt;
&lt;o:p&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;Resumen&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En este artículo, aprendimos los primeros pasos para escribir tu
propio código Java, que demuestran los siguientes principios:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Que el comportamiento de un objeto está especificado en la clase
del objeto.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Más precisamente, el comportamiento de un objeto está especificado
en una definición de método en la clase del objeto.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Las clases Actor en Greenfoot tienen un método llamado &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;act&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; que especifica su
comportamiento principal.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;El cuerpo del método (la parte entre las llaves { } ) contiene el
código que determina que hace el método cuando es llamado.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Las instrucciones pueden ser especificadas llamado a los métodos
existentes (como &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;move&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; y &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;color: #0066ff; mso-bidi-font-family: NeueSansPro-SemiBold;&quot;&gt;turn&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; en nuestro ejemplo).&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Las llamadas a los métodos consisten del nombre del método que estás
llamando seguido por parámetros en paréntesis.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Todas las instrucciones son terminadas con un punto y coma (&lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;;&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;).&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Podemos además escribir secuencias de instrucciones.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18.0pt;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Y bien, esto es todo para la primera parte de este interesante
proyecto, no tardo en subir las demás, cualquier duda, comentario, petición o
critica, en la parte de abajo, saludos.&amp;nbsp;&lt;/span&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Traducción por: El Blog De Baro.&lt;/span&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Escrito por: Michael Kölling.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Fuente:&amp;nbsp;&lt;a href=&quot;http://www.oracle.com/technetwork/java/javamagazine/index.html&quot; target=&quot;_blank&quot;&gt;Java Magazine&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-6.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 6)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/aprender-java-creando-un-juego-parte-5.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 5)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-4.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 4)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-3.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 3)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-2.html&quot; target=&quot;_blank&quot;&gt;Aprender Java creando un juego (Parte 2)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/3491593113761966112/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-1.html#comment-form' title='3 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/3491593113761966112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/3491593113761966112'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/09/aprender-java-creando-un-juego-parte-1.html' title='Aprender Java creando un juego (Parte 1)'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaU7h_RaSXUDDrTFFhthX1GBNhdFYBm4Q-6-7SW5N2pWe074A-YJnwN9hvKM3pKBLQny6hQL1eOUXhdvEnKxRYIjlKnsZ-L141N9y4y7toqkwcp9jSHPHm7ssvdd9j6egZ0xR7vGrNBlLY/s72-c/Imagen1.jpg" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-1854810282078127482</id><published>2012-09-18T11:18:00.001-07:00</published><updated>2012-10-22T13:37:01.127-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eclipse ide"/><category scheme="http://www.blogger.com/atom/ns#" term="instalar libreria"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><category scheme="http://www.blogger.com/atom/ns#" term="sql"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL y Java"/><category scheme="http://www.blogger.com/atom/ns#" term="sqlite"/><title type='text'>Cómo instalar SQLITE en Eclipse IDE</title><content type='html'>&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Hola y buen día a
todos mis lectores (Que no son muchos) hoy veremos cómo instalar la librería
de SQLITE para trabajar en Eclipse (y con Eclipse me refiero al entorno de
desarrollo, no a la película), pero primero veamos qué es SQLITE...&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span lang=&quot;ES&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhULRnYKzdeMlEYYRPf5PNazWgj67Yo55jIwnE9Uj4t6X9eLDbXbyjd92GYMOpHKfdPWb_RgajF7CLXCxDSI5uvoB4bilkcNKoFiM6Wvijb6_UID1ydQ4DKLraaQ1j7rsnd4GQtnB0-dZU2/s1600/SQLITE+Logo.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhULRnYKzdeMlEYYRPf5PNazWgj67Yo55jIwnE9Uj4t6X9eLDbXbyjd92GYMOpHKfdPWb_RgajF7CLXCxDSI5uvoB4bilkcNKoFiM6Wvijb6_UID1ydQ4DKLraaQ1j7rsnd4GQtnB0-dZU2/s1600/SQLITE+Logo.jpg&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp;SQLITE es una
librería que implementa un motor de base de datos SQL con varias ventajas, por
ejemplo, no es necesaria configuración o administración, es multiplataforma,
portable, no necesita servidor (Aunque puede usarse con PHP) y lo mejor: ¡Es de
dominio público! :D. Es utilizado en aplicaciones muy conocidas como por
ejemplo en el sistema operativo para dispositivos móviles Google Android, otro
ejemplo es el muy conocido antivirus Avast!, así que si ellos utilizan esta
librería ¿porqué nosotros no?.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCQW2H5VtBya8lix-dfcytsgZM5r_81fY32FRgXjAN2qcLN7lpat1VEda28coUgtNiE22q3JHMOODT7SpOfp5h6UqJ7MqypSGKiCvjr5qaoAWEDa67mZeD6AsSR8vCxieo-o4otpsSuz1Q/s1600/GoogleAndroidLogo.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCQW2H5VtBya8lix-dfcytsgZM5r_81fY32FRgXjAN2qcLN7lpat1VEda28coUgtNiE22q3JHMOODT7SpOfp5h6UqJ7MqypSGKiCvjr5qaoAWEDa67mZeD6AsSR8vCxieo-o4otpsSuz1Q/s320/GoogleAndroidLogo.jpg&quot; width=&quot;320&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: right;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2Vi7U7popc9ZQNQrZPL0yPDGzoOR2rfT546thCN_g4DZG85gDVPu9-OduFMXXlwth4ESABuzSnOqAl11fgT2X7IEuWUxCtF2c3zzr8NURZugYVrasirMzT0cvinLHk0nNPxjn96IzIW4g/s1600/avast_logo.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;120&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2Vi7U7popc9ZQNQrZPL0yPDGzoOR2rfT546thCN_g4DZG85gDVPu9-OduFMXXlwth4ESABuzSnOqAl11fgT2X7IEuWUxCtF2c3zzr8NURZugYVrasirMzT0cvinLHk0nNPxjn96IzIW4g/s320/avast_logo.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: right;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Otros
puntos a favor de SQLITE son: Que es extremadamente fácil de usar, que no hay
casi ninguna diferencia entre SQL, MySQL o SQLITE (&lt;a href=&quot;http://www.tutorialspoint.com/sql/sql_pdf_version.htm&quot; target=&quot;_blank&quot;&gt;Descargar tutorial SQL en PDF&lt;/a&gt;) ya que se basa en el estándar
SQL92 (Para ver características no soportadas por SQLITE &lt;a href=&quot;http://www.sqlite.org/omitted.html&quot; target=&quot;_blank&quot;&gt;click aquí&lt;/a&gt;) y
otro punto muy importante es que es más rápido que la mayoría de los motores de base de
datos Cliente/Servidor en las operaciones más comunes por lo tanto es ideal
para aplicaciones Java, grandes o pequeñas que requieran una base de datos.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora,
los pasos necesarios para instalar la librería en nuestro proyecto de Eclipse
IDE (&lt;a href=&quot;http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/R/eclipse-jee-juno-win32.zip&quot; target=&quot;_blank&quot;&gt;Descargar Eclipse IDE&lt;/a&gt;) y comenzar a trabajar con la misma:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Primero
que nada, obviamente necesitamos &lt;a href=&quot;http://code.google.com/p/sqlitebot/downloads/detail?name=sqlitejdbc-v056.jar&amp;amp;can=2&amp;amp;q=&quot; target=&quot;_blank&quot;&gt;descargar la librería de SQLITE&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ya en
nuestro proyecto, damos click secundario en donde dice JRE System Library[etc]
buscamos la opción Build path y luego Configure build path así como se muestra
en la imagen:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8kaSbNLAizMjaA0w0LzZsrSXQ6ZnNLsDNJ_F27N85_JcixJtuuBwXi2zxPx6PLE5TpVrttw-lGmhFBh9huIGoXshWaVmRc7DQwz5XWareGhnzjKZm5MCJlx-Rg3Al_ZfqX-kVKF1Yr9A6/s1600/Configurar+build+path.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;388&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8kaSbNLAizMjaA0w0LzZsrSXQ6ZnNLsDNJ_F27N85_JcixJtuuBwXi2zxPx6PLE5TpVrttw-lGmhFBh9huIGoXshWaVmRc7DQwz5XWareGhnzjKZm5MCJlx-Rg3Al_ZfqX-kVKF1Yr9A6/s400/Configurar+build+path.JPG&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Veremos
un dialogo como el que se muestra abajo y daremos click en el botón que está
rodeado en rojo “Add external jars”:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpJdKDWZKVON8E5gE_4r-H2NRzm1_1aQgitYZNjC4bqbBUNqIIywVFyKyTEF3SNQTU2Uh0lxF_p5FHinVn0zXa2b2YMWMH4Mx_CGzhzTNvsAXYYDskI-cBk0hWkKAiYKYIwp-pez9EQOUA/s1600/Propiedades+proyecto+JPG.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;325&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpJdKDWZKVON8E5gE_4r-H2NRzm1_1aQgitYZNjC4bqbBUNqIIywVFyKyTEF3SNQTU2Uh0lxF_p5FHinVn0zXa2b2YMWMH4Mx_CGzhzTNvsAXYYDskI-cBk0hWkKAiYKYIwp-pez9EQOUA/s400/Propiedades+proyecto+JPG.JPG&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Seleccionamos
la carpeta donde tenemos nuestra librería y damos click en “Abrir” o doble click como se
muestra a continuación:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiztA7hTtmmqCVoC-1tLiSQIw9PagtYTGINtQOBEowfIdtjPN3TOqlJod1XYShEf5oA_A_cZZ7Wr-0nUSOvsvuQVt8HQ1KohumyCdNXR2npacyl7_uzE_BzcrFQ9GBdqJEz19uClR_Ez1OE/s1600/Seleccionando+jar.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;325&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiztA7hTtmmqCVoC-1tLiSQIw9PagtYTGINtQOBEowfIdtjPN3TOqlJod1XYShEf5oA_A_cZZ7Wr-0nUSOvsvuQVt8HQ1KohumyCdNXR2npacyl7_uzE_BzcrFQ9GBdqJEz19uClR_Ez1OE/s400/Seleccionando+jar.JPG&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;¡Y listo! Si todo
salió bien, veremos en nuestro proyecto el archivo .jar que acabamos de agregar
como se muestra en la imagen:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg08GWQB5oMplhBtqGmJMkn0bpLLcuRqY6Yar0ogu1hY-LRkxLEd8K-Qs7Rr51_TfPgRu18oM0Nb3YF-yZ7iBa_OvpkPCrXq8Kc-2nDUQ3vbc6hylbPLI6i7ZSNvg_brHDHx9PgTHmpXMB3/s1600/Jar+agregado.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg08GWQB5oMplhBtqGmJMkn0bpLLcuRqY6Yar0ogu1hY-LRkxLEd8K-Qs7Rr51_TfPgRu18oM0Nb3YF-yZ7iBa_OvpkPCrXq8Kc-2nDUQ3vbc6hylbPLI6i7ZSNvg_brHDHx9PgTHmpXMB3/s1600/Jar+agregado.JPG&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;En mi
próxima entrada veremos (Ahora sí) cómo trabajar con esta librería en Java e
incluso dar la opción al usuario de donde guardar el archivo de base de datos,
como siempre, espero que hayan disfrutado la entrada, no duden en poner
comentarios, criticas o dudas abajo, saludos.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;line-height: 115%;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Georgia, Times New Roman, serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/utilizando-sqlite-en-java.html&quot; target=&quot;_blank&quot;&gt;Utilizando SQLITE en Java&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span lang=&quot;ES&quot; style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/1854810282078127482/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/09/como-instalar-sqlite-en-eclipse-ide.html#comment-form' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/1854810282078127482'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/1854810282078127482'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/09/como-instalar-sqlite-en-eclipse-ide.html' title='Cómo instalar SQLITE en Eclipse IDE'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhULRnYKzdeMlEYYRPf5PNazWgj67Yo55jIwnE9Uj4t6X9eLDbXbyjd92GYMOpHKfdPWb_RgajF7CLXCxDSI5uvoB4bilkcNKoFiM6Wvijb6_UID1ydQ4DKLraaQ1j7rsnd4GQtnB0-dZU2/s72-c/SQLITE+Logo.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-9180707011882989191</id><published>2012-09-12T10:24:00.000-07:00</published><updated>2012-10-22T13:40:30.716-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Archivo de texto en java"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse ide"/><category scheme="http://www.blogger.com/atom/ns#" term="Entradas y Salidas"/><category scheme="http://www.blogger.com/atom/ns#" term="I/O"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java poo"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Principiantes java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><title type='text'>Escribir un archivo de texto en Java</title><content type='html'>&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;link href=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; 
&lt;script language=&quot;javascript&quot;&gt; 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;



&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;img src=&quot;http://www.blogelectronica.com/wp-content/uploads/2008/07/programacion-java-siemens.gif&quot; /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Las entradas y salidas en Java pueden llegar a ser algo confuso para programadores que vienen de otros lenguajes como Visual Basic, C++, etc. También claro para quienes comienzan a aprender de este tema en Java, pero en realidad llega a ser algo muy sencillo de utilizar cuando lo aprendemos de la manera correcta, veremos una introducción al tema de Entradas y Salidas (I/O) en otro artículo, pero ahora sólo voy a escribir a cerca de como crear un simple archivo de texto en Java (Para aprender como leer archivos de texto en Java &lt;a href=&quot;http://baro3495.blogspot.mx/2012/09/escribir-un-archivo-de-texto-en-java.html&quot; target=&quot;_blank&quot;&gt;click aquí&lt;/a&gt;), ahí vamos...&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Digamos que quiero crear un archivo de nombre &quot;nota.txt&quot; con el texto &quot;Hola mundo&quot; dentro:&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;

&lt;br /&gt;

&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
public class EscritorNota {

 public static void escribirNota() throws IOException{

 //Primero creamos el atributo &quot;carpeta&quot; que tendrá como dirección la carpeta de inicio del usuario (user.home) donde pondremos el archivo de texto
 File carpeta = new File(System.getProperty(&quot;user.home&quot;)); 
 //En mi caso user.home = &quot;C:\Documents and Settings\Gustavo&quot; pero varía dependiendo de cada sistema operativo.

 //Para ver en la consola a donde va nuestra nota:
 System.out.println(System.getProperty(&quot;user.home&quot;));

 //Ahora le damos un nombre al archivo de la nota:
 String nombreArchivo = &quot;nota.txt&quot;;

 //Ahora para combinar el nombre del archivo y la carpeta hacemos lo siguiente:
 File archivo = new File(carpeta, nombreArchivo);

 String texto = &quot;Hola mundo&quot;; //El texto que va dentro del archivo.

 FileWriter fw = new FileWriter(archivo); //Instanciamos el escritor de archivo.

 fw.write(texto); //Escribimos el texto en el archivo.

 //Nota: Es muy importante limpiar y cerrar siempre el escritor de archivo al finalizar la escritura con los métodos &quot;flush()&quot; y &quot;close()&quot;.

 fw.flush();
 fw.close();
 }

 public static void main(String[] args) {
  try {
   escribirNota();
  }
  catch (IOException e) {
  e.printStackTrace();
  }//Fin del bloque try/catch
 }//Fin del main()
}//Fin de la clase
]]&gt;&lt;/script&gt;


Otra cosa muy importante es que después de llamar al método &lt;i&gt;close()&lt;/i&gt; no tratemos de escribir en el archivo con el método &lt;i&gt;write()&lt;/i&gt;&amp;nbsp;ya que esto va a generar una&amp;nbsp;excepción, aunque yo recomendaría no usar nuevamente el escritor de archivo una vez llamado al método &lt;i&gt;close()&lt;/i&gt; para nada más ya que puede tener resultados inesperados.
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Ahora, si vamos a la carpeta que nos devolvió &lt;i&gt;user.home&lt;/i&gt; (en mi caso)&amp;nbsp;&lt;i&gt;&quot;&lt;/i&gt;&lt;i&gt;C:\Documents and Settings\Gustavo&lt;/i&gt;&lt;i&gt;&quot;&lt;/i&gt; encontraremos un archivo llamado &lt;i&gt;nota.txt&lt;/i&gt;&amp;nbsp;y al abrirlo encontraremos el texto: &lt;i&gt;&quot;Hola mundo&quot;&lt;/i&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;Espero hayan disfrutado de esta entrada, cualquier duda, comentario o critica pueden ponerlo abajo y con gusto les daré respuesta, saludos.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;Entradas Relacionadas:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/leer-un-archivo-de-texto-en-java.html&quot; target=&quot;_blank&quot;&gt;Leer un archivo de texto en Java&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;a href=&quot;http://baro3495.blogspot.com/2012/10/entradas-y-salidas-lo-basico.html&quot; target=&quot;_blank&quot;&gt;Entradas y Salidas en Java - Lo básico&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/9180707011882989191/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/09/escribir-un-archivo-de-texto-en-java.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/9180707011882989191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/9180707011882989191'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/09/escribir-un-archivo-de-texto-en-java.html' title='Escribir un archivo de texto en Java'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6022595936443891655.post-2224108657717464995</id><published>2012-09-12T08:17:00.000-07:00</published><updated>2012-09-12T11:53:08.494-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="bienvenida"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse ide"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="Programación"/><title type='text'>Bienvenida</title><content type='html'>&lt;h2 style=&quot;text-align: center;&quot;&gt;
¡Bienvenido al blog de Baro!&lt;/h2&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s1600/JavaBlack.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;213&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s320/JavaBlack.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Éste blog está dedicado a las personas interesadas en aprender programación orientada a objetos (POO) en lenguaje &lt;b&gt;Java SE&lt;/b&gt;, utilizando el entorno de desarrollo (IDE) Eclipse y algunas librerías interesantes, veremos algunos ejemplos de entradas y salidas (I/O), conexión a base de datos, etc. Para la programación de interfaces gráficas (GUI&#39;s) &lt;b&gt;no se utilizarán plugins&lt;/b&gt; ya que a mi criterio, es mucho mejor saber como hacerlo &quot;a mano&quot; antes de utilizar herramientas para ello, espero que mi blog sea de su agrado, no olviden compartir las entradas que les gusten, saludos.&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://baro3495.blogspot.com/feeds/2224108657717464995/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://baro3495.blogspot.com/2012/09/bienvenida.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/2224108657717464995'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6022595936443891655/posts/default/2224108657717464995'/><link rel='alternate' type='text/html' href='http://baro3495.blogspot.com/2012/09/bienvenida.html' title='Bienvenida'/><author><name>Baro</name><uri>http://www.blogger.com/profile/01773303224282020277</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOG11Viu-01cf2AmIznYKXJTt46sdvhwhmsHGH2DLIDi9suruM93u9GA19be01MyMKbygnLBQtOIcC4oSmZP-0h5rAsbWR2_BsIFXcAbhPtOCo1ci_XhHPeEprB3RIAohV1lih7vlQy6X/s72-c/JavaBlack.jpg" height="72" width="72"/><thr:total>0</thr:total></entry></feed>