您好我正在使用Java Swing开发一个程序,并且我有4个选项窗格用于获取某些输入,但是当我运行该程序时它将显示选项窗口,但是当我关闭选项窗格,并运行最后一个按钮,我必须执行程序的其余部分。我目前困惑,为什么。这里是actionPerformed()方法的代码和文件选择器的方法。请注意,选项窗格用于从单选按钮获取输入,而不用选择是或否,因此4检查*方法用于查看单选按钮被按下以及如何处理该信息。JOptionPane正在运行FileChooser
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("settings")) {
JOptionPane.showOptionDialog(null, encryptPanel,
"Settings Choices", JOptionPane.NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null);
}
if (e.getActionCommand().equals("paths")) {
JOptionPane.showOptionDialog(null, pathsPanel,
"Paths Options", JOptionPane.NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null);
}
if (e.getActionCommand().equals("tools")) {
JOptionPane.showOptionDialog(null, toolsPane,
"Tools Options", JOptionPane.NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null);
}
if (e.getActionCommand().equals("techniques")) {
JOptionPane.showOptionDialog(null, methodPane,
"Choose your encryption method", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null);
}
checkEncrypt(e.getActionCommand());
checkPaths(e.getActionCommand());
checkTools(e.getActionCommand());
checkTech(e.getActionCommand());
if (e.getActionCommand().equals("go")) ;
{
runLauncher();
}
}
private void runLauncher()
{
directory.makeDir("PEP");
JFileChooser getFile = new JFileChooser();
getFile.setCurrentDirectory(new File(System.getProperty("user.home")));
int result = getFile.showOpenDialog(this);
String str;
int numWheels = Integer.getInteger(wheels.getText());
if (result == JFileChooser.APPROVE_OPTION) {
str = getFile.getSelectedFile().getAbsolutePath();
int result2 = getFile.showOpenDialog(this);
if (result2 == JFileChooser.APPROVE_OPTION) {
String endFilePath = getFile.getSelectedFile().getAbsolutePath();
if(gOn)
{
launcher go = new launcher(str, endFilePath, numWheels, 5);
go.run();
}
else
{
launcher go = new launcher(str, endFilePath, numWheels, selection);
go.run();
}
}
selection = 0;
}
}
除了你的问题,你有几件事情要做。通常的做法是从大写的类名开始,然后将每个单词的每个首字母大写。即SomeVeryLongClassName。其次,如果你反复调用同样的方法,那么你做错了。调用一次并将其分配给一个变量。例如:String cmd = e.getActionCommand();那么你可以用cmd代替。第三,只有一个命令得到执行,这是说。而不是使用,如果如果...等等,你应该使用,如果否则,如果...等等。现在它没有区别,但很快它会。 – Gacci
我很欣赏我需要修复的错误。仍然必须解决我的其他问题,它与每个JOptionPane运行最后一点位 – Snipeshot101