java - 多个文本输入和按钮 Java
问题描述
我正在制作一个运行 Caeser Cipher 的 Java 程序。我创建了 2 种使用 Caeser Cipher 进行编码和解码的方法,它们就在这里。
//encoder method
public static String encoder(String text, int shift)
{
String alpha = "abcdefghijklmnopqrstuvwxyz";
String total = "";
for (int i = 0; i < text.length(); i++)
{
String temp = text.substring(i, i + 1);
if (!temp.equalsIgnoreCase(" "))
{
int e = alpha.indexOf(temp);
e += shift;
if (e >= 26)
e -= 26;
total += alpha.substring(e, e + 1);
}
else
total += " ";
}
return total;
}
//decoder method
public static String decoder(String text, int shift)
{
String alpha = "abcdefghijklmnopqrstuvwxyz";
String total = "";
for (int i = 0; i < text.length(); i++)
{
String temp = text.substring(i, i + 1);
if (!temp.equalsIgnoreCase(" "))
{
int e = alpha.indexOf(temp);
e -= shift;
if (e <= 0)
e += 26;
total += alpha.substring(e, e + 1);
}
else
total += " ";
}
return total;
}
我正在尝试创建一个提示 2 个文本框的程序:每个文本框旁边都有文本,上面写着“输入文本:”和“班次编号:”。在那些文本输入框下,我想要 2 个显示编码和解码的按钮。每个盒子都会运行相应的方法。我是创建 JPanels 和 JOptionPane 的新手,我已经查看了几天,但我仍然感到困惑。在我添加的课程之前:
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
我从 Stack Overflow 上的另一个问题中发现了这一点,但我仍然感到困惑。
谢谢!
解决方案
推荐阅读
- python-3.x - 将json文件转换为数组的python字典
- javascript - 有没有办法在不提交表单的情况下从前端检查数据库中的电子邮件 ID 和旁边的值?
- python - 从 CSV 读取数据帧并将其存储以供将来使用
- elastalert - 如何修复“ImportError:没有名为错误的模块”
- javascript - 在 python bokeh 中将文件从客户端上传到服务器
- matlab - 如何在 Matlab 中将不规则单元格转换为字符串或字符向量
- ios - 在更短的时间内过滤数据
- javascript - Jquery Slider 在移动设备上不起作用
- php - 在 tcpdf 的 writeHtml 中只获取一条记录
- javascript - 如何在 macOS 预览应用程序中使用 JavaScript for Automator (JXA) 保存图像?