好的,所以我有这个代码:
package coding.language;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Launcher extends JFrame
{
private static final long serialVersionUID = 1L;
JPanel jp = new JPanel();
static JLabel jl = new JLabel();
static String[] input;
JTextField jt = new JTextField(30);
public static String a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,q,p,r,s,t,v,w,x,y,z;
Scanner sc = new Scanner(System.in);
public Launcher()
{
setTitle("Cypher");
setVisible(true);
setSize(400, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
jp.add(jt);
jt.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
input = jt.getText().split("\\s+");
coding();
}
});
jp.add(jl);
add(jp);
}
public static void main(String[] args)
{
Launcher t = new Launcher();
}
public static void coding()
{
for(int za = 0;za<input.length;za++)
{
int size = input[za].length();
switch(size)
{
case 0:
System.out.println("You need to type in a longer input");
break;
case 1:
a = input[za];
jl.setText(code(a)+" ");
break;
case 2:
a = input[za].substring(0,1);
b = input[za].substring(1,2);
jl.setText(code(a)+code(b)+" ");
break;
case 3:
a = input[za].substring(0,1);
b = input[za].substring(1,2);
c = input[za].substring(2,3);
jl.setText(code(a)+code(b)+code(c)+" ");
break;
case 4:
a = input[za].substring(0,1);
b = input[za].substring(1,2);
c = input[za].substring(2,3);
d = input[za].substring(3,4);
jl.setText(code(a)+code(b)+code(c)+code(d)+" ");
break;
case 5:
a = input[za].substring(0,1);
b = input[za].substring(1,2);
c = input[za].substring(2,3);
d = input[za].substring(3,4);
e = input[za].substring(4,5);
jl.setText(code(a)+code(b)+code(c)+code(d)+code(e)+" ");
break;
case 6:
a = input[za].substring(0,1);
b = input[za].substring(1,2);
c = input[za].substring(2,3);
d = input[za].substring(3,4);
e = input[za].substring(4,5);
f = input[za].substring(5,6);
jl.setText(code(a)+code(b)+code(c)+code(d)+code(e)+code(f)+" ");
break;
case 7:
a = input[za].substring(0,1);
b = input[za].substring(1,2);
c = input[za].substring(2,3);
d = input[za].substring(3,4);
e = input[za].substring(4,5);
f = input[za].substring(5,6);
g = input[za].substring(6,7);
jl.setText(code(a)+code(b)+code(c)+code(d)+code(e)+code(f)+code(g)+" ");
break;
case 8:
a = input[za].substring(0,1);
b = input[za].substring(1,2);
c = input[za].substring(2,3);
d = input[za].substring(3,4);
e = input[za].substring(4,5);
f = input[za].substring(5,6);
g = input[za].substring(6,7);
h = input[za].substring(7,8);
jl.setText(code(a)+code(b)+code(c)+code(d)+code(e)+code(f)+code(g)+code(h)+" ");
break;
case 9:
a = input[za].substring(0,1);
b = input[za].substring(1,2);
c = input[za].substring(2,3);
d = input[za].substring(3,4);
e = input[za].substring(4,5);
f = input[za].substring(5,6);
g = input[za].substring(6,7);
h = input[za].substring(7,8);
i = input[za].substring(8,9);
jl.setText(code(a)+code(b)+code(c)+code(d)+code(e)+code(f)+code(g)+code(h)+code(i)+" ");
break;
case 10:
a = input[za].substring(0,1);
b = input[za].substring(1,2);
c = input[za].substring(2,3);
d = input[za].substring(3,4);
e = input[za].substring(4,5);
f = input[za].substring(5,6);
g = input[za].substring(6,7);
h = input[za].substring(7,8);
i = input[za].substring(8,9);
j = input[za].substring(9,10);
System.out.print(code(a)+code(b)+code(c)+code(d)+code(e)+code(f)+code(g)+code(h)+code(i)+code(j)+" ");
break;
}
}
}
public static String code(String string)
{
switch(string)
{
case "a": string = "z";
break;
case "b": string = "y";
break;
case "c": string = "x";
break;
case "d": string = "w";
break;
case "e": string = "v";
break;
case "f": string = "u";
break;
case "g": string = "t";
break;
case "h": string = "s";
break;
case "i": string = "r";
break;
case "j": string = "q";
break;
case "k": string = "p";
break;
case "l": string = "o";
break;
case "m": string = "n";
break;
case "n": string = "m";
break;
case "o": string = "l";
break;
case "p": string = "k";
break;
case "q": string = "j";
break;
case "r": string = "i";
break;
case "s": string = "h";
break;
case "t": string = "g";
break;
case "u": string = "f";
break;
case "v": string = "e";
break;
case "w": string = "d";
break;
case "x": string = "c";
break;
case "y": string = "b";
break;
case "z": string = "a";
break;
}
return string;
}
}
我的问题是如何更改方法 coding() 中的 setText() 函数,以便一次显示超过 1 个单词?我的意思是如果写了 2 个字,代码会将第一个字打印到屏幕上,然后打印第二个,但您看不到第一个字。