Java 当我按下按钮时,JFrame冻结了
我正在制作一个加密程序,由于某种原因,当我按下按钮时,程序完全冻结。我不确定出了什么问题,因为我以前做过很多简单的GUI,我从来没有遇到过这个问题。这是按钮的空白处:Java 当我按下按钮时,JFrame冻结了,java,Java,我正在制作一个加密程序,由于某种原因,当我按下按钮时,程序完全冻结。我不确定出了什么问题,因为我以前做过很多简单的GUI,我从来没有遇到过这个问题。这是按钮的空白处: private void btnEncryptActionPerformed(java.awt.event.ActionEvent evt) { String origMessage = txtDInput.getText();
private void btnEncryptActionPerformed(java.awt.event.ActionEvent evt) {
String origMessage = txtDInput.getText();
String encMessage = "";
String revMessage = "";
String extraStg1 = "";
String extraStg2 = "";
char tempChar;
char tempExtraChar;
int tempAscii;
int tempExtraAscii;
for (int i = origMessage.length() - 1; i >= 0; i = i--) //reverses message
{
revMessage = revMessage + origMessage.charAt(i);
}
for (int i = 0; i < revMessage.length(); i = i++)
{
tempChar = revMessage.charAt(i); //stores character in the tempChar variable
tempAscii = (int)tempChar; //converts the character into an Ascii value
tempAscii = tempAscii + 3; //adds 3 to Ascii value
tempChar = (char)tempAscii; //converts Ascii value back into a character value
encMessage = encMessage + tempChar; //adds the new character to the encrypted string and repeats for every character
}
for (int i = 0; i <= 7; i++)
{
tempExtraAscii = (int)Math.round(Math.random()*25+1+96); //generates a random integer between 97 and 122
tempExtraChar = (char)tempExtraAscii; //convert the random integer into a character
extraStg1 = extraStg1 + tempExtraChar; //add the extra character to tempExtraStg1
}
for (int i = 0; i <= 7; i++)
{
tempExtraAscii = (int)Math.round(Math.random()*25+1+96); //generates a random integer between 97 and 122
tempExtraChar = (char)tempExtraAscii; //convert the random integer into a character
extraStg2 = extraStg2 + tempExtraChar; //add the extra character to tempExtraStg2
}
encMessage = extraStg1 + encMessage + extraStg2;
txtEncrypted.setText(encMessage);
}
private void btnEncryptActionPerformed(java.awt.event.ActionEvent evt){
String origMessage=txtDInput.getText();
字符串encMessage=“”;
字符串revMessage=“”;
字符串extraStg1=“”;
字符串extraStg2=“”;
char tempChar;
炭黑;
int-tempAscii;
int-tempExtraAscii;
for(int i=origMessage.length()-1;i>=0;i=i--)//反转消息
{
revMessage=revMessage+origMessage.charAt(i);
}
for(int i=0;i
for(int i=0;i
i=i++
是一个无操作-它增加i
,但随后将其设置回原始值,因此循环将永远执行。只需将其更改为:
for(int i=0;i
实际上,您在前面遇到了相同的问题:
for(int i=origMessage.length()-1;i>=0;i=i--)
应该是
for(int i=origMessage.length()-1;i>=0;i--)
(顺便说一句,这并不是一种真正有用的“加密”,你也不应该使用自己的加密,但我已经回答了这个问题。)这就是问题所在:
for(int i=0;i
i=i++
是一个无操作-它增加i
,但随后将其设置回原始值,因此循环将永远执行。只需将其更改为:
for(int i=0;i
实际上,您在前面遇到了相同的问题:
for(int i=origMessage.length()-1;i>=0;i=i--)
应该是
for(int i=origMessage.length()-1;i>=0;i--)
(顺便说一句,这并不是一种真正有用的“加密”,你也不应该使用自己的加密,但我已经回答了这个问题。)啊……就是这样。它现在可以工作了。这是一个多么愚蠢的错误,尤其是因为我在代码的其他部分中使用了正确的方法。非常感谢你的帮助。是的,我知道它不是特别有用,但该程序只是用于一个学校项目。只需对它进行凯撒加密,并添加其他层,如反转它和添加不相关的额外字符呃。用户可以输入一条消息并对其进行加密,然后他们可以输入加密的消息并对其进行解密。我现在就做这部分,所以如果我遇到任何问题,希望你也能帮我解决。哈哈……就是这样。它现在起作用了。这是一个多么愚蠢的错误,尤其是因为我在代码的其他部分中使用了正确的方法。T非常感谢你的帮助。是的,我知道它不是特别有用,但这个程序只是用于学校项目。只需对它进行Caesar加密,并添加其他层,如反转和添加不相关的额外字符。用户可以输入消息并对其进行加密,然后他们可以输入加密的消息并对其进行解密。我很高兴如果我遇到任何问题,希望你也能帮我。我的魔杖说你的程序中有一个无限循环。你为什么要这样做?for(int I=origMessage.length()-1;I>=0;I=I--)无限循环。我的魔杖说你的程序中有一个无限循环。你为什么要这样做?for(int i=origMessage.length()-1;i>=0;i=i--)无限循环。