我的问题是,我正在通过终端运行一些 adb 命令。我写了一个工具;这将有助于使事情变得更容易。所以回到问题,为了让命令运行,我必须在终端上输入一个“密码”。那么我该怎么做才能使“密码”部分出现在 JOptionPane.showInputDialog 框中?
这是我到目前为止所拥有的:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
public class flash implements ActionListener {
private File runfile;
@Override
public void actionPerformed(ActionEvent arg0) {
{
JFileChooser adbflashfile = new JFileChooser("/home/local/ANT/arthm/Desktop/os");
FileNameExtensionFilter filter = new FileNameExtensionFilter(".py", "py");
adbflashfile.setFileFilter(filter);
int returnVal = adbflashfile.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
runfile = adbflashfile.getSelectedFile();
try {
Runtime.getRuntime().exec("sudo python ./flashimage.py");
} catch (IOException e1) {
e1.printStackTrace();
}
//This is where a real application would open the file.
System.out.println("File: " + runfile.getName() + ".");
} else {
JOptionPane.showMessageDialog(null, "Open command cancelled by user.");
}
System.out.println(returnVal);
}
};
}