Java - Ayuda con un programa GUI que majena eventos

 
Vista:

Ayuda con un programa GUI que majena eventos

Publicado por Jose armando (1 intervención) el 14/05/2006 15:17:32
Estoy haciendo un programa grafico, es un automata que cheque si un comentario de c o c++ escrito en un textfield es valido.
El problema que tengo es al momento de manejar el evento sobre un boton, la funcion donde se hace el proceso no jala bien, ademas de que se debe hacer una simulacion.
por ejemplo si el usuario introduce
//
se debe de poner de otro color el estado q1 y despues el estado q2, y que aparezca un mensaje donde diga que la cadena es aceptada.

import.java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.JOptionPane;

public class AFD extends Frame
{

TextField TInser = new TextField(50);

public AFD()
{
Panel bottomPanel = new Panel();
Panel centerPanel = new Panel();

// TextField TInser = new TextField(50);
Button Ana = new Button("Analizar");

bottomPanel.add(TInser);
bottomPanel.add(Ana);

centerPanel.setLayout( new GridLayout( 1,2 ) );

centerPanel.add( new MiCanvas() );
Panel p = new Panel();
p.setLayout( new BorderLayout() );

setLayout( new BorderLayout() );
add( "South",bottomPanel );
add( "Center",centerPanel );

Ana.addActionListener( new Auditor() );

}

public static void main( String args[] )
{

AFD ventana = new AFD();

ventana.setTitle("Automata Finito Deterministico" );
ventana.setVisible( true );
}

}

class Auditor implements ActionListener
{
public void actionPerformed( ActionEvent e )
{
System.out.print("Boton clickeado.");

//In this place, i need to do a function for doing all the //process of the program

Auditor.Proceso( Graphics g );
}

public void Proceso( Graphics g )
{

String Aux = new String();

Aux = TInser.getText();

int aux;

aux = Aux.length();

char afd[] = new char[aux];

afd = Aux.toCharArray();

do
{

while(afd == ' ' || afd == '\r' || afd == '\n' && afd != '\0')
{
g.fillOval(40,60,40,40);
i++;
}
if(afd == '/')
{
g.fillOval(120, 60, 40, 40);
i++;
if(afd == '/')
{
g.fillOval(200, 60, 40, 40);
i++;
while(afd != '\r' && afd != '\0')
{
g.fillOval(280, 280, 40, 40);
JOptionPane.showMessageDialog(null, " Comentario valido ");
i++;
}
while(afd == '\r' || afd == ' ' || afd == '\n')
{
g.fillOval(280, 280, 40, 40); JOptionPane.showMessage Dialog(null, " Comentario valido ");
i++;
}
}
else if(afd == '*')
{
g.fillOval(200, 200, 40, 40);
i++;
do
{
while(afd != '*' && afd != '\0')
{
g.fillOval(200, 200, 40, 40);
i++;
}
if(afd == '*')
{
g.fillOval(280, 200, 40, 40);
i++;
while(afd == '*')
{
g.fillOval(280, 200, 40, 40);
i++;
}
}
}while(afd != '*' && afd != '/' && afd != '\0');
if(afd == '/')
{
g.fillOval(285, 285, 30, 30);
i++;
while(afd == ' ' || afd == '\r' || afd == '\n')
{
g.fillOval(500, 60, 40, 40);
i++;
}
}
}
}
else
{
while(afd != '\0')
{
i++;
}
}
}while(afd != '\0');
}

}


