Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package taximetro; /* Esta aplicacin,consiste en un taxmetro bsico * Calcula la coordenadas latitud y longitud de origen en formato decimal * a grados, minutos y segundos. * Muestra un mapa con el recorrido en linea recta, a partir de los datos de * origen introducidos y la direccin en formato texto, utilizando la API de * Google. * (1.1) Al presionar el botn de comienzo y se guarda la hora para mostrarla * posteriormente, se inicia un contador de ticket, se habilita el botn de fin * de trayecto. * Al presionar el botn de fin se detiene el contador y se guarda la hora y la * fecha,para mostrarla seguidamente. * Se calcula el coste del trayecto, para mostrarlo seguidamente. * Se muestra el numero de ticket, la hora de comienzo del trayecto, la hora de * final del trayecto, el tiempo del trayecto, el coste del trayecto;importe,IVA * e importe total. * Al presionar de nuevo el botn de comienzo, se borra el rea de texto, se * reinicia el contador y vuelve hacer el punto (1.1). */ import es.javiergarbedo.coordinateslib.CoordinatesConverter; import java.text.DateFormat; import java.text.NumberFormat; import java.util.Calendar; import java.util.Locale; import javax.swing.ImageIcon; import javax.swing.JOptionPane; import org.apache.commons.lang3.time.DurationFormatUtils; import org.apache.commons.lang3.time.StopWatch; import org.apache.commons.validator.routines.CreditCardValidator; /** * * @author Manuel */ public class main extends javax.swing.JFrame { //Declaracin de Varialbles y constantes. int ticket = 0; String textoticket = ""; boolean numcc; String horacomienzocarrera; final float TARIFA = 1.5F; //Declaracin de Objetos globales. StopWatch cronometro = new StopWatch(); Locale zona = Locale.getDefault(); public main() { //Definicin de parmetros iniciales. initComponents(); //Estado del botn de fin a desabilitado. jButtonfin.setEnabled(false); //Configurar el icono de la apicacin. setIconImage(new ImageIcon(getClass().getResource("../Imagenes/taxi.png")).getImage()); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jTextFieldlatitud = new javax.swing.JTextField(); jTextFieldlongitud = new javax.swing.JTextField(); jLabelgps = new javax.swing.JLabel(); jLabellatitud = new javax.swing.JLabel(); jLabellongitud = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jLabelmapa = new javax.swing.JLabel(); jTextFieldtarjeta = new javax.swing.JTextField(); jPanel3 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextAreaticket = new javax.swing.JTextArea(); jButtoncomienzo = new javax.swing.JButton(); jButtonfin = new javax.swing.JButton(); jButtoncomprobar = new javax.swing.JButton(); jPanel4 = new javax.swing.JPanel(); jTextFielddestino = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItemcreditos = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Taxmetro"); jPanel1.setBorder(javax.swing.BorderFactory .createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Datos de Origen")); jLabel1.setText("Latitud:"); jLabel2.setText("Longitud:"); jTextFieldlatitud.setHorizontalAlignment(javax.swing.JTextField.RIGHT); jTextFieldlatitud.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextFieldlatitudActionPerformed(evt); } }); jTextFieldlatitud.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { jTextFieldlatitudKeyPressed(evt); } public void keyReleased(java.awt.event.KeyEvent evt) { jTextFieldlatitudKeyReleased(evt); } }); jTextFieldlongitud.setHorizontalAlignment(javax.swing.JTextField.RIGHT); jTextFieldlongitud.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextFieldlongitudActionPerformed(evt); } }); jTextFieldlongitud.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { jTextFieldlongitudKeyReleased(evt); } }); jLabelgps.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/gps.png"))); // NOI18N javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2) .addComponent(jTextFieldlatitud, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE) .addComponent(jTextFieldlongitud)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabellatitud, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabellongitud, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabelgps).addGap(36, 36, 36))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextFieldlatitud, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabellatitud, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextFieldlongitud, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabellongitud, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(jLabelgps, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(15, Short.MAX_VALUE))); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder( new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Ruta")); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout .setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelmapa, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelmapa, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); jTextFieldtarjeta.setHorizontalAlignment(javax.swing.JTextField.RIGHT); jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder( javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED), "Ticket")); jTextAreaticket.setEditable(false); jTextAreaticket.setColumns(20); jTextAreaticket.setRows(5); jScrollPane1.setViewportView(jTextAreaticket); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE) .addContainerGap())); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE) .addContainerGap())); jButtoncomienzo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ok.png"))); // NOI18N jButtoncomienzo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtoncomienzoActionPerformed(evt); } }); jButtonfin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancel.png"))); // NOI18N jButtonfin.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonfinActionPerformed(evt); } }); jButtoncomprobar.setText("Comprobar"); jButtoncomprobar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtoncomprobarActionPerformed(evt); } }); jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos del Destino")); jTextFielddestino.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextFielddestinoActionPerformed(evt); } }); jLabel5.setText("Direccin destino:"); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap().addComponent(jLabel5) .addGap(18, 18, 18).addComponent(jTextFielddestino, javax.swing.GroupLayout.PREFERRED_SIZE, 372, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(156, Short.MAX_VALUE))); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextFielddestino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5)) .addContainerGap(32, Short.MAX_VALUE))); jLabel4.setText("Tarjeta de crdito:"); jMenu1.setText("Acerca de"); jMenuItemcreditos.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK)); jMenuItemcreditos.setText("Crditos"); jMenuItemcreditos.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItemcreditosActionPerformed(evt); } }); jMenu1.add(jMenuItemcreditos); jMenuBar1.add(jMenu1); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jButtoncomienzo, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButtonfin, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextFieldtarjeta, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(jButtoncomprobar, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(15, 15, 15) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jButtoncomienzo, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButtonfin, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(13, 13, 13).addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextFieldtarjeta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtoncomprobar).addGap(8, 8, 8))); pack(); }// </editor-fold>//GEN-END:initComponents private void jButtoncomienzoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtoncomienzoActionPerformed //Establecer parmetros del nuevo estado de los botones comiezo y fin // de carrera, despus de la accin del botn. jButtonfin.setEnabled(true); jButtoncomienzo.setEnabled(false); //Borrado del texto existente del area de texto. jTextAreaticket.setText(""); //Guardar la hora de comienzo de carrera al presionar el boton de comenzar. Calendar tiempo = Calendar.getInstance(zona); DateFormat formatohoras = DateFormat.getTimeInstance(DateFormat.MEDIUM); horacomienzocarrera = formatohoras.format(tiempo.getTimeInMillis()); //Establecer contador de tiempo ponerlo a cero, y inicarlo. cronometro.reset(); cronometro.start(); //Establecer contador del nmero de ticket. ticket++; //Darle formato al nmero del ticket con 5 dgitos, sin punto. NumberFormat formato = NumberFormat.getInstance(); formato.setMinimumIntegerDigits(5); formato.setGroupingUsed(false); textoticket = String.valueOf(formato.format(ticket)); }//GEN-LAST:event_jButtoncomienzoActionPerformed private void jButtonfinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonfinActionPerformed //Establecer de nuevo parametros de los botones de fin y comienzo carrera. jButtonfin.setEnabled(false); jButtoncomienzo.setEnabled(true); //Parar el contador. cronometro.stop(); //Darle formato HH:mm:ss al resultado del contador. String tiempotexto = DurationFormatUtils.formatDuration(cronometro.getTime(), "HH:mm:ss"); //Guardar la hora de fin de carrera al presionar botn de fin carrera. Calendar tiempo = Calendar.getInstance(zona); //Dar formato a la hora de fin de carrera al presionar el boton de fin. DateFormat formatohoras = DateFormat.getTimeInstance(DateFormat.MEDIUM); String horafincarrera = formatohoras.format(tiempo.getTimeInMillis()); //Dar formato a la fecha. DateFormat formatotiempo = DateFormat.getDateInstance(DateFormat.LONG); String fechatexto = formatotiempo.format(tiempo.getTime()); //Calcular el coste del trayecto, a partir del tiempo del contador. float coste = (cronometro.getTime() / 1000) * (TARIFA / 60); float iva = coste * 0.21F; float costetotal = coste * 1.21F; //Dar formato al coste del trayecto. NumberFormat formatoeuro = NumberFormat.getCurrencyInstance(zona); //Escribir en el area de texto todos los parmetros. jTextAreaticket.append("TICKET:\n \n"); jTextAreaticket.append("=================\n"); jTextAreaticket.append("Ticket N: " + textoticket + " .\n"); jTextAreaticket.append("Fecha:\n" + fechatexto + " .\n\n"); jTextAreaticket.append("Hora de comienzo de carrera: " + horacomienzocarrera + " .\n"); jTextAreaticket.append("Hora de fin de carrera: " + horafincarrera + " .\n"); jTextAreaticket.append("El tiempo del trayecto es: " + tiempotexto + " .\n\n\n"); jTextAreaticket.append("Importe: " + formatoeuro.format(coste) + " .\n"); jTextAreaticket.append("IVA: " + formatoeuro.format(iva) + " .\n"); jTextAreaticket.append("Importe Total: " + formatoeuro.format(costetotal) + " .\n"); }//GEN-LAST:event_jButtonfinActionPerformed private void jTextFieldlatitudKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldlatitudKeyReleased //Calcular la latitud en los grados decimales a grados, minutos y segundos //en la etiqueta ayacente al ser introducidos. double latitud = Double.valueOf(jTextFieldlatitud.getText()); String latitudtext = CoordinatesConverter.decimalToDMS(latitud); jLabellatitud.setText(latitudtext); }//GEN-LAST:event_jTextFieldlatitudKeyReleased private void jTextFieldlongitudKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldlongitudKeyReleased //Calcular la longuitud en los grados decimales a grados, minutos y segundos //en la etiqueta ayacente al ser introducidos. double longitud = Double.valueOf(jTextFieldlongitud.getText()); String longitudtext = CoordinatesConverter.decimalToDMS(longitud); jLabellongitud.setText(longitudtext); }//GEN-LAST:event_jTextFieldlongitudKeyReleased private void jTextFieldlatitudKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldlatitudKeyPressed }//GEN-LAST:event_jTextFieldlatitudKeyPressed private void jTextFieldlatitudActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldlatitudActionPerformed }//GEN-LAST:event_jTextFieldlatitudActionPerformed private void jTextFieldlongitudActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldlongitudActionPerformed }//GEN-LAST:event_jTextFieldlongitudActionPerformed private void jTextFielddestinoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFielddestinoActionPerformed //Generar el mapa a partir de la direccin en formato texto introducida. //al darle a Enter. String origen = jTextFieldlatitud.getText() + "," + jTextFieldlongitud.getText(); String destino = jTextFielddestino.getText(); //Hay que sustituir los espacios por el carcter %20 para que se // interprete bien la URL que se generar destino = destino.replaceAll(" ", "%20"); //Cambia el nombre [etiqueta] por el nombre de un objeto JLabel (etiqueta) que // has debido colocar antes en el formulario y que ser donde se muestre el mapa. // Deja la etiqueta del formulario sin ningn texto en el diseo. javax.swing.JLabel jLabelMapa = jLabelmapa; //Indica aqu el tamao que desees para el mapa int tamHorizontal = 200; int tamVertical = 200; //Puedes encontrar ms informacin sobre el uso de mapas estticos de Google Maps aqu: // http://code.google.com/intl/es-ES/apis/maps/documentation/staticmaps/ //A partir de aqu no hace falta cambiar nada try { String txtDireccionImagenMapa = "http://maps.google.com/maps/api/staticmap?path=" + origen + "|" + destino + "&size=" + tamHorizontal + "x" + tamVertical + "&language=ES&sensor=false"; System.out.println(txtDireccionImagenMapa); java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit(); java.awt.Image imagenMapa = toolkit.getImage(new java.net.URL(txtDireccionImagenMapa)); jLabelMapa.setIcon(new javax.swing.ImageIcon(imagenMapa)); } catch (java.net.MalformedURLException e) { javax.swing.JOptionPane.showMessageDialog(this, "La direccin de imagen indicada no es correcta"); } }//GEN-LAST:event_jTextFielddestinoActionPerformed private void jButtoncomprobarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtoncomprobarActionPerformed //Verificar el nmero de tarjeta de crdito introducido si es correcto o //no, y aparece un mensaje de si es correcta o no. CreditCardValidator validezcc = new CreditCardValidator(); numcc = validezcc.isValid(jTextFieldtarjeta.getText()); String mensajes = (numcc) ? "La tarjeta es vlida." : "La tarjeta es Erronea."; JOptionPane.showMessageDialog(this, mensajes, "Informacin", JOptionPane.INFORMATION_MESSAGE); }//GEN-LAST:event_jButtoncomprobarActionPerformed private void jMenuItemcreditosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemcreditosActionPerformed //Muestra una ventana de dialogo en la que aparecen los crditos. JOptionPane .showMessageDialog(null, "Thanks you for images to:\n" + "jean_victor_balin \n" + "nshokunin jabernal\n" + "kuba\n" + "From:\n" + "http://openclickart.org", "Creditos", JOptionPane.INFORMATION_MESSAGE); { } }//GEN-LAST:event_jMenuItemcreditosActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new main().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtoncomienzo; private javax.swing.JButton jButtoncomprobar; private javax.swing.JButton jButtonfin; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabelgps; private javax.swing.JLabel jLabellatitud; private javax.swing.JLabel jLabellongitud; private javax.swing.JLabel jLabelmapa; private javax.swing.JMenu jMenu1; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItemcreditos; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextAreaticket; private javax.swing.JTextField jTextFielddestino; private javax.swing.JTextField jTextFieldlatitud; private javax.swing.JTextField jTextFieldlongitud; private javax.swing.JTextField jTextFieldtarjeta; // End of variables declaration//GEN-END:variables private void jOptionPane(main aThis, String este_es_el_mensaje, String ttulo, int ERROR_MESSAGE) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }