necesito ayuda para que las variables de txtfield solo acepten letras ademas de porque no funcioa el try cathc correctamente
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Ingenieria extends Applet implements ActionListener {
int D = 0;
Button btnComprobar = new Button("Comprobar");
Button btnlimpiar = new Button("Limpiar");
Button btnSalir = new Button("Salir");
TextField txtfor = new TextField (3);
TextField txtVar = new TextField (3);
TextField txtSimbolo = new TextField (3);
TextField txtRangInicial = new TextField (3);
TextField txtto = new TextField (3);
TextField txtRangFinal = new TextField (3);
TextField txtdo = new TextField (3);
public void init() {
setSize(1000, 500);
add(txtfor);
add(txtVar);
add(txtSimbolo);
add(txtRangInicial);
add(txtto);
add(txtRangFinal);
add(txtdo);
add(btnComprobar);
add(btnlimpiar);
add(btnSalir);
btnComprobar.addActionListener(this);
btnlimpiar.addActionListener(this);
btnSalir.addActionListener(this);
}
public void paint(Graphics g) {
g.drawLine(50, 137, 100, 137);
g.drawLine(100, 137, 90, 125);
g.drawLine(100, 135, 90, 150);
g.drawOval(100, 100, 75, 75);
g.drawString("q0", 130, 140);
g.drawString("" + D, 198, 130);
g.drawLine(175, 137, 230, 137);
g.drawLine(229, 137, 219, 125);
g.drawLine(229, 137, 219, 150);
g.drawOval(230, 100, 75, 75);
g.drawString("q1", 260, 140);
g.drawString("" + D, 327, 130);
g.drawLine(306, 137, 360, 137);
g.drawLine(360, 137, 350, 125);
g.drawLine(360, 137, 350, 150);
g.drawArc(378, 60, 40, 90, 0, 180);
g.drawLine(429, 83, 419, 105);
g.drawLine(400, 83, 419, 107);
g.drawOval(360, 100, 75, 75);
g.drawString("q2", 390, 140);
g.drawString("" + D, 456, 130);
g.drawString("" + D, 415, 70);
g.drawLine(435, 137, 490, 137);
g.drawLine(489, 137, 481, 125);
g.drawLine(489, 137, 481, 150);
g.drawOval(490, 100, 75, 75);
g.drawString("q3", 520, 140);
g.drawString("" + D, 585, 130);
g.drawLine(565, 137, 620, 137);
g.drawLine(620, 137, 612, 125);
g.drawLine(620, 137, 612, 150);
g.drawArc(638, 60, 40, 90, 0, 180);
g.drawLine(689, 83, 678, 105);
g.drawLine(661, 83, 679, 107);
g.drawOval(620, 100, 75, 75);
g.drawString("q4", 650, 140);
g.drawString("" + D, 718, 130);
g.drawString("" + D, 677, 70);
g.drawLine(695, 137, 750, 137);
g.drawLine(751, 137, 741, 125);
g.drawLine(751, 137, 741, 150);
g.drawArc(769, 61, 40, 90, 0, 180);
g.drawLine(820, 83, 810, 105);
g.drawLine(791, 83, 810, 107);
g.drawOval(750, 100, 75, 75);
g.drawString("q5", 780, 140);
g.drawString("" + D, 847, 130);
g.drawString("" + D, 807, 70);
g.drawLine(825, 137, 880, 137);
g.drawLine(881, 137, 871, 125);
g.drawLine(881, 137, 871, 150);
g.drawOval(880, 100, 75, 75);
g.drawOval(892, 113, 50, 50);
g.drawString("q6", 910, 140);
//Lineas Verticales
g.drawRect(50, 200, 750, 250);
g.drawLine(125, 200, 125, 450);
g.drawLine(200, 225, 200, 450);
g.drawLine(275, 225, 275, 450);
g.drawLine(350, 225, 350, 450);
g.drawLine(425, 225, 425, 450);
g.drawLine(500, 225, 500, 450);
g.drawLine(575, 225, 575, 450);
g.drawLine(650, 225, 650, 450);
g.drawLine(725, 200, 725, 450);
//Lineas Horizontales
g.drawLine(125, 225, 725, 225);
g.drawLine(50, 250, 800, 250);
g.drawLine(50, 275, 800, 275);
g.drawLine(50, 300, 800, 300);
g.drawLine(50, 325, 800, 325);
g.drawLine(50, 350, 800, 350);
g.drawLine(50, 375, 800, 375);
g.drawLine(50, 400, 800, 400);
g.drawLine(50, 425, 800, 425);
}
public void actionPerformed(ActionEvent evento) {
if (evento.getSource()==btnComprobar){
int[] i=new int[7];
try{
String f1=txtfor.getText();
String f3=txtSimbolo.getText();
String f5=txtto.getText();
String f7=txtdo.getText();
if(f1.equals("For")){
JOptionPane.showMessageDialog(null, "Comprobando For ¡¡Correcto!!","Comprobando...",JOptionPane.INFORMA TION_MESSAGE);
txtfor.setEditable(false);
i[0]=1;
}
else{
JOptionPane.showMessageDialog(null, "Comprobando For ¡¡INCORRECTO!!","Comprobando...",JOptionPane.INFOR MATION_MESSAGE);
}
JOptionPane.showMessageDialog(null, "Comprobando i ¡¡Correcto!!","Comprobando...",JOptionPane.INFORMA TION_MESSAGE);
txtVar.setEditable(false);
i[1]=i[0]+1;
if(f3.equals(":=")){
JOptionPane.showMessageDialog(null, "Comprobando := ¡¡Correcto!!","Comprobando...",JOptionPane.INFORMA TION_MESSAGE);
txtSimbolo.setEditable(false);i[2]=i[1]+1;
}
else{
JOptionPane.showMessageDialog(null, "Comprobando := ¡¡INCORRECTO!!","Comprobando...",JOptionPane.INFOR MATION_MESSAGE);
}
JOptionPane.showMessageDialog(null, "Comprobando Rango de Inicio ¡¡Correcto!!","Comprobando...",JOptionPane.INFORMA TION_MESSAGE);
txtRangInicial.setEditable(false);
i[3]=i[2]+1;
if(f5.equals("to")){
JOptionPane.showMessageDialog(null, "Comprobando to ¡¡Correcto!!","Comprobando...",JOptionPane.INFORMA TION_MESSAGE);
txtto.setEditable(false);i[4]=i[3]+1;
}
else{
JOptionPane.showMessageDialog(null, "Comprobando to ¡¡INCORRECTO!!","Comprobando...",JOptionPane.INFOR MATION_MESSAGE);
}
JOptionPane.showMessageDialog(null, "Comprobando Rango Final ¡¡Correcto!!","Comprobando...",JOptionPane.INFORMA TION_MESSAGE);
txtRangFinal.setEditable(false);
i[5]=i[4]+1;
if(f7.equals("do")){
JOptionPane.showMessageDialog(null, "Comprobando do ¡¡Correcto!!","Comprobando...",JOptionPane.INFORMA TION_MESSAGE);
txtdo.setEditable(false);i[6]=i[5]+1;
}
else{
JOptionPane.showMessageDialog(null, "Comprobando do ¡¡INCORRECTO!!","Comprobando...",JOptionPane.INFOR MATION_MESSAGE);
}
if(i[6]=='5'){
JOptionPane.showMessageDialog(null, "¡¡SENTENCIA CORRECTA!!","Comprobando...",JOptionPane.INFORMATI ON_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null, "¡¡SENTENCIA INCORRECTA!!","Comprobando...",JOptionPane.INFORMA TION_MESSAGE);
}
}
catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "¡¡SENTENCIA INCORRECTA!!","Comprobando...",JOptionPane.INFORMA TION_MESSAGE);
}
}
if (evento.getSource()==btnlimpiar){
btnComprobar.setEnabled(true);
txtfor.setText("");
txtVar.setText("");
txtSimbolo.setText("");
txtRangInicial.setText("");
txtto.setText("");
txtRangFinal.setText("");
txtdo.setText("");
txtfor.setEditable(true);
txtVar.setEditable(true);
txtSimbolo.setEditable(true);
txtRangInicial.setEditable(true);
txtto.setEditable(true);
txtRangFinal.setEditable(true);
txtdo.setEditable(true);
repaint();
}
if (evento.getSource()==btnSalir){
System.exit(1);
}
}
}