class MiCanvas extends Canvas
{

String MsgQ0 = new String("q0");
String MsgQ1 = new String("q1");
String MsgQ2 = new String("q2");
String MsgQ3 = new String("q3");
String MsgQ4 = new String("q4");
String MsgQ5 = new String("q5");
String MsgQ6 = new String("q6");


public void paint( Graphics g )
{

g.drawString("Escriba un comentario de C o C++:", 10, 678);

g.setFont( new Font( "Dialog",Font.PLAIN,14 ) );

g.setColor(Color.black);
//Primera linea inicial
g.drawLine(10, 80, 40, 80);

//Segunda linea
g.drawLine(80, 80, 120, 80);

//Tercera linea
g.drawLine(200, 80, 160, 80);

//Cuarta linea
g.drawLine(280, 220, 240, 220);

//Quinta linea
g.drawLine(300, 240, 300, 280);

//ESTADOS DEL AFD

//Primer estado q0
//g.setColor(Color.red);
g.drawOval(40, 60, 40, 40);
g.setColor(Color.red);
g.fillOval(40,60,40,40);
g.drawString( MsgQ0, 52, 85);

//Segundo estado q1
g.setColor(Color.black);
g.drawOval(120, 60, 40, 40 );
g.drawString( MsgQ1, 133, 85 );

//Tercer estado q2
g.drawOval(200, 60, 40, 40 );
g.drawString( MsgQ2, 214 , 85 );

//* Estado final del tercer estado q2*//
g.drawOval(205, 65, 30, 30);

//Cuarto estado q3
g.drawOval(500, 60, 40, 40);
g.drawString( MsgQ3, 513, 85 );

//Quinto estado q4
g.drawOval(200, 200, 40, 40);
g.drawString( MsgQ4, 214, 223 );

//Sexto estado q5
g.drawOval(280, 200, 40, 40);
g.drawString( MsgQ5, 292, 223 );

//Septimo estado q6
g.drawOval(280, 280, 40, 40);
g.drawString( MsgQ6, 292, 305 );

//Estado final q6
g.drawOval(285, 285, 30, 30);

//ARCOS

//Estado q0-q0
g.drawArc(50, 40, 25, 50, 0, 180 );

//**************************************
//Segundo arco q1-q3
g.drawArc( 140, 35, 380, 50, 0, 180 );

//Tercer arco q1-q6
g.drawArc( 100, 45, 380, 270, 143, 127 );

//Cuarto arco q4-q5
g.drawArc( 225, 182, 70, 40, 0, 180 );

//Quinto arco q4-q4
g.drawArc( 200, 220, 35, 40, 147, 230 );

//Sexta arcp q1-q4
g.drawArc(140, 10, 150, 206, 172, 88 );

//Noveno arco q5-q5
g.drawArc(300, 203, 40, 30, 260, 212 );

//Septima arco q3-q6
g.drawArc(235, 30, 310, 310, 239, 155 );

//Octavo arco q2 q2
g.drawArc(220, 63, 40, 30, 260, 212 );

//Noveno arco
g.drawArc(520, 65, 40, 30, 261, 212 );


// Dibujo de los caracteres insertado del comentario
// / q0 q1
g.drawString("/", 100, 75 );

// / q1 q2
g.drawString("/", 180, 75 );

// * q1 q4
g.drawString("*", 136, 160 );

// Complemento de / * q1 q3
g.drawString("[ /, * ]c ", 270, 30 );

// Complemento de / * q5 q4
g.drawString("[ /, * ]c", 240, 175 );

// * q4 q5
g.drawString("*", 255, 222 );

// / q6 q1
g.drawString("/", 260, 310 );

// * q5 q5
g.drawString("*", 345, 225 );

// / q5 q6
g.drawString("/", 305, 260 );

// Complemento de * q4 q4
g.drawString("[ * ]c", 210, 275 );

// Complemento de enter q2 q2
g.drawString("[ Enter ]c", 263, 82);

//Complemento de / q6 q3
g.drawString("[ / ]c", 505, 230 );

// null enter q0 q0
g.drawString("Null, Enter", 35, 35);

//ASCII
g.drawString("ASCII", 565, 84 );

g.drawLine( 35, 75, 40, 80 );
g.drawLine( 35, 85, 40, 80 );

g.drawLine(115,75,120,80);
g.drawLine(115,85,120,80);

g.drawLine(195,75,200,80);
g.drawLine(195,85,200,80);

g.drawLine(125,104,137,100);
g.drawLine(135,110,137,100);

g.drawLine(192,205,200,214 );
g.drawLine(190,215,200,214);

g.drawLine(270,215,280,220);
g.drawLine(270,225,280,220);

g.drawLine(220,190,225,200 );
g.drawLine(235,195,225,200);

g.drawLine(228,245,235,235 );
g.drawLine(242,245,235,235);

g.drawLine(295, 270, 300, 280);
g.drawLine(305, 270, 300, 280);

g.drawLine(325, 227, 316, 233);
g.drawLine(325, 240, 316, 233);

g.drawLine(245, 87, 236, 93);
g.drawLine(245, 97, 236, 93);

g.drawLine(515, 107, 520, 100);
g.drawLine(530, 105, 520, 100);

g.drawLine(510, 55, 520, 60);
g.drawLine(525, 50, 520, 60);

g.drawLine(69,58,76,65);
g.drawLine(81,58,76,65);

g.drawLine(540, 90, 533, 95);
g.drawLine(540, 100, 533, 95);

}

}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder