{"id":1611,"date":"2016-05-24T13:54:00","date_gmt":"2016-05-24T18:54:00","guid":{"rendered":"http:\/\/linuxitos.com\/main\/algunos-tips-al-programar-en-java\/"},"modified":"2016-05-24T13:54:00","modified_gmt":"2016-05-24T18:54:00","slug":"algunos-tips-al-programar-en-java","status":"publish","type":"post","link":"https:\/\/linuxitos.com\/main\/algunos-tips-al-programar-en-java\/","title":{"rendered":"Algunos TIPS al programar en JAVA"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/2.bp.blogspot.com\/-Wv2mUD2St0g\/V0SSPpfuQPI\/AAAAAAAACKU\/byBMPLbPNH4VHNwHhmgFZzdLunDX3SpIwCLcB\/s1600\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B12-40-05.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" height=\"358\" src=\"https:\/\/2.bp.blogspot.com\/-Wv2mUD2St0g\/V0SSPpfuQPI\/AAAAAAAACKU\/byBMPLbPNH4VHNwHhmgFZzdLunDX3SpIwCLcB\/s640\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B12-40-05.png\" width=\"640\" \/><\/a><\/div>\n<p><\/p>\n<div style=\"text-align: justify;\">Entiendo que como programadores o desarrolladores, tenemos ya nuestra pila de \u00abTrucos y Tips\u00bb a la hora de programar, as\u00ed como tambi\u00e9n solucionar o encontrar los \u00abErrores\u00bb, los catch, que no contemplamos o que simplemente no sab\u00edamos que ocurri\u00e1n.<\/div>\n<p><\/p>\n<div style=\"text-align: justify;\">Como ya mencion\u00e9, cada quien crea sus propios trucos con base a sus experiencias, pero no est\u00e1 de m\u00e1s saber trucos de alguien m\u00e1s:<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Les presentar\u00e9 una serie de trucos y m\u00e9todos que son los m\u00e1s usuales que siempre se requieren a la hora de programar en JAVA.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<h3 style=\"text-align: justify;\">1.- Siempre crear el paquete main o principal el cual inicie todo el programa<\/h3>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/2.bp.blogspot.com\/-5Zs6tlwbwZo\/V0Sd1JokZrI\/AAAAAAAACLg\/lyNTaQmG7CA0dbtYgCh39jJsaT7vq3TtACLcB\/s1600\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B13-29-18.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" height=\"400\" src=\"https:\/\/2.bp.blogspot.com\/-5Zs6tlwbwZo\/V0Sd1JokZrI\/AAAAAAAACLg\/lyNTaQmG7CA0dbtYgCh39jJsaT7vq3TtACLcB\/s400\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B13-29-18.png\" width=\"273\" \/><\/a><\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Desde mi punto de vista, \u00e9ste es el tip m\u00e1s importante, adem\u00e1s, de que es esencial en caso de querer crear el Jar al final. Como sabran, para poder crear un Jar, es necesario que solo exista un main en todo el software, por lo tanto al programar, crear una estructura parecida a la imagen de arriba.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">La clase principal donde est\u00e1 el \u00fanico main de todo el software, yo siempre la coloco en un paquete separado a todas las dem\u00e1s, tambi\u00e9n separo las clases de las interfaces gr\u00e1ficas, de los recursos, y de las im\u00e1genes.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">De este modo es mucho m\u00e1s f\u00e1cil el desarrollo, desde mi punto de vista claro.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Entonces, mi clase&nbsp; principal donde est\u00e1 el \u00fanico main, lo \u00fanico que har\u00e1 es crear y visualizar la primera interfaz Gr\u00e1fica (JFrame), de todo el software, y de ah\u00ed parte todo lo dem\u00e1s.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Ejemplo de mi c\u00f3digo en la clase principal donde contiene el main:<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<pre style=\"background: url(&quot;assets\/shadow.png&quot;) 50% 100% repeat-x rgb(245, 245, 245); border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 3px; box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; font-stretch: normal; line-height: 1.42857; margin-bottom: 10px; overflow: auto; padding: 9.5px; tab-size: 4; text-shadow: rgb(255, 255, 255) 0px 1px 0px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;\">[...]<br \/>\/*<br \/> * Nombre de la clase: Principal<br \/> * Descripci\u00f3n: esta clases es la principal, desde aqu\u00ed se invocan a las dem\u00e1s<br \/> *  interfaces para que inicie el programa completo.<br \/> *\/<br \/>package gestionbasedatos;<br \/><br \/>import gestionbasedatos.interfaces.LoginBD;<br \/>import gestionbasedatos.interfaces.SplashScreen;<br \/>import java.util.logging.Level;<br \/>import java.util.logging.Logger;<br \/>import javax.swing.SwingUtilities;<br \/>import javax.swing.UIManager;<br \/>import javax.swing.UnsupportedLookAndFeelException;<br \/><br \/>\/**<br \/> *<br \/> * @author m2 &lt;linuxitos@gmail.com&gt;<br \/> *\/<br \/>public class Principal {<br \/><br \/>    \/**<br \/>     * @param args the command line arguments<br \/>     *\/<br \/>    public static void main(String[] args) {<br \/>        try{<br \/>            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());<br \/>        }catch(ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e){<br \/>            System.err.println(\"Error Look GUI: \"+e.getMessage());<br \/>        }<br \/>        SplashScreen s=new SplashScreen();<br \/>        s.setVisible(true);<br \/>        try {<br \/>            Thread.sleep(10000);<br \/>        } catch (InterruptedException ex) {<br \/>            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);<br \/>        }<br \/>        s.dispose();<br \/>        SwingUtilities.invokeLater(new Runnable(){<br \/>            @Override<br \/>            public void run(){<br \/>                \/*Aqu\u00ed crean el objeto hac\u00eda su aplicaci\u00f3n, para hacer visible*\/<br \/>                LoginBD nuevaSesion = new LoginBD();<br \/>                nuevaSesion.setVisible(true);<br \/>            }<br \/>        });        <br \/>    }<br \/>    <br \/>}<br \/>[...]<\/pre>\n<h3 style=\"text-align: justify;\">2.-&nbsp; Agregar javadoc a todos los m\u00e9todos y clases<\/h3>\n<div style=\"text-align: justify;\">Esto no creo que sea solo un tip, sino una oligaci\u00f3n de todo desarrollador;<\/div>\n<div style=\"text-align: justify;\">En Java es sencillo, solo basta posicionarse sobre el m\u00e9todo, presionar la tecla Alt+Enter y lo agrega autom\u00e1ticamente:<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Ejemplo:<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<pre style=\"background: url(&quot;assets\/shadow.png&quot;) 50% 100% repeat-x rgb(245, 245, 245); border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 3px; box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; font-stretch: normal; line-height: 1.42857; margin-bottom: 10px; overflow: auto; padding: 9.5px; tab-size: 4; text-shadow: rgb(255, 255, 255) 0px 1px 0px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;\">[...]<br \/>\/**<br \/>     * M\u00e9todo que devuelve el valor de un campo esp\u00e9ficico que se le indique lo retorna como string<br \/>     * si la consulta cuenta con muchas filas, se quedar\u00e1 con el \u00faltimo valor<br \/>     * @param rel<br \/>     * @param campo<br \/>     * @return String<br \/>     * @throw SQLException.<br \/>    *\/<br \/>    public String obtenerCampo(ResultSet rel, String campo){<br \/>       String valCampo =new String();<br \/>       try{<br \/>            while(rel.next()){ <br \/>                valCampo=rel.getString(campo);<br \/>            }<br \/>        } catch (SQLException ex) {<br \/>            System.out.println(\"Error: \"+ex.getMessage());<br \/>        }<br \/>        return valCampo;<br \/>    }<br \/>[...]<\/pre>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Si no quieren, escribir toda la documentaci\u00f3n o comentarios en un momento dado, entonces, solo agreguen lo m\u00e1s importante y despu\u00e9s la terminan.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Documentar su c\u00f3digo no solo los ayudar\u00e1 a ustedes cuando no se acuerden qu\u00e9 hace cada uno de los mil m\u00e9todo que tienen en su c\u00f3digo, sino que tambi\u00e9n ayudar\u00e1 a otros en caso de que desarronen en grupos.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Tambi\u00e9n debo decir, que su c\u00f3digo se ver\u00e1 m\u00e1s profesional, esto es de cada quien, pero es una excelente pr\u00e1tica hacerlo. <\/div>\n<h3 style=\"text-align: justify;\">3.- Evitar cerrar todo el&nbsp; PROGRAMA al dar CLIC en la opci\u00f3n Cerrar de la Vetana:<\/h3>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/1.bp.blogspot.com\/-v_PSSzOySbI\/V0SUTeTteLI\/AAAAAAAACKg\/nvfozqQTVaAQFsvgezHGe-2gQHT2RuPVgCLcB\/s1600\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B12-48-44.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" border=\"0\" src=\"https:\/\/1.bp.blogspot.com\/-v_PSSzOySbI\/V0SUTeTteLI\/AAAAAAAACKg\/nvfozqQTVaAQFsvgezHGe-2gQHT2RuPVgCLcB\/s1600\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B12-48-44.png\" \/><\/a><\/div>\n<div style=\"text-align: justify;\">Quizas no en todos los programas se requiera inahabilitar esta opci\u00f3n, pero algunos casos es importante preguntar al usuario si realmente desea cerrar o si simplemente no cerrar el programa sino que te regrese a otra ventana.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Para esto, yo utilizo el siguiente c\u00f3digo:<\/div>\n<div style=\"text-align: justify;\"><\/p>\n<pre style=\"background: url(&quot;assets\/shadow.png&quot;) 50% 100% repeat-x rgb(245, 245, 245); border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 3px; box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; font-stretch: normal; line-height: 1.42857; margin-bottom: 10px; overflow: auto; padding: 9.5px; tab-size: 4; text-shadow: rgb(255, 255, 255) 0px 1px 0px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;\"><span style=\"color: #7f6000;\">\/\/Se inhabilita que al presionar el bot\u00f3n cerar de la ventana salga del programa<\/span><br \/>setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);<br \/><span style=\"color: #7f6000;\">\/\/Se agrega de Listener para que \u00e9ste detecte cuando se presione el bot\u00f3n <br \/>\/\/cerrar y ejecute otra accion, por ejemplo hacer visible una ventana anterior.<\/span><br \/>addWindowListener(new java.awt.event.WindowAdapter() {<br \/>    @Override<br \/>    public void windowClosing(java.awt.event.WindowEvent evt) {<br \/>        <span style=\"color: #7f6000;\">\/\/Acci\u00f3n a realizar contrario a salirse del programa<\/span><br \/>    }<br \/>});<\/pre>\n<\/div>\n<h3 style=\"text-align: justify;\">4.- Crear m\u00e9todos para reutilizaci\u00f3n<\/h3>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/2.bp.blogspot.com\/-Tyct4PejWfU\/V0SWU2XzvtI\/AAAAAAAACKs\/LqTxf-D0cioFMeaP5Oc0JsWVSp9myVHCwCLcB\/s1600\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B12-57-27.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" border=\"0\" src=\"https:\/\/2.bp.blogspot.com\/-Tyct4PejWfU\/V0SWU2XzvtI\/AAAAAAAACKs\/LqTxf-D0cioFMeaP5Oc0JsWVSp9myVHCwCLcB\/s1600\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B12-57-27.png\" \/><\/a><\/div>\n<p><\/p>\n<div style=\"text-align: justify;\">La idea es la siguiente: Supongamos que en el ejemplo anterior, se requiere regresar a una ventana anterior al presionar el bot\u00f3n cerrar de la ventana, pero tambi\u00e9n, hay que actualizar la informaci\u00f3n que se haya capturado en la ventana actual antes de cerrar. Adem\u00e1s, tenemos un bot\u00f3n de \u00abCerrar\u00bb, entonces, el c\u00f3digo que se ejecutar\u00e1 en bot\u00f3n cerrar de la ventana, tambi\u00e9n se utilizar\u00e1 en el bot\u00f3n cerrar que agregamos nosotros, por ente, para no duplicar el mismo c\u00f3digo, crear un m\u00e9todo, y solo se invocar\u00eda el m\u00e9todo en ambas opciones:<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Ejemplo:<\/div>\n<p><\/p>\n<pre style=\"background: url(&quot;assets\/shadow.png&quot;) 50% 100% repeat-x rgb(245, 245, 245); border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 3px; box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; font-stretch: normal; line-height: 1.42857; margin-bottom: 10px; overflow: auto; padding: 9.5px; tab-size: 4; text-shadow: rgb(255, 255, 255) 0px 1px 0px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;\">[...]<br \/>\/\/M\u00e9todo creado<br \/>private void close(){<br \/>    consultas.cargarPacientesTablas(jtableInfoActFisica);<br \/>    consultas.actualizarDatosGenerales();<br \/>    regAModiExp.setVisible(true);<br \/>    this.dispose()<br \/>}<br \/>[...]<\/pre>\n<pre style=\"background: url(&quot;assets\/shadow.png&quot;) 50% 100% repeat-x rgb(245, 245, 245); border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 3px; box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; font-stretch: normal; line-height: 1.42857; margin-bottom: 10px; overflow: auto; padding: 9.5px; tab-size: 4; text-shadow: rgb(255, 255, 255) 0px 1px 0px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;\">[...]<br \/>\/\/Cuando se detecte clic en el bot\u00f3n de cerar ventana quedar\u00eda as\u00ed<br \/>setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);<span style=\"color: #7f6000;\"><\/span><br \/>addWindowListener(new java.awt.event.WindowAdapter() {<br \/>    @Override<br \/>    public void windowClosing(java.awt.event.WindowEvent evt) {<br \/>       close();<span style=\"color: #7f6000;\"><\/span><br \/>    }<br \/>});<br \/>[...]<\/pre>\n<p>Y cuando se de clic en el bot\u00f3n cerrar que se agreg\u00f3 en la ventana quedar\u00eda a\u015bi:<\/p>\n<pre style=\"background: url(&quot;assets\/shadow.png&quot;) 50% 100% repeat-x rgb(245, 245, 245); border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 3px; box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; font-stretch: normal; line-height: 1.42857; margin-bottom: 10px; overflow: auto; padding: 9.5px; tab-size: 4; text-shadow: rgb(255, 255, 255) 0px 1px 0px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;\">[...]<br \/>private void jbCerarActionPerformed(java.awt.event.ActionEvent evt) {<br \/>   close();<br \/>}<br \/>[...]<\/pre>\n<p>Y con eso se dismiyen las l\u00edneas de c\u00f3digo, y se hace uso de la Reutilizaci\u00f3n.<\/p>\n<h3 style=\"text-align: justify;\">5.- Centrar todas las ventanas al iniciar el programa:<\/h3>\n<p><\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/1.bp.blogspot.com\/-0MUa9oCKtVk\/V0SZaczFGRI\/AAAAAAAACK4\/Zs07fDOkFNs9tec4Vwrh9YUPOIjwyIs6wCLcB\/s1600\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B13-10-25.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" height=\"179\" src=\"https:\/\/1.bp.blogspot.com\/-0MUa9oCKtVk\/V0SZaczFGRI\/AAAAAAAACK4\/Zs07fDOkFNs9tec4Vwrh9YUPOIjwyIs6wCLcB\/s320\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B13-10-25.png\" width=\"320\" \/><\/a><\/div>\n<p><\/p>\n<div style=\"text-align: justify;\">Para lograr que las ventanas de todo nuestro Software a desarrollar se centre autom\u00e1ticamente, es necesario agregar lo siguiente: <\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\"><\/p>\n<pre style=\"background: url(&quot;assets\/shadow.png&quot;) 50% 100% repeat-x rgb(245, 245, 245); border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 3px; box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; font-stretch: normal; line-height: 1.42857; margin-bottom: 10px; overflow: auto; padding: 9.5px; tab-size: 4; text-shadow: rgb(255, 255, 255) 0px 1px 0px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;\">[...]<br \/>initComponents();<br \/>setLocationRelativeTo(null); \/\/esto hace que se centre de manera utom\u00e1tica<br \/>[...]<\/pre>\n<\/div>\n<div style=\"text-align: justify;\">Es necesario agregarlo a cada JFrame que se cree. El orden tambi\u00e9n es necesario, ya que si no lo hacen en ese orden, les lanzar\u00e1 una excepci\u00f3n.<\/div>\n<p><\/p>\n<h3 style=\"text-align: justify;\">6.- Agregar \u00edcono a nuestro Software<\/h3>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/1.bp.blogspot.com\/-q218N9GwhVI\/V0Sa03NBomI\/AAAAAAAACLI\/aBqq3tbROv0GlwuAogU1yrfuQXzg5yoOQCLcB\/s1600\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B13-16-23.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" height=\"224\" src=\"https:\/\/1.bp.blogspot.com\/-q218N9GwhVI\/V0Sa03NBomI\/AAAAAAAACLI\/aBqq3tbROv0GlwuAogU1yrfuQXzg5yoOQCLcB\/s400\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B13-16-23.png\" width=\"400\" \/><\/a><\/div>\n<p><\/p>\n<div style=\"text-align: justify;\">Muchos podr\u00e1n decir que no es necesario, pero la personalizaci\u00f3n de un Software es lo que lo hace ser m\u00e1s llamativo, as\u00ed que, para agregar el \u00edcono yo utilizo el siguiente c\u00f3digo:<\/div>\n<pre style=\"background: url(&quot;assets\/shadow.png&quot;) 50% 100% repeat-x rgb(245, 245, 245); border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 3px; box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; font-stretch: normal; line-height: 1.42857; margin-bottom: 10px; overflow: auto; padding: 9.5px; tab-size: 4; text-shadow: rgb(255, 255, 255) 0px 1px 0px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;\">[...]<br \/>initComponents();<br \/>\/*Tiene que ser despu\u00e9s de initiComponents*\/<br \/>Image icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource(\"..\/images\/favicon.png\"));<br \/>setIconImage(icon);<br \/>[...]<\/pre>\n<p><\/p>\n<div style=\"text-align: justify;\">Obviamente es necesario crear el \u00edcono previamente, guardarlo dentro del proyecto, y agregarlo a cada JFrame que se cree.<\/div>\n<p><\/p>\n<h3 style=\"text-align: justify;\">7.- Agregar \u00edcono a nuestro Software<\/h3>\n<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin-left: auto; margin-right: auto; text-align: center;\">\n<tbody>\n<tr>\n<td style=\"text-align: center;\"><a href=\"https:\/\/3.bp.blogspot.com\/-IOsvJgayOVo\/V0ScgmutSQI\/AAAAAAAACLU\/liWgPuqSIUwzSeIaJJxuJ8Z9jMMxRjnYACLcB\/s1600\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B13-23-48.png\" style=\"margin-left: auto; margin-right: auto;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" height=\"193\" src=\"https:\/\/3.bp.blogspot.com\/-IOsvJgayOVo\/V0ScgmutSQI\/AAAAAAAACLU\/liWgPuqSIUwzSeIaJJxuJ8Z9jMMxRjnYACLcB\/s640\/Captura%2Bde%2Bpantalla%2Bde%2B2016-05-24%2B13-23-48.png\" width=\"640\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">Izquierda utilizando el tema default de Java, Derecha adaptado al tema del SO.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Hacer que la interfaz se adapte al estilo de ventanas y botones del sistema en el que se ejectue el software y que no utilice el default de Java.<\/p>\n<p>Para esto, yo agrego el siguiente c\u00f3digo al inicio de donde inicia la ejecuci\u00f3n del primer JFrame:<\/p>\n<p><\/p>\n<pre style=\"background: url(&quot;assets\/shadow.png&quot;) 50% 100% repeat-x rgb(245, 245, 245); border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 3px; box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; font-stretch: normal; line-height: 1.42857; margin-bottom: 10px; overflow: auto; padding: 9.5px; tab-size: 4; text-shadow: rgb(255, 255, 255) 0px 1px 0px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;\">[...]<br \/>try{<br \/>   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());<br \/>        }catch(ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e){<br \/>    System.err.println(\"Error Look GUI: \"+e.getMessage());<br \/>}<br \/>[...]<\/pre>\n<p><\/p>\n<h3 style=\"text-align: justify;\">8.- En las excepciones agregar m\u00e1s informaci\u00f3n<\/h3>\n<div style=\"text-align: justify;\">Esto tambi\u00e9n lo recomiendo, pero es de cada quien de c\u00f3mo encuentra sus errores en el c\u00f3digo, sobre todo por las excepciones:<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Lo que yo hago en cada error de una posible Excepci\u00f3n, es mostrar el con System.out.println(\u00ab\u00bb);, pero agregando el nombre del m\u00e9todo en el que ocurra el error:<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Ejemplo:<\/div>\n<pre style=\"background: url(&quot;assets\/shadow.png&quot;) 50% 100% repeat-x rgb(245, 245, 245); border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 3px; box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; font-stretch: normal; line-height: 1.42857; margin-bottom: 10px; overflow: auto; padding: 9.5px; tab-size: 4; text-shadow: rgb(255, 255, 255) 0px 1px 0px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;\">[...]<br \/>     \/**<br \/>     * M\u00e9todo que realiza la desconexi\u00f3n con la BD.<br \/>     * @return boolean<br \/>     *\/<br \/>    public boolean desconectar(){<br \/>        boolean desconecta=false;<br \/>        try {<br \/>           conexion.close();<br \/>           desconecta=true;<br \/>           System.out.println(\"Clase conexi\u00f3n: desconexi\u00f3n exitosa\");<br \/>        } catch (SQLException e) {<br \/>           System.out.println(\"Error en m\u00e9todo desconectar: \" + e.getMessage());<br \/>        }<br \/>        return desconecta;<br \/>    }<br \/>[...]<\/pre>\n<p>De esta manera me doy cuenta de d\u00f3nde m\u00e1s o menos est\u00e1 el error.<\/p>\n<p>Bueno, por ahora solo les dejo esos tips, espero y les sean de utilidad. Gracias por visitar.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Entiendo que como programadores o desarrolladores, tenemos ya nuestra pila de \u00abTrucos y Tips\u00bb a la hora de programar, as\u00ed como tambi\u00e9n solucionar o encontrar los \u00abErrores\u00bb, los catch, que no contemplamos o que simplemente no sab\u00edamos que ocurri\u00e1n. Como ya mencion\u00e9, cada quien crea sus propios trucos con base a sus experiencias, pero no [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[640,642,446,542,639,198,641,643],"tags":[],"class_list":["post-1611","post","type-post","status-publish","format-standard","hentry","category-catch","category-errores","category-java","category-programacion","category-programar","category-tips","category-trucos","category-try"],"_links":{"self":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/posts\/1611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/comments?post=1611"}],"version-history":[{"count":0,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/posts\/1611\/revisions"}],"wp:attachment":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/media?parent=1611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/categories?post=1611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/tags?post=1611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}