Sie sind auf Seite 1von 21

package Lenguaje.Formal.AFND2AFD.Modelo; import java.util.

*; public class Automa ta { private private private private private private private String Nombre; int numEstados; int EstadoInicial; int EstadoActual; TreeSet<String> Alfabeto; TreeS et<Integer> estadoFinal; TreeSet<Integer>[][] TablaTransiciones; public Automata() { super(); Alfabeto = new TreeSet<String>(); estadoFinal = new TreeSet<Integer>(); } public Automata(String nombre, int nEstados, TreeSet<Stri ng> alfabeto, int q0, TreeSet<Integer> qend, TreeSet<Integer>[][] tablaTransicio nes) { super(); Nombre = nombre; this.numEstados = nEstados; Alfabeto = alfabeto ; this.EstadoInicial = q0; estadoFinal = qend; TablaTransiciones = tablaTransici ones; } public String getNombre() { return Nombre; } public void setNombre(Strin g 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(TreeS et<String> alfabeto) { Alfabeto = alfabeto; } public int getEstadoInicial() { re turn EstadoInicial; }

public void setEstadoInicial(int q0) { this.EstadoInicial = q0; } public TreeSet <Integer> getestadoFinal() { return estadoFinal; } public void setestadoFinal(Tr eeSet<Integer> qend) { estadoFinal = qend; } public TreeSet<Integer>[][] getTabl aTransiciones() { return TablaTransiciones; } public void setTablaTransiciones(T reeSet<Integer>[][] tablaTransiciones) { TablaTransiciones = tablaTransiciones; } public void addEstadoFinal(int q) { estadoFinal.add(q); } public int getEstado Actual() { return EstadoActual; } @SuppressWarnings("unchecked") public void add LetraAlfabeto(String letra) { Alfabeto.add(letra); TablaTransiciones = new TreeS et[numEstados][Alfabeto.size()]; iniciarTablaTransiciones(); } private void inic iarTablaTransiciones() { 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 bo olean analizarPalabra(String palabra) { EstadoActual = EstadoInicial; String[] l etras = palabra.split(""); for(String l:letras) { if(!l.equals("")) {

EstadoActual = funcion(EstadoActual,l); if(EstadoActual==-1) return false; } } i f(estadoFinal.contains(EstadoActual)) return true; return false; } private int f uncion(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 < TablaTran siciones.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 import import import Lenguaje.Formal.AFND2AFD.Modelo.Automata; java.util.Stack; java.util.TreeSet; ja va.util.Vector; import javax.swing.JOptionPane; public class Transformador { private private pri vate private private private String nombre; int numestados; int estadoInicial; T reeSet<String> alfabeto; TreeSet<Integer> estadoFinal; TreeSet<Integer>[][] tabt rans; public Automata minimizar(Automata automata) { nombre = automata.getNombre(); nu mestados = automata.getnumEstados(); alfabeto = automata.getAlfabeto(); estadoIn icial = automata.getEstadoInicial(); estadoFinal = automata.getestadoFinal(); ta btrans = automata.getTablaTransiciones(); if(alfabeto.contains("E")) { JOptionPa ne.showMessageDialog(null,"Quitando tranciciones vacias"); quitarTansicionesVaci as(); JOptionPane.showMessageDialog(null,"tranciciones vacias quitadas"); } else { JOptionPane.showMessageDialog(null,"no tiene tranciciones vacias"); } if(noEs Determinista()) { JOptionPane.showMessageDialog(null,"Quitando indeterminismo"); quitarIndeterminismo(); JOptionPane.showMessageDialog(null,"Indeterminismo quit ado"); } else {

JOptionPane.showMessageDialog(null,"Ya es determinista"); } while(!verificarMini mo()) minimizar(); JOptionPane.showMessageDialog(null,"Es minimo"); return new A utomata(nombre, numestados, alfabeto, estadoInicial, estadoFinal, tabtrans); } p rivate 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.s ize()!=0 && !nuevosEstados.contains(ts)) { nuevosEstados.add(ts); } } } Vector<T reeSet> nuevosEstados.clone(); temporal = (Vector<TreeSet>) for(TreeSet<Integer> t: temporal) { ts2 = new TreeSet<Integer>(); for(String s: alfabeto) { for(Integer i: t) { ts2.addAll(obtenerTransicion(i, s)); } if(ts2.si ze()!=0 && !nuevosEstados.contains(ts2)) { nuevosEstados.add(ts2); } }

} TreeSet<Integer>[][] tablaaux = new TreeSet[nuevosEstados.size()][alfabeto.siz e()]; 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(n uevosEstados.indexOf(tranO)!=-1) tran.add(nuevosEstados.indexOf(tranO)); Vector< String> a = new Vector<String>(); a.addAll(alfabeto); tablaaux[nuevosEstados.ind exOf(t)][a.indexOf(s)] = tran; } } TreeSet<Integer> finales = new TreeSet<Intege r>(); for(TreeSet<Integer> t: nuevosEstados) { for(Integer i: estadoFinal) { if( t.contains(i)) { finales.add(nuevosEstados.indexOf(t)); } } } numestados = nuevo sEstados.size(); estadoFinal = finales; tabtrans = tablaaux; System.out.println( tablaaux); } private boolean noEsDeterminista() { boolean b = false; TreeSet<Int eger> ts = new TreeSet<Integer>(); for(String s:alfabeto) { for(int cont = 0;con t<numestados;cont++)

{ ts=obtenerTransicion(cont, s); if(ts!=null && ts.size()>1) { b = true; } } } r eturn b; } private void quitarTansicionesVacias() { TreeSet<Integer> tran; TreeS et<Integer> clau; TreeSet<Integer> clau2; TreeSet<String> alfabetoTemp = (TreeSe t<String>)alfabeto.clone(); alfabetoTemp.remove("E"); TreeSet<Integer>[][] tabla transicionesTemp = new TreeSet[numestados][alfabetoTemp.size()]; for(int a=0;a<a lfabetoTemp.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<S tring> a = new Vector<String>();

a.addAll(alfabetoTemp); tablatransicionesTemp[cont][a.indexOf(s)].addAll(clau2); } } } } TreeSet<Integer> f = cerrarVacias(estadoInicial); boolean cq0F=false; f or(Integer i: estadoFinal) { if(f.contains(i)) { cq0F = true; } } if(cq0F) { est adoFinal.add(estadoInicial); } alfabeto = alfabetoTemp; tabtrans = tablatransici onesTemp; System.out.println(); } private TreeSet<Integer> cerrarVacias(int q) { TreeSet<Integer> cierre = new TreeSet<Integer>(); TreeSet<Integer> ts = new Tre eSet<Integer>(); Stack<TreeSet<Integer>> pila = new Stack<TreeSet<Integer>>(); p ila.push(obtenerTransicion(q, "E")); cierre.add(q); while(!pila.isEmpty()) { ts = pila.pop(); for(Integer i: ts) { if(!cierre.contains(i.intValue())) { pila.pus h(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.prin tln(tabtrans[q0][a.indexOf(e)]); return tabtrans[q0][a.indexOf(e)]; } private bo olean 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))||(est adoFinal .contains(cont2)&&!estadoFinal.contains(cont))) { estados[cont][cont2] = 1; } ta manio =0; for(String s:alfabeto) { r = obtenerTransicion(cont, s); t = obtenerTr ansicion(cont2, s); if(r.size()>0 && t.size()>0) { tamanio++; y = r.first().intV alue(); 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][con t2] = 1; } } } for(int cont=1;cont<numestados;cont++) { for(int cont2=0;cont2<co nt;cont2++) { if(estados[cont][cont2]==0) f = false; } } return f; } private voi d minimizar() { int[][] estados = new int[numestados][numestados]; TreeSet<Integ er> r; TreeSet<Integer> t; int x; int y; int tamanio =0; for(int cont=1;cont<num estados;cont++) { for(int cont2=0;cont2<cont;cont2++) { if((estadoFinal.contains (cont)&&!estadoFinal.contains(cont2))||(est adoFinal.contains(cont2)&&!estadoFin al.contains(cont))) { estados[cont][cont2] = 1; } tamanio =0; for(String s:alfab eto) { r = obtenerTransicion(cont, s); t = obtenerTransicion(cont2, s); if(r.siz e()>0 && t.size()>0) { tamanio++; x = r.first().intValue(); y = t.first().intVal ue(); 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> vec tor = 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][con t2] == 0) { ts = new TreeSet<Integer>(); f = true; ts.add(cont); ts.add(cont2); for(TreeSet<Integer> tsmod: vector) { if(tsmod.contains(cont)||tsmod.contains(co nt)) { 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 TreeS et<Integer>(); ts.add(cont); vector.add(ts); } } TreeSet<Integer>[][] tablaTemp = new TreeSet[vector.size()][alfabeto.size()]; TreeSet<Integer> tran; int t0; Tr eeSet<Integer> t1; for(String s: alfabeto) { for(TreeSet<Integer> tsi:vector) { tran = new TreeSet<Integer>(); for(Integer i:tsi) { tran.addAll(obtenerTransicio n(i, s)); } t0 = vector.indexOf(tsi); t1 = new TreeSet<Integer>(); for(TreeSet<I nteger> 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<I nteger>(); int q00=estadoInicial;

for(TreeSet<Integer> i: vector) { if(i.contains(estadoInicial)) { q00 = vector.i ndexOf(i); } for(Integer ii:estadoFinal) { if(i.contains(ii)) { finales.add(vect or.indexOf(i)); } } } estadoInicial=q00; numestados = vector.size(); estadoFinal = finales; tabtrans = tablaTemp; System.out.println(); } } package Lenguaje.Formal.AFND2AFD.Ventanas; import import import import import im port import import import import import import import import import import impor t import Lenguaje.Formal.AFND2AFD.Logica.Transformador; Lenguaje.Formal.AFND2AFD .Modelo.Automata; Lenguje.Formal.AFND2AFD.Util.PanelFondo; com.mycsistemas.swing ec.button.RoundtButton; java.awt.Color; java.awt.Dimension; java.awt.Font; java. awt.Toolkit; java.awt.event.ActionEvent; java.awt.event.ActionListener; javax.sw ing.ImageIcon; javax.swing.JFrame; javax.swing.JLabel; javax.swing.JOptionPane; javax.swing.JScrollPane; javax.swing.JTextArea; javax.swing.JTextField; javax.sw ing.SpringLayout; /* * To change this template, choose Tools | Templates * and open the template i n the editor. */ /**

* * @author Maricela Maldonado */ public class Ventanita extends JFrame implemen ts ActionListener{ private RoundtButton ingresar= new RoundtButton(); private Ro undtButton ingresaLetrar= new RoundtButton(); private RoundtButton ingresaNEstad os= new RoundtButton(); private RoundtButton ingresaEstadoI= new RoundtButton(); private RoundtButton ingresaEstadoF= new RoundtButton(); private RoundtButton i ngresaTabla= new RoundtButton(); private RoundtButton limpiar= new RoundtButton( ); private JTextArea area=new JTextArea(); private JScrollPane scroll=new JScrol lPane(area); private private private private private JLabel JLabel JLabel JLabel JLabel eti=new JLabel("Ingrese una eti3=new JLabel("Ingrese el eti4=new JLabel( "Ingrese el eti5=new JLabel("Ingrese el eti6=new JLabel("Ingrese la Letra al Alf abeto:"); Numero de Estados:"); Estado Inicial:"); Estado Final:"); Tabla de Tra nsiciones:"); private JLabel eti7=new JLabel("q?"); private JLabel eti8=new JLabel("Letra"); p rivate JLabel eti9=new JLabel("q?"); private JLabel eti2=new JLabel("<html><body ><p align=\"center\">Resultados de la Transformacion</p></body></html>"); privat e JTextField txtIngreso=new JTextField(); private JTextField txtEstadosN=new JTe xtField(); private JTextField txtEstadosI=new JTextField(); private JTextField t xtEstadosF=new JTextField(); private JTextField txtTabla=new JTextField(); priva te JTextField txtTabla2=new JTextField(); private JTextField txtTabla3=new JText Field(); private PanelFondo back=new PanelFondo(); Automata auto=new Automata(); public Ventanita() { initComponents(); setTitle("Convertidor"); Dimension scree nSize = 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//A FND2AFD//Imagenes/ /23.jpg")));

area.setEditable(false); SpringLayout sp=new SpringLayout(); back.setLayout(sp); sp.putConstraint(SpringLayout.NORTH, eti3, 15, SpringLayout.NORTH, back); sp.pu tConstraint(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, ing resaNEstados, 0, SpringLayout.NORTH, eti3); sp.putConstraint(SpringLayout.EAST, ingresaNEstados, -15, SpringLayout.EAST, back); sp.putConstraint(SpringLayout.NO RTH, txtEstadosN, 0, SpringLayout.NORTH, eti3); sp.putConstraint(SpringLayout.WE ST, txtEstadosN, 15, SpringLayout.EAST, eti3); sp.putConstraint(SpringLayout.EAS T, txtEstadosN, -15, SpringLayout.WEST, ingresaNEstados); sp.putConstraint(SpringLayout.NORTH, eti, 15, SpringLayout.SOUTH, eti3); sp.putC onstraint(SpringLayout.WEST, eti, 0, SpringLayout.WEST, eti3); eti.setFont(new F ont("Times New Roman", Font.BOLD, 16)); eti.setHorizontalAlignment(JLabel.CENTER ); eti.setForeground(Color.red); sp.putConstraint(SpringLayout.NORTH, ingresaLet rar, 0, SpringLayout.NORTH, eti); sp.putConstraint(SpringLayout.EAST, ingresaLet rar, -15, SpringLayout.EAST, back); sp.putConstraint(SpringLayout.NORTH, txtIngr eso, 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, Sp ringLayout.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, b ack); sp.putConstraint(SpringLayout.NORTH, txtEstadosI, 0, SpringLayout.NORTH, e ti4); sp.putConstraint(SpringLayout.WEST, txtEstadosI, 15, SpringLayout.EAST, et i4); sp.putConstraint(SpringLayout.EAST, txtEstadosI, -15, SpringLayout.WEST, in gresaEstadoI); 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.setHorizontalAli gnment(JLabel.CENTER); eti5.setForeground(Color.red); sp.putConstraint(SpringLay out.NORTH, ingresaEstadoF, 0, SpringLayout.NORTH, eti5); sp.putConstraint(Spring Layout.EAST, ingresaEstadoF, -15, SpringLayout.EAST, back); sp.putConstraint(Spr ingLayout.NORTH, txtEstadosF, 0, SpringLayout.NORTH, eti5); sp.putConstraint(Spr ingLayout.WEST, txtEstadosF, 15, SpringLayout.EAST, eti5); sp.putConstraint(Spri ngLayout.EAST, txtEstadosF, -15, SpringLayout.WEST, ingresaEstadoF); sp.putConst raint(SpringLayout.NORTH, eti6, 15, SpringLayout.SOUTH, eti7); sp.putConstraint( SpringLayout.WEST, eti6, 15, SpringLayout.WEST, back); eti6.setFont(new Font("Ti mes New Roman", Font.BOLD, 16)); eti6.setHorizontalAlignment(JLabel.CENTER); eti 6.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, tx tTabla2, 0, SpringLayout.NORTH, txtTabla);

sp.putConstraint(SpringLayout.WEST, txtTabla2, -30, SpringLayout.EAST, txtTabla2 ); sp.putConstraint(SpringLayout.EAST, txtTabla2, -15, SpringLayout.WEST, txtTab la); sp.putConstraint(SpringLayout.NORTH, txtTabla3, 0, SpringLayout.NORTH, txtT abla2); sp.putConstraint(SpringLayout.WEST, txtTabla3, -30, SpringLayout.EAST, t xtTabla3); 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, txtTabla 3); eti7.setFont(new Font("Times New Roman", Font.BOLD, 16)); eti7.setHorizontal Alignment(JLabel.CENTER); eti7.setForeground(Color.red); sp.putConstraint(Spring Layout.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.setFo reground(Color.red); sp.putConstraint(SpringLayout.NORTH, eti9, 15, SpringLayout .SOUTH, eti5); sp.putConstraint(SpringLayout.WEST, eti9, 5, SpringLayout.WEST, t xtTabla); eti9.setFont(new Font("Times New Roman", Font.BOLD, 16)); eti9.setHori zontalAlignment(JLabel.CENTER); eti9.setForeground(Color.red); sp.putConstraint( SpringLayout.NORTH, eti2, 10, SpringLayout.SOUTH, eti6); sp.putConstraint(Spring Layout.WEST, eti2, 0, SpringLayout.WEST, eti); sp.putConstraint(SpringLayout.EAS T, 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, limpi ar, -15, SpringLayout.SOUTH, back); sp.putConstraint(SpringLayout.EAST, limpiar, 0, SpringLayout.EAST, eti2); sp.putConstraint(SpringLayout.NORTH, scroll, 10, S pringLayout.SOUTH, eti2); sp.putConstraint(SpringLayout.WEST, scroll, 0, SpringL ayout.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"); i ngresaNEstados.setText("Ingresar"); ingresaEstadoI.setText("Ingresar"); ingresaE stadoF.setText("Ingresar"); ingresaTabla.setText("Ingresar"); limpiar.setText("L impiar Campos"); eti2.setFont(new Font("Times New Roman", Font.BOLD, 16)); eti2. setHorizontalAlignment(JLabel.CENTER); eti2.setForeground(Color.red); ingresar.a ddActionListener(this); ingresaLetrar.addActionListener(this); ingresaNEstados.a ddActionListener(this); ingresaEstadoI.addActionListener(this); ingresaEstadoF.a ddActionListener(this); ingresaTabla.addActionListener(this); limpiar.addActionL istener(this); back.add(eti); back.add(txtIngreso); back.add(ingresaLetrar); bac k.add(eti3); back.add(txtEstadosN); back.add(ingresaNEstados); back.add(eti4); b ack.add(txtEstadosI); back.add(ingresaEstadoI); back.add(eti5); back.add(txtEsta dosF); back.add(ingresaEstadoF); back.add(eti6); back.add(txtTabla); back.add(tx tTabla2); back.add(txtTabla3); back.add(eti7); back.add(eti8); back.add(eti9); b ack.add(ingresaTabla); back.add(eti2); back.add(ingresar); back.add(limpiar); ba ck.add(scroll); getContentPane().add(back); } public void actionPerformed(Action Event e) {

if(e.getSource().equals(ingresaLetrar)){ if(txtIngreso.getText().equals("")){ JO ptionPane.showMessageDialog(this, "Ingrese una letra al alfabeto","Error",JOptio nPane.ERROR_MESSAGE); }else{ auto.addLetraAlfabeto(txtIngreso.getText()); area.a ppend(txtIngreso.getText()+"\t"); txtIngreso.setText(""); } }else if(e.getSource ().equals(limpiar)){ txtIngreso.setText(""); area.setText(""); }else if(e.getSou rce().equals(ingresaNEstados)){ try { int numeros = Integer.parseInt(txtEstadosN .getText()); area.append("Numero de estados: "+numeros+"\n"); auto.setnumEstados (numeros); txtEstadosN.setEditable(false); } catch (NumberFormatException number FormatException) { JOptionPane.showMessageDialog(this, "Ingrese un numero valido ","Error",JOptionPane.ERROR_MESSAGE); } }else if(e.getSource().equals(ingresaEst adoI)){ try { int numeros = Integer.parseInt(txtEstadosI.getText()); area.append ("\nEstado Inicial : "+numeros); auto.setEstadoInicial(numeros); txtEstadosI.set Editable(false); } catch (NumberFormatException numberFormatException) { JOption Pane.showMessageDialog(this, "Ingrese un numero valido","Error",JOptionPane.ERRO R_MESSAGE); } }else if(e.getSource().equals(ingresaEstadoF)){ try { int numeros = Integer.parseInt(txtEstadosF.getText()); area.append("\nEstado Final: "+numero s); auto.addEstadoFinal(numeros); txtEstadosF.setText(""); } catch (NumberFormat Exception 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(numero s, txtTabla2.getText(), numeros2); area.append("\nTransisicion: "+numeros+"\t\t" +txtTabla2.getText()+"\t"+numeros2); txtTabla.setText("");

txtTabla2.setText(""); txtTabla3.setText(""); } catch (NumberFormatException num berFormatException) { JOptionPane.showMessageDialog(this, "Ingrese un numero val ido","Error",JOptionPane.ERROR_MESSAGE); } }else if(e.getSource().equals(ingresa r)){ Transformador trans=new Transformador(); area.append("\nAutomata Finito no Determinista\n"+auto); area.append("\nAutomata Finito Determinista\n"+trans.mini mizar(auto)); } } public static void main (String []er){ new Ventanita(); } }

Das könnte Ihnen auch gefallen