The Artima Developer Community
Sponsored Link

Java Answers Forum
Loop Program Crashes.Why?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
DAYO

Posts: 22
Nickname: done
Registered: Jun, 2002

Loop Program Crashes.Why? Posted: Jul 3, 2002 6:18 PM
Reply to this message Reply
Advertisement
I am trying to write a java program
that models a while.But keeps crashing.
To test it i wrote the following in
the textfield :
T1[0]=1(i.e Textfield contains 1)
This prints "start" onto a label
T1[1]=2
increments x
T1[2]=3
checks if x<0 and goes back to T1[1]
T1[3]=4
Stops the loop
Here is part of the code.
Any idea why?
//x and i are both global variables
private class testahandler implements ActionListener
{ public void actionPerformed(ActionEvent event)
{ x=-6;
for(i=0;i<4 && stop=false;i++)
{ if(T1.getText().equals(""))
{ JOptionPane.showMessageDialog(
null, "Empty Box" , "ERROR",
JOptionPane.ERROR_MESSAGE);
return;
}
else
{ int OPC=(int)(Integer.parseInt(T1.getText()));
OBEY(OPC);
}
}
}
}
public void OBEY(int op)
{ switch(op)
{ case 1:labels.setText("start");
break;
case 2:x=x+1;
break;
case 3:
if(x<0)
i=1;
break;
case 4:
stop=true;
break;
default:

}
}

Topic: can I call a c++ function ? Previous Topic   Next Topic Topic: Help Me Please WIth Java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use