此代码应该执行的主要任务是,一旦我按下按钮,代码就会将输入字符串中的每个字母转换为用户输入的密钥,每个字母都有自己的密钥...我知道这是一个巨大的代码但它使用非常简单的命令,但我不知道它为什么不起作用
private class ReplaceEncBtnHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
String sentence;
String repKeyA; String repKeyB; String repKeyC; String repKeyD;
String repKeyE; String repKeyF; String repKeyG; String repKeyH;
String repKeyI; String repKeyJ; String repKeyK; String repKeyL;
String repKeyM; String repKeyN; String repKeyO; String repKeyP;
String repKeyQ; String repKeyR; String repKeyS; String repKeyT;
String repKeyU; String repKeyV; String repKeyW; String repKeyX;
String repKeyY; String repKeyZ;
sentence = replaceinputTxt.getText();
try{
repKeyA = repKeyTxtA.getText(); repKeyB = repKeyTxtB.getText(); repKeyC = repKeyTxtC.getText();
repKeyD = repKeyTxtD.getText(); repKeyE = repKeyTxtE.getText(); repKeyF = repKeyTxtF.getText();
repKeyG = repKeyTxtG.getText(); repKeyH = repKeyTxtH.getText(); repKeyI = repKeyTxtI.getText();
repKeyJ = repKeyTxtJ.getText(); repKeyK = repKeyTxtK.getText(); repKeyL = repKeyTxtL.getText();
repKeyM = repKeyTxtM.getText(); repKeyN = repKeyTxtN.getText(); repKeyO = repKeyTxtO.getText();
repKeyP = repKeyTxtP.getText(); repKeyQ = repKeyTxtQ.getText(); repKeyR = repKeyTxtR.getText();
repKeyS = repKeyTxtS.getText(); repKeyT = repKeyTxtT.getText(); repKeyU = repKeyTxtU.getText();
repKeyV = repKeyTxtV.getText(); repKeyW = repKeyTxtW.getText(); repKeyX = repKeyTxtX.getText();
repKeyY = repKeyTxtY.getText(); repKeyZ = repKeyTxtZ.getText();
replaceoutputTxt.setText("");
if(repKeyA.isEmpty()||repKeyB.isEmpty()||repKeyC.isEmpty()||repKeyD.isEmpty()||repKeyE.isEmpty()||
repKeyF.isEmpty()||repKeyG.isEmpty()||repKeyH.isEmpty()||repKeyI.isEmpty()||repKeyJ.isEmpty()||
repKeyK.isEmpty()||repKeyL.isEmpty()||repKeyM.isEmpty()||repKeyN.isEmpty()||repKeyO.isEmpty()||
repKeyP.isEmpty()||repKeyQ.isEmpty()||repKeyR.isEmpty()||repKeyS.isEmpty()||repKeyT.isEmpty()||
repKeyU.isEmpty()||repKeyV.isEmpty()||repKeyW.isEmpty()||repKeyX.isEmpty()||repKeyY.isEmpty()||
repKeyZ.isEmpty()){
replaceoutputTxt.setForeground(Color.red);
replaceoutputTxt.setText("You must fill all key elements!");
repKeyTxtA.requestFocusInWindow();
}
else
{
String[] chars = sentence.split("(?!^)");
for(int i = 0; i < sentence.length(); i++)
{
String c = chars[i];
String[] decrypted = replacecipher(c,repKeyA,repKeyB,repKeyC,repKeyD,
repKeyE, repKeyF,repKeyG,repKeyH,repKeyI,repKeyJ,repKeyK,repKeyL,
repKeyM,repKeyN,repKeyO,repKeyP,repKeyQ,repKeyR,repKeyS,repKeyT,
repKeyU,repKeyV,repKeyW,repKeyX,repKeyY,repKeyZ);
String output = Arrays.toString(decrypted);
replaceoutputTxt.append(output);
}
}
}
catch (Exception j)
{
}
}
}
public static String[] replacecipher(String c,String repKeyA,String repKeyB,String repKeyC,String repKeyD,
String repKeyE,String repKeyF,String repKeyG,String repKeyH,String repKeyI,
String repKeyJ,String repKeyK,String repKeyL,String repKeyM,String repKeyN,
String repKeyO,String repKeyP,String repKeyQ,String repKeyR,String repKeyS,
String repKeyT,String repKeyU,String repKeyV,String repKeyW,String repKeyX,
String repKeyY,String repKeyZ)
{
int i = 0;
String letA = "a", letB = "b", letC = "c", letD = "d";
String letE = "e", letF = "f", letG = "g", letH = "h";
String letI = "i", letJ = "j", letK = "k", letL = "l";
String letM = "m", letN = "n", letO = "o", letP = "p";
String letQ = "q", letR = "r", letS = "s", letT = "t";
String letU = "u", letV = "v", letW = "w", letX = "x";
String letY = "y", letZ = "z";
String[] out = c.split("(?!^)");
while (i < 26)
{
if (out[i].equals(letA)){
out[i]=repKeyA;
i++;
}
else if(out[i].equals(letB)){
out[i]=repKeyB;
i++;
}
else if(out[i].equals(letC)){
out[i]=repKeyC;
i++;
}
else if(out[i].equals(letD)){
out[i]=repKeyD;
i++;
}
else if(out[i].equals(letE)){
out[i]=repKeyE;
i++;
}
else if(out[i].equals(letF)){
out[i]=repKeyF;
i++;
}
else if(out[i].equals(letG)){
out[i]=repKeyG;
i++;
}
else if(out[i].equals(letH)){
out[i]=repKeyH;
i++;
}
else if(out[i].equals(letI)){
out[i]=repKeyI;
i++;
}
else if(out[i].equals(letJ)){
out[i]=repKeyJ;
i++;
}
else if(out[i].equals(letK)){
out[i]=repKeyK;
i++;
}
else if(out[i].equals(letL)){
out[i]=repKeyL;
i++;
}
else if(out[i].equals(letM)){
out[i]=repKeyM;
i++;
}
else if(out[i].equals(letN)){
out[i]=repKeyN;
i++;
}
else if(out[i].equals(letO)){
out[i]=repKeyO;
i++;
}
else if(out[i].equals(letP)){
out[i]=repKeyP;
i++;
}
else if(out[i].equals(letQ)){
out[i]=repKeyQ;
i++;
}
else if(out[i].equals(letR)){
out[i]=repKeyR;
i++;
}
else if(out[i].equals(letS)){
out[i]=repKeyS;
i++;
}
else if(out[i].equals(letT)){
out[i]=repKeyT;
i++;
}
else if(out[i].equals(letU)){
out[i]=repKeyU;
i++;
}
else if(out[i].equals(letV)){
out[i]=repKeyV;
i++;
}
else if(out[i].equals(letW)){
out[i]=repKeyW;
i++;
}
else if(out[i].equals(letX)){
out[i]=repKeyX;
i++;
}
else if(out[i].equals(letY)){
out[i]=repKeyY;
i++;
}
else if(out[i].equals(letZ)){
out[i]=repKeyZ;
i++;
}
else{
out[i]="";
i++;}
}
return out;
}
我会感激任何帮助,我为庞大而道歉,但是当我工作时,它是一个超级简单的巨大代码或过于复杂的小代码。我的大脑仍在处理如何做到这两点。 :)