You are on page 1of 20

package Lenguaje.Formal.AFND2AFD.

Modelo;

import java.util.*;

public class Automata {

private String Nombre;


private int numEstados;
private int EstadoInicial;
private int EstadoActual;
private TreeSet<String> Alfabeto;
private TreeSet<Integer> estadoFinal;
private TreeSet<Integer>[][] TablaTransiciones;

public Automata()
{
super();
Alfabeto = new TreeSet<String>();
estadoFinal = new TreeSet<Integer>();

public Automata(String nombre, int nEstados, TreeSet<String>


alfabeto, int q0,
TreeSet<Integer> qend, TreeSet<Integer>[][]
tablaTransiciones) {
super();
Nombre = nombre;
this.numEstados = nEstados;
Alfabeto = alfabeto;
this.EstadoInicial = q0;
estadoFinal = qend;
TablaTransiciones = tablaTransiciones;
}

public String getNombre() {


return Nombre;
}
public void setNombre(String nombre) {
Nombre = nombre;
}
public int getnumEstados() {
return numEstados;
}
public void setnumEstados(int nEstados) {
this.numEstados = nEstados;
}
public TreeSet<String> getAlfabeto() {
return Alfabeto;
}
public void setAlfabeto(TreeSet<String> alfabeto) {
Alfabeto = alfabeto;
}
public int getEstadoInicial() {
return EstadoInicial;
}
public void setEstadoInicial(int q0) {
this.EstadoInicial = q0;
}
public TreeSet<Integer> getestadoFinal() {
return estadoFinal;
}
public void setestadoFinal(TreeSet<Integer> qend) {
estadoFinal = qend;
}
public TreeSet<Integer>[][] getTablaTransiciones() {
return TablaTransiciones;
}
public void setTablaTransiciones(TreeSet<Integer>[][]
tablaTransiciones) {
TablaTransiciones = tablaTransiciones;
}
public void addEstadoFinal(int q)
{
estadoFinal.add(q);
}
public int getEstadoActual()
{
return EstadoActual;
}
@SuppressWarnings("unchecked")
public void addLetraAlfabeto(String letra)
{
Alfabeto.add(letra);
TablaTransiciones = new TreeSet[numEstados][Alfabeto.size()];
iniciarTablaTransiciones();
}
private void iniciarTablaTransiciones()
{
for(int x=0;x<numEstados;x++)
{
for(int y=0;y<Alfabeto.size();y++)
{
TablaTransiciones[x][y]= new TreeSet<Integer>();
}
}
}
public void addTransicion(int q0, String e, int q1)
{
Vector<String> a = new Vector<String>();
a.addAll(Alfabeto);
TablaTransiciones[q0][a.indexOf(e)].add(q1);
}
public boolean analizarPalabra(String palabra)
{

EstadoActual = EstadoInicial;
String[] letras = palabra.split("");

for(String l:letras)
{
if(!l.equals(""))
{
EstadoActual = funcion(EstadoActual,l);
if(EstadoActual==-1)
return false;
}
}
if(estadoFinal.contains(EstadoActual))
return true;

return false;
}
private int funcion(int estadoActual, String e)
{
Vector<String> a = new Vector<String>();
a.addAll(Alfabeto);
if(TablaTransiciones[estadoActual][a.indexOf(e)].isEmpty())
{
return -1;
}
else
{
return TablaTransiciones[estadoActual]
[a.indexOf(e)].first();
}

@Override
public String toString() {
String cadena="";

for (String string : Alfabeto) {


cadena+=string+"\t";
}
cadena+="\n";
for (int i = 0; i < TablaTransiciones.length; i++) {
for (int j = 0; j < TablaTransiciones[i].length; j++) {
cadena+=TablaTransiciones[i][j]+"\t";

}
cadena+="\n";

return cadena;
}

}
package Lenguaje.Formal.AFND2AFD.Logica;

import Lenguaje.Formal.AFND2AFD.Modelo.Automata;
import java.util.Stack;
import java.util.TreeSet;
import java.util.Vector;

import javax.swing.JOptionPane;

public class Transformador {

private String nombre;


private int numestados;
private int estadoInicial;
private TreeSet<String> alfabeto;
private TreeSet<Integer> estadoFinal;
private TreeSet<Integer>[][] tabtrans;

public Automata minimizar(Automata automata)


{

nombre = automata.getNombre();
numestados = automata.getnumEstados();
alfabeto = automata.getAlfabeto();
estadoInicial = automata.getEstadoInicial();
estadoFinal = automata.getestadoFinal();
tabtrans = automata.getTablaTransiciones();

if(alfabeto.contains("E"))
{
JOptionPane.showMessageDialog(null,"Quitando tranciciones
vacias");

quitarTansicionesVacias();
JOptionPane.showMessageDialog(null,"tranciciones vacias
quitadas");

}
else
{
JOptionPane.showMessageDialog(null,"no tiene tranciciones
vacias");

}
if(noEsDeterminista())
{
JOptionPane.showMessageDialog(null,"Quitando indeterminismo");

quitarIndeterminismo();
JOptionPane.showMessageDialog(null,"Indeterminismo quitado");

}
else
{
JOptionPane.showMessageDialog(null,"Ya es determinista");

while(!verificarMinimo())
minimizar();

JOptionPane.showMessageDialog(null,"Es minimo");

return new Automata(nombre, numestados, alfabeto, estadoInicial,


estadoFinal, tabtrans);

private void quitarIndeterminismo()


{

Vector<TreeSet> nuevosEstados = new Vector<TreeSet>();


TreeSet<Integer> ts;
TreeSet<Integer> ts2;

TreeSet<Integer> c = new TreeSet<Integer>();


c.add(0);
nuevosEstados.add(c);

for(String s:alfabeto)
{
for(int cont = 0;cont<numestados;cont++)
{
ts = obtenerTransicion(cont, s);
if(ts.size()!=0 && !nuevosEstados.contains(ts))

{
nuevosEstados.add(ts);
}
}
}
Vector<TreeSet> temporal = (Vector<TreeSet>)
nuevosEstados.clone();

for(TreeSet<Integer> t: temporal)
{
ts2 = new TreeSet<Integer>();
for(String s: alfabeto)
{
for(Integer i: t)
{
ts2.addAll(obtenerTransicion(i, s));
}
if(ts2.size()!=0 && !nuevosEstados.contains(ts2))

{
nuevosEstados.add(ts2);
}
}
}

TreeSet<Integer>[][] tablaaux = new


TreeSet[nuevosEstados.size()][alfabeto.size()];

TreeSet<Integer> tranO,tran;
for(String s: alfabeto)
{
for(TreeSet<Integer> t: nuevosEstados)
{
tranO = new TreeSet<Integer>();
tran = new TreeSet<Integer>();
for(Integer i: t)
{
tranO.addAll(obtenerTransicion(i, s));
}

///-nuevo
if(nuevosEstados.indexOf(tranO)!=-1)

tran.add(nuevosEstados.indexOf(tranO));

Vector<String> a = new Vector<String>();


a.addAll(alfabeto);
tablaaux[nuevosEstados.indexOf(t)][a.indexOf(s)] =
tran;
}
}

TreeSet<Integer> finales = new TreeSet<Integer>();

for(TreeSet<Integer> t: nuevosEstados)
{
for(Integer i: estadoFinal)
{
if(t.contains(i))
{
finales.add(nuevosEstados.indexOf(t));
}
}
}

numestados = nuevosEstados.size();
estadoFinal = finales;
tabtrans = tablaaux;
System.out.println(tablaaux);
}

private boolean noEsDeterminista()


{
boolean b = false;
TreeSet<Integer> ts = new TreeSet<Integer>();
for(String s:alfabeto)
{
for(int cont = 0;cont<numestados;cont++)
{
ts=obtenerTransicion(cont, s);
if(ts!=null && ts.size()>1)
{
b = true;
}
}
}
return b;
}

private void quitarTansicionesVacias()


{
TreeSet<Integer> tran;
TreeSet<Integer> clau;
TreeSet<Integer> clau2;

TreeSet<String> alfabetoTemp =
(TreeSet<String>)alfabeto.clone();
alfabetoTemp.remove("E");
TreeSet<Integer>[][] tablatransicionesTemp = new
TreeSet[numestados][alfabetoTemp.size()];

for(int a=0;a<alfabetoTemp.size();a++)
{
for(int q=0;q<numestados;q++)
{
tablatransicionesTemp[q][a] = new
TreeSet<Integer>();
}

for(String s: alfabeto)
{
if(!s.equals("E"))
{
for(int cont=0;cont<numestados;cont++)
{
//System.out.print(cont + " "+s+" -");

tran = new TreeSet<Integer>();


clau = cerrarVacias(cont);
clau2 = new TreeSet<Integer>();
for(Integer i: clau)
{
tran.addAll(obtenerTransicion(i.intValue(), s));
}
for(Integer i: tran)
{

clau2.addAll(cerrarVacias(i.intValue()));

Vector<String> a = new
Vector<String>();
a.addAll(alfabetoTemp);
tablatransicionesTemp[cont]
[a.indexOf(s)].addAll(clau2);
}
}
}
}

TreeSet<Integer> f = cerrarVacias(estadoInicial);
boolean cq0F=false;

for(Integer i: estadoFinal)
{
if(f.contains(i))
{
cq0F = true;
}
}

if(cq0F)
{
estadoFinal.add(estadoInicial);
}
alfabeto = alfabetoTemp;
tabtrans = tablatransicionesTemp;

System.out.println();
}

private TreeSet<Integer> cerrarVacias(int q)


{
TreeSet<Integer> cierre = new TreeSet<Integer>();
TreeSet<Integer> ts = new TreeSet<Integer>();
Stack<TreeSet<Integer>> pila = new Stack<TreeSet<Integer>>();

pila.push(obtenerTransicion(q, "E"));
cierre.add(q);

while(!pila.isEmpty())
{
ts = pila.pop();

for(Integer i: ts)
{
if(!cierre.contains(i.intValue()))
{
pila.push(obtenerTransicion(i.intValue(),
"E"));
}
}
cierre.addAll(ts);
}
return cierre;
}

private TreeSet<Integer> obtenerTransicion(int q0, String e)


{
Vector<String> a = new Vector<String>();
a.addAll(alfabeto);
//System.out.println(tabtrans[q0][a.indexOf(e)]);
return tabtrans[q0][a.indexOf(e)];
}

private boolean verificarMinimo()

{
boolean f = true;

int[][] estados = new int[numestados][numestados];


TreeSet<Integer> r;
TreeSet<Integer> t;
int y;
int x;
int tamanio =0;
for(int cont=1;cont<numestados;cont++)
{
for(int cont2=0;cont2<cont;cont2++)
{
if((estadoFinal.contains(cont)&&!
estadoFinal.contains(cont2))||(estadoFinal.contains(cont2)&&!
estadoFinal.contains(cont)))
{
estados[cont][cont2] = 1;

}
tamanio =0;
for(String s:alfabeto)
{
r = obtenerTransicion(cont, s);
t = obtenerTransicion(cont2, s);

if(r.size()>0 && t.size()>0)


{
tamanio++;
y = r.first().intValue();
x = t.first().intValue();

if(x<y)
{
if(estados[y][x]==1)
{
estados[cont][cont2] = 1;
}
}
else
{
if(estados[x][y]==1)
{
estados[cont][cont2] = 1;
}
}
if(y!=x)
{
estados[cont][cont2] = 1;
}
}
}
if(tamanio!=alfabeto.size())
{
estados[cont][cont2] = 1;
}
}
}

for(int cont=1;cont<numestados;cont++)
{
for(int cont2=0;cont2<cont;cont2++)
{
if(estados[cont][cont2]==0)
f = false;
}
}

return f;

private void minimizar()


{

int[][] estados = new int[numestados][numestados];


TreeSet<Integer> r;
TreeSet<Integer> t;
int x;
int y;
int tamanio =0;
for(int cont=1;cont<numestados;cont++)
{
for(int cont2=0;cont2<cont;cont2++)
{
if((estadoFinal.contains(cont)&&!
estadoFinal.contains(cont2))||(estadoFinal.contains(cont2)&&!
estadoFinal.contains(cont)))
{
estados[cont][cont2] = 1;

}
tamanio =0;
for(String s:alfabeto)
{
r = obtenerTransicion(cont, s);
t = obtenerTransicion(cont2, s);

if(r.size()>0 && t.size()>0)


{
tamanio++;
x = r.first().intValue();
y = t.first().intValue();

if(y<x)
{
if(estados[x][y]==1)
{
estados[cont][cont2] = 1;
}
}
else
{
if(estados[y][x]==1)
{
estados[cont][cont2] = 1;
}
}
if(x!=y)
{
estados[cont][cont2] = 1;
}
}
}
if(tamanio!=alfabeto.size())
{
estados[cont][cont2] = 1;
}
}
}
Vector<TreeSet> vector = new Vector<TreeSet>();
TreeSet<Integer> ts;
boolean f;

for(int cont=1;cont<numestados;cont++)
{
for(int cont2=0;cont2<cont;cont2++)
{
if(estados[cont][cont2] == 0)
{
ts = new TreeSet<Integer>();
f = true;

ts.add(cont);
ts.add(cont2);

for(TreeSet<Integer> tsmod: vector)


{
if(tsmod.contains(cont)||
tsmod.contains(cont))
{
tsmod.addAll(ts);
f=false;
}
}
if(f)
{
vector.add(ts);
}
}
}
}

f= true;

for(int cont =0;cont<numestados;cont++)


{
f= true;
for(TreeSet<Integer> tsmod: vector)
{
if(tsmod.contains(cont))
{
f=false;
}
}
if(f)
{
ts = new TreeSet<Integer>();
ts.add(cont);
vector.add(ts);
}
}

TreeSet<Integer>[][] tablaTemp = new TreeSet[vector.size()]


[alfabeto.size()];

TreeSet<Integer> tran;
int t0;
TreeSet<Integer> t1;
for(String s: alfabeto)
{
for(TreeSet<Integer> tsi:vector)
{
tran = new TreeSet<Integer>();
for(Integer i:tsi)
{
tran.addAll(obtenerTransicion(i, s));
}

t0 = vector.indexOf(tsi);
t1 = new TreeSet<Integer>();
for(TreeSet<Integer> tsi2:vector)
{
if(tran.size()>0&&tsi2.containsAll(tran))
{
t1.add(vector.indexOf(tsi2));
}
}

Vector<String> a = new Vector<String>();


a.addAll(alfabeto);
tablaTemp[t0][a.indexOf(s)] = t1;

}
}

TreeSet<Integer> finales = new TreeSet<Integer>();


int q00=estadoInicial;

for(TreeSet<Integer> i: vector)
{
if(i.contains(estadoInicial))
{
q00 = vector.indexOf(i);
}

for(Integer ii:estadoFinal)
{
if(i.contains(ii))
{
finales.add(vector.indexOf(i));
}
}
}

estadoInicial=q00;
numestados = vector.size();
estadoFinal = finales;
tabtrans = tablaTemp;

System.out.println();

}
}

package Lenguaje.Formal.AFND2AFD.Ventanas;

import Lenguaje.Formal.AFND2AFD.Logica.Transformador;
import Lenguaje.Formal.AFND2AFD.Modelo.Automata;
import Lenguje.Formal.AFND2AFD.Util.PanelFondo;
import com.mycsistemas.swingec.button.RoundtButton;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Maricela Maldonado
*/
public class Ventanita extends JFrame implements ActionListener{
private RoundtButton ingresar= new RoundtButton();
private RoundtButton ingresaLetrar= new RoundtButton();
private RoundtButton ingresaNEstados= new RoundtButton();
private RoundtButton ingresaEstadoI= new RoundtButton();
private RoundtButton ingresaEstadoF= new RoundtButton();
private RoundtButton ingresaTabla= new RoundtButton();
private RoundtButton limpiar= new RoundtButton();

private JTextArea area=new JTextArea();


private JScrollPane scroll=new JScrollPane(area);

private JLabel eti=new JLabel("Ingrese una Letra al Alfabeto:");


private JLabel eti3=new JLabel("Ingrese el Numero de Estados:");
private JLabel eti4=new JLabel("Ingrese el Estado Inicial:");
private JLabel eti5=new JLabel("Ingrese el Estado Final:");
private JLabel eti6=new JLabel("Ingrese la Tabla de Transiciones:");

private JLabel eti7=new JLabel("q?");


private JLabel eti8=new JLabel("Letra");
private JLabel eti9=new JLabel("q?");

private JLabel eti2=new JLabel("<html><body><p


align=\"center\">Resultados de la Transformacion</p></body></html>");
private JTextField txtIngreso=new JTextField();
private JTextField txtEstadosN=new JTextField();
private JTextField txtEstadosI=new JTextField();
private JTextField txtEstadosF=new JTextField();
private JTextField txtTabla=new JTextField();
private JTextField txtTabla2=new JTextField();
private JTextField txtTabla3=new JTextField();

private PanelFondo back=new PanelFondo();

Automata auto=new Automata();

public Ventanita() {
initComponents();
setTitle("Convertidor");
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-535)/2, (screenSize.height-420)/2,
535, 420);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void initComponents(){

// back.setImageIcon(new
ImageIcon(getClass().getResource("//Lenguaje//Formal//AFND2AFD//Imagenes/
/23.jpg")));

area.setEditable(false);

SpringLayout sp=new SpringLayout();

back.setLayout(sp);

sp.putConstraint(SpringLayout.NORTH, eti3, 15,


SpringLayout.NORTH, back);
sp.putConstraint(SpringLayout.WEST, eti3, 15, SpringLayout.WEST,
back);
eti3.setFont(new Font("Times New Roman", Font.BOLD, 16));
eti3.setHorizontalAlignment(JLabel.CENTER);
eti3.setForeground(Color.red);

sp.putConstraint(SpringLayout.NORTH, ingresaNEstados, 0,
SpringLayout.NORTH, eti3);
sp.putConstraint(SpringLayout.EAST, ingresaNEstados, -15,
SpringLayout.EAST, back);

sp.putConstraint(SpringLayout.NORTH, txtEstadosN, 0,
SpringLayout.NORTH, eti3);
sp.putConstraint(SpringLayout.WEST, txtEstadosN, 15,
SpringLayout.EAST, eti3);
sp.putConstraint(SpringLayout.EAST, txtEstadosN, -15,
SpringLayout.WEST, ingresaNEstados);

sp.putConstraint(SpringLayout.NORTH, eti, 15, SpringLayout.SOUTH,


eti3);
sp.putConstraint(SpringLayout.WEST, eti, 0, SpringLayout.WEST,
eti3);
eti.setFont(new Font("Times New Roman", Font.BOLD, 16));
eti.setHorizontalAlignment(JLabel.CENTER);
eti.setForeground(Color.red);

sp.putConstraint(SpringLayout.NORTH, ingresaLetrar, 0,
SpringLayout.NORTH, eti);
sp.putConstraint(SpringLayout.EAST, ingresaLetrar, -15,
SpringLayout.EAST, back);

sp.putConstraint(SpringLayout.NORTH, txtIngreso, 0,
SpringLayout.NORTH, eti);
sp.putConstraint(SpringLayout.WEST, txtIngreso, 15,
SpringLayout.EAST, eti);
sp.putConstraint(SpringLayout.EAST, txtIngreso, -15,
SpringLayout.WEST, ingresaLetrar);

sp.putConstraint(SpringLayout.NORTH, eti4, 15,


SpringLayout.SOUTH, eti);
sp.putConstraint(SpringLayout.WEST, eti4, 15, SpringLayout.WEST,
back);
eti4.setFont(new Font("Times New Roman", Font.BOLD, 16));
eti4.setHorizontalAlignment(JLabel.CENTER);
eti4.setForeground(Color.red);

sp.putConstraint(SpringLayout.NORTH, ingresaEstadoI, 0,
SpringLayout.NORTH, eti4);
sp.putConstraint(SpringLayout.EAST, ingresaEstadoI, -15,
SpringLayout.EAST, back);

sp.putConstraint(SpringLayout.NORTH, txtEstadosI, 0,
SpringLayout.NORTH, eti4);
sp.putConstraint(SpringLayout.WEST, txtEstadosI, 15,
SpringLayout.EAST, eti4);
sp.putConstraint(SpringLayout.EAST, txtEstadosI, -15,
SpringLayout.WEST, ingresaEstadoI);

sp.putConstraint(SpringLayout.NORTH, eti5, 15,


SpringLayout.SOUTH, eti4);
sp.putConstraint(SpringLayout.WEST, eti5, 15, SpringLayout.WEST,
back);
eti5.setFont(new Font("Times New Roman", Font.BOLD, 16));
eti5.setHorizontalAlignment(JLabel.CENTER);
eti5.setForeground(Color.red);

sp.putConstraint(SpringLayout.NORTH, ingresaEstadoF, 0,
SpringLayout.NORTH, eti5);
sp.putConstraint(SpringLayout.EAST, ingresaEstadoF, -15,
SpringLayout.EAST, back);

sp.putConstraint(SpringLayout.NORTH, txtEstadosF, 0,
SpringLayout.NORTH, eti5);
sp.putConstraint(SpringLayout.WEST, txtEstadosF, 15,
SpringLayout.EAST, eti5);
sp.putConstraint(SpringLayout.EAST, txtEstadosF, -15,
SpringLayout.WEST, ingresaEstadoF);

sp.putConstraint(SpringLayout.NORTH, eti6, 15,


SpringLayout.SOUTH, eti7);
sp.putConstraint(SpringLayout.WEST, eti6, 15, SpringLayout.WEST,
back);
eti6.setFont(new Font("Times New Roman", Font.BOLD, 16));
eti6.setHorizontalAlignment(JLabel.CENTER);
eti6.setForeground(Color.red);

sp.putConstraint(SpringLayout.NORTH, ingresaTabla, 0,
SpringLayout.NORTH, eti6);
sp.putConstraint(SpringLayout.EAST, ingresaTabla, -15,
SpringLayout.EAST, back);

sp.putConstraint(SpringLayout.NORTH, txtTabla, 0,
SpringLayout.NORTH, ingresaTabla);
sp.putConstraint(SpringLayout.WEST, txtTabla, -30,
SpringLayout.EAST, txtTabla);
sp.putConstraint(SpringLayout.EAST, txtTabla, -15,
SpringLayout.WEST, ingresaTabla);

sp.putConstraint(SpringLayout.NORTH, txtTabla2, 0,
SpringLayout.NORTH, txtTabla);
sp.putConstraint(SpringLayout.WEST, txtTabla2, -30,
SpringLayout.EAST, txtTabla2);
sp.putConstraint(SpringLayout.EAST, txtTabla2, -15,
SpringLayout.WEST, txtTabla);

sp.putConstraint(SpringLayout.NORTH, txtTabla3, 0,
SpringLayout.NORTH, txtTabla2);
sp.putConstraint(SpringLayout.WEST, txtTabla3, -30,
SpringLayout.EAST, txtTabla3);
sp.putConstraint(SpringLayout.EAST, txtTabla3, -15,
SpringLayout.WEST, txtTabla2);

sp.putConstraint(SpringLayout.NORTH, eti7, 15,


SpringLayout.SOUTH, eti5);
sp.putConstraint(SpringLayout.WEST, eti7, 5, SpringLayout.WEST,
txtTabla3);
eti7.setFont(new Font("Times New Roman", Font.BOLD, 16));
eti7.setHorizontalAlignment(JLabel.CENTER);
eti7.setForeground(Color.red);

sp.putConstraint(SpringLayout.NORTH, eti8, 15,


SpringLayout.SOUTH, eti5);
sp.putConstraint(SpringLayout.WEST, eti8, -5, SpringLayout.WEST,
txtTabla2);
eti8.setFont(new Font("Times New Roman", Font.BOLD, 16));
eti8.setHorizontalAlignment(JLabel.CENTER);
eti8.setForeground(Color.red);

sp.putConstraint(SpringLayout.NORTH, eti9, 15,


SpringLayout.SOUTH, eti5);
sp.putConstraint(SpringLayout.WEST, eti9, 5, SpringLayout.WEST,
txtTabla);
eti9.setFont(new Font("Times New Roman", Font.BOLD, 16));
eti9.setHorizontalAlignment(JLabel.CENTER);
eti9.setForeground(Color.red);

sp.putConstraint(SpringLayout.NORTH, eti2, 10,


SpringLayout.SOUTH, eti6);
sp.putConstraint(SpringLayout.WEST, eti2, 0, SpringLayout.WEST,
eti);
sp.putConstraint(SpringLayout.EAST, eti2, 0, SpringLayout.EAST,
txtEstadosN);

sp.putConstraint(SpringLayout.SOUTH, ingresar, -15,


SpringLayout.SOUTH, back);
sp.putConstraint(SpringLayout.WEST, ingresar, 0,
SpringLayout.WEST, eti);

sp.putConstraint(SpringLayout.SOUTH, limpiar, -15,


SpringLayout.SOUTH, back);
sp.putConstraint(SpringLayout.EAST, limpiar, 0,
SpringLayout.EAST, eti2);

sp.putConstraint(SpringLayout.NORTH, scroll, 10,


SpringLayout.SOUTH, eti2);
sp.putConstraint(SpringLayout.WEST, scroll, 0, SpringLayout.WEST,
eti);
sp.putConstraint(SpringLayout.EAST, scroll, 0, SpringLayout.EAST,
ingresaLetrar);
sp.putConstraint(SpringLayout.SOUTH, scroll, -15,
SpringLayout.NORTH, ingresar);

ingresar.setText("Ejecutar Conversion");
ingresaLetrar.setText("Ingresar");
ingresaNEstados.setText("Ingresar");
ingresaEstadoI.setText("Ingresar");
ingresaEstadoF.setText("Ingresar");
ingresaTabla.setText("Ingresar");
limpiar.setText("Limpiar Campos");

eti2.setFont(new Font("Times New Roman", Font.BOLD, 16));


eti2.setHorizontalAlignment(JLabel.CENTER);
eti2.setForeground(Color.red);

ingresar.addActionListener(this);
ingresaLetrar.addActionListener(this);
ingresaNEstados.addActionListener(this);
ingresaEstadoI.addActionListener(this);
ingresaEstadoF.addActionListener(this);
ingresaTabla.addActionListener(this);
limpiar.addActionListener(this);

back.add(eti);
back.add(txtIngreso);
back.add(ingresaLetrar);
back.add(eti3);
back.add(txtEstadosN);
back.add(ingresaNEstados);
back.add(eti4);
back.add(txtEstadosI);
back.add(ingresaEstadoI);
back.add(eti5);
back.add(txtEstadosF);
back.add(ingresaEstadoF);
back.add(eti6);
back.add(txtTabla);
back.add(txtTabla2);
back.add(txtTabla3);
back.add(eti7);
back.add(eti8);
back.add(eti9);
back.add(ingresaTabla);
back.add(eti2);
back.add(ingresar);
back.add(limpiar);
back.add(scroll);

getContentPane().add(back);

public void actionPerformed(ActionEvent e) {


if(e.getSource().equals(ingresaLetrar)){
if(txtIngreso.getText().equals("")){
JOptionPane.showMessageDialog(this, "Ingrese una letra al
alfabeto","Error",JOptionPane.ERROR_MESSAGE);
}else{
auto.addLetraAlfabeto(txtIngreso.getText());
area.append(txtIngreso.getText()+"\t");
txtIngreso.setText("");
}

}else if(e.getSource().equals(limpiar)){
txtIngreso.setText("");
area.setText("");
}else if(e.getSource().equals(ingresaNEstados)){
try {
int numeros = Integer.parseInt(txtEstadosN.getText());
area.append("Numero de estados: "+numeros+"\n");
auto.setnumEstados(numeros);
txtEstadosN.setEditable(false);
} catch (NumberFormatException numberFormatException) {
JOptionPane.showMessageDialog(this, "Ingrese un numero
valido","Error",JOptionPane.ERROR_MESSAGE);
}

}else if(e.getSource().equals(ingresaEstadoI)){
try {
int numeros =
Integer.parseInt(txtEstadosI.getText());
area.append("\nEstado Inicial : "+numeros);
auto.setEstadoInicial(numeros);
txtEstadosI.setEditable(false);
} catch (NumberFormatException numberFormatException) {
JOptionPane.showMessageDialog(this, "Ingrese un numero
valido","Error",JOptionPane.ERROR_MESSAGE);
}

}else if(e.getSource().equals(ingresaEstadoF)){
try {
int numeros = Integer.parseInt(txtEstadosF.getText());
area.append("\nEstado Final: "+numeros);
auto.addEstadoFinal(numeros);
txtEstadosF.setText("");
} catch (NumberFormatException numberFormatException) {
JOptionPane.showMessageDialog(this, "Ingrese un numero
valido","Error",JOptionPane.ERROR_MESSAGE);
}
}
else if(e.getSource().equals(ingresaTabla)){
try {
int numeros = Integer.parseInt(txtTabla3.getText());
int numeros2 = Integer.parseInt(txtTabla.getText());
auto.addTransicion(numeros, txtTabla2.getText(),
numeros2);
area.append("\nTransisicion:
"+numeros+"\t\t"+txtTabla2.getText()+"\t"+numeros2);
txtTabla.setText("");
txtTabla2.setText("");
txtTabla3.setText("");
} catch (NumberFormatException numberFormatException) {
JOptionPane.showMessageDialog(this, "Ingrese un numero
valido","Error",JOptionPane.ERROR_MESSAGE);
}

}else if(e.getSource().equals(ingresar)){
Transformador trans=new Transformador();
area.append("\nAutomata Finito no Determinista\n"+auto);
area.append("\nAutomata Finito
Determinista\n"+trans.minimizar(auto));

public static void main (String []er){


new Ventanita();

}
}

You might also like