gt: 		aviso = new JLabel("Matriz incorrecta");
context: import javax.sound.sampled.AudioFormat;
  import javax.sound.sampled.AudioInputStream;
  import javax.sound.sampled.AudioSystem;
  import javax.sound.sampled.DataLine;
  import javax.sound.sampled.SourceDataLine;
  import javax.swing.*;
  import javax.swing.event.ChangeEvent;
  import javax.swing.event.ChangeListener;
  import javax.swing.event.TableModelEvent;
  import javax.swing.event.TableModelListener;
  import javax.swing.table.DefaultTableModel;
  import javax.swing.table.TableCellRenderer;
  import javax.swing.table.TableModel;
  
  import java.awt.Color;
  import java.awt.Component;
  import java.awt.Dimension;
  import java.awt.Rectangle;
  import java.awt.Toolkit;
  import java.awt.event.*;
  import java.io.File;
  import java.io.IOException;
  
  /**
   * IA Pract1
   * VentanaEntorno.java
   * Purpose: Clase que define la GUI.
   *
   * @author G.P.A (GUI Preciosa y Asombrosa)
   * @version 1.1.c 10/10/2017
   */
  
  public class VentanaEntorno extends JFrame implements ActionListener, TableModelListener, ChangeListener {
  
  	private static final long serialVersionUID = 1L;
  	private Entorno backEnd;
  	private JTable matriz;
  	private JTextField n,m,percent;
  	private JPanel panelContenido;
  	private JButton changePercent, createFromFile, solve, dibujar;
  	private JLabel aviso,info;
  	private JScrollPane panelMatriz;
  	private final JFileChooser fc = new JFileChooser();
  	private boolean timerStopper = false;
  	private int j = 0;
  	private javax.swing.Timer timer = new javax.swing.Timer(100, this);
  	private JRadioButton MNH, EUC, MHL;
  	ButtonGroup metodos;
  	protected AudioFormat audioFormat;
  	protected AudioInputStream audioInputStream;
  	protected SourceDataLine sourceDataLine;
  	protected boolean stopPlayback = false;
  	/**
  	 * Metodo que observa las acciones realizadas en la interfaz grafica
  	 * 
  	 * @param e Evento que lanzo este metodo
  	 */
  	public void actionPerformed(ActionEvent e) {
  		Object[]dummy;
  		if(e.getSource() == changePercent) backEnd.setPorcentaje(Integer.parseInt(percent.getText()));
  		else if(e.getSource() == createFromFile) {
  			int returnVal = fc.showOpenDialog(panelContenido);
  
  			if (returnVal == JFileChooser.APPROVE_OPTION) {
  				File file = fc.getSelectedFile();
  				try {
  					backEnd = new Entorno(file.getAbsolutePath());
  					aviso.setVisible(false);
  				} catch (IOException | ConstructorException | NumberFormatException e1) {
  					aviso.setVisible(true);
  				}
  			} else {
  				System.out.println("Open command cancelled by user.");
  			}
  			backEnd.setMode(Integer.parseInt(metodos.getSelection().getActionCommand()));
  			dummy = new String[backEnd.getMatriz().length];
  			dummy = backEnd.getMatriz()[0];
  			matriz.setModel(new DefaultTableModel(backEnd.getMatriz(),dummy));
  			matriz.setTableHeader(null);
  			matriz.getModel().addTableModelListener(this);
  		} else if(e.getSource() == solve) {
  			if(backEnd.test()) {
  				solve();
  				j = 0;
  			} else aviso.setVisible(true);
  		} else if(e.getSource() == timer){
  			if(timerStopper) return;
  			backEnd.showOptimalStep(j);
  			j++;
  			if(!backEnd.test() && j != 0)  { 
  				createFromFile.setEnabled(true);
  				dibujar.setEnabled(true);
  				stopPlayback = true;
  				timerStopper = true;
  				}
  			dummy = new String[backEnd.getMatriz().length];
  			dummy = backEnd.getMatriz()[0];
  			matriz.setModel(new DefaultTableModel(backEnd.getMatriz(),dummy)) ;
  			matriz.setTableHeader(null);
  			matriz.getModel().addTableModelListener(this);
  			for(int i = 0; i < matriz.getColumnCount();i++) {
  				matriz.getColumnModel().getColumn(i).setPreferredWidth(20);
  				matriz.getColumnModel().getColumn(i).setWidth(20);
  			}
  			panelMatriz.setPreferredSize(new Dimension ((int)matriz.getRowHeight()*backEnd.getMatriz().length, (int)matriz.getRowHeight()*backEnd.getMatriz()[0].length+3));
  			panelMatriz.setColumnHeader(null);
  			scrollToCenter(matriz,backEnd.getCoche().getX(), backEnd.getCoche().getY());
  			panelMatriz.revalidate();
  			panelContenido.revalidate();
  		} else if(e.getSource() == MNH) {
  			if(backEnd.test()) backEnd.setMode(0);
  		} else if (e.getSource() == EUC) {
  			if(backEnd.test()) backEnd.setMode(1);
  		} else if(e.getSource() == MHL) {
  			if(backEnd.test()) backEnd.setMode(2);
  		} else{
  			try {
  				backEnd= new Entorno(Integer.parseInt(n.getText()),Integer.parseInt(m.getText()));
  				aviso.setVisible(false);
  			} catch (NumberFormatException e1) {
  				aviso.setVisible(true);
  			} catch (ConstructorException e1) {
  				aviso.setVisible(true);
  			}
  			backEnd.setMode(Integer.parseInt(metodos.getSelection().getActionCommand()));
  			dummy = new String[backEnd.getMatriz().length];
  			dummy = backEnd.getMatriz()[0];
  			matriz.setModel(new DefaultTableModel(backEnd.getMatriz(),dummy)) ;
  			matriz.setTableHeader(null);
  			matriz.getModel().addTableModelListener(this);
  		}
  		info.setText("DIM:" + backEnd.getMatriz().length + "x" + backEnd.getMatriz()[0].length + "|porcentaje:" + backEnd.getPorcentaje() + "|TTS:" + backEnd.getTTS() + "|Num.Pasos:" + backEnd.getVisitados().size());
  		for(int i = 0; i < matriz.getColumnCount();i++) {
  			matriz.getColumnModel().getColumn(i).setPreferredWidth(20);
  			matriz.getColumnModel().getColumn(i).setWidth(20);
  		}
  		panelMatriz.setPreferredSize(new Dimension ((int)matriz.getRowHeight()*backEnd.getMatriz().length, (int)matriz.getRowHeight()*backEnd.getMatriz()[0].length+3));
  		panelMatriz.setColumnHeader(null);
  		if(timerStopper) timer.stop();
  		panelMatriz.revalidate();
  		panelContenido.revalidate();
  		if (e.getSource() != timer && e.getSource() != solve) pack();
  	}
  	private void scrollToCenter(JTable matriz2, int x, int y) {
  			    if (!(matriz2.getParent() instanceof JViewport)) {
  			      return;
  			    }
  			    JViewport viewport = (JViewport) matriz2.getParent();
  			    Rectangle rect = matriz2.getCellRect(x, y, true);
  			    Rectangle viewRect = viewport.getViewRect();
  			    rect.setLocation(rect.x - viewRect.x, rect.y - viewRect.y);
  
  			    int centerX = (viewRect.width - rect.width) / 2;
  			    int centerY = (viewRect.height - rect.height) / 2;
  			    if (rect.x < centerX) {
  			      centerX = -centerX;
  			    }
  			    if (rect.y < centerY) {
  			      centerY = -centerY;
  			    }
  			    rect.translate(centerX, centerY);
  			    viewport.scrollRectToVisible(rect);
  			}
  		
  	/**
  	 * Resuelve el problema
  	 */
  	private void solve() {
  		timerStopper = false;
  		dibujar.setEnabled(false);
  		createFromFile.setEnabled(false);
  		backEnd.restartLists();
  		try {
  			backEnd.solve();
  		} catch (BadMatrixException e) {
  			aviso.setVisible(true);
  			dibujar.setEnabled(true);
  			createFromFile.setEnabled(true);
  			stopPlayback = true;
  			timerStopper = true;
  		} finally {
  			playAudio();
  			timer.start();
  		}	
  	}
  	private void playAudio() {
  		    try{
  		      File soundFile =
  		                   new File("brumbrum.wav");
  		      audioInputStream = AudioSystem.
  		                  getAudioInputStream(soundFile);
  		      audioFormat = audioInputStream.getFormat();
  		      System.out.println(audioFormat);
  
  		      DataLine.Info dataLineInfo =
  		                          new DataLine.Info(
  		                            SourceDataLine.class,
  		                                    audioFormat);
  
  		      sourceDataLine =
  		             (SourceDataLine)AudioSystem.getLine(
  		                                   dataLineInfo);
  
  		      //Create a thread to play back the data and
  		      // start it running.  It will run until the
  		      // end of file, or the Stop button is
  		      // clicked, whichever occurs first.
  		      // Because of the data buffers involved,
  		      // there will normally be a delay between
  		      // the click on the Stop button and the
  		      // actual termination of playback.
  		      new PlayThread().start();
  		    }catch (Exception e) {
  		      e.printStackTrace();
  		      System.exit(0);
  		    }//end catch
  		  }//end playAudio
  		
  	/**
  	 * Constructor de la ventana
  	 * @param x Entorno que se muestra en la JTable matriz
  	 */
  	public VentanaEntorno(Entorno x) {
  		ImageIcon img = new ImageIcon("gpa.jpg");
  		setIconImage(img.getImage());
  		panelContenido = new JPanel();
  		GroupLayout layout = new GroupLayout(panelContenido);
  		panelContenido.setLayout(layout);
  		layout.setAutoCreateGaps(true);
  		layout.setAutoCreateContainerGaps(true);
  		this.backEnd = x;
  