[英]How do I pass file path to command line arguements when using “open with” in Windows?
I'm new here so I'm not sure I'm doing anything wrong so please do tell me if I am. 我是新来的,所以不确定自己做错了什么,所以请告诉我我是否在。
I'm making a simple image/gif viewer in Java. 我正在用Java创建一个简单的图像/ gif查看器。 I want to be able to use the extracted application (which I will wrap in an .exe with launch4j) to open image files. 我希望能够使用提取的应用程序(该应用程序将与launch4j包装在.exe中)来打开图像文件。 When choosing the image to open with it, I want it to get the file path of the image and pass it to args[0] so that the application can use it. 选择要打开的图像时,我希望它获取图像的文件路径并将其传递给args [0],以便应用程序可以使用它。
I'm sensing this is something that needs to be done outside of my Java code. 我感觉到这是需要在Java代码之外完成的事情。 Maybe in an installer or the wrapper I'm using but I have no idea how to do it. 也许在我正在使用的安装程序或包装程序中,但我不知道该怎么做。
I've been searching the past 3 hours to no avail. 我一直在搜索过去3小时无济于事。 Any help is appreciated. 任何帮助表示赞赏。 My code so far: 到目前为止,我的代码:
public class MainWindow {
private JFrame frame1;
public static String imageLocation = null;
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Throwable e) {
e.printStackTrace();
}
try {
imageLocation = args[0];
} catch (Exception e1) {
e1.printStackTrace();
System.exit(0);
}
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainWindow window = new MainWindow();
window.frame1.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public MainWindow() {
initialize();
}
private void initialize() {
BufferedImage img = null;
try{
img = ImageIO.read(new File(imageLocation));
}catch (IOException e) {
e.printStackTrace();
}
int imgWidth = img.getWidth();
int imgHeight = img.getHeight();
frame1 = new JFrame();
frame1.getContentPane().setBackground(Color.WHITE);
frame1.setResizable(false);
frame1.setTitle(imageLocation);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.getContentPane().setLayout(new BorderLayout(0, 0));
frame1.setBounds(200, 200, imgWidth+18, imgHeight+40);
JLabel imgLabel = new JLabel("");
imgLabel.setToolTipText(imageLocation);
imgLabel.setHorizontalAlignment(SwingConstants.CENTER);
imgLabel.setIcon(new ImageIcon(imageLocation));
imgLabel.setBounds(0, 0, frame1.getWidth(), frame1.getWidth());
frame1.getContentPane().add(imgLabel);
}
}
Thanks in advance. 提前致谢。
I don't see any form elements to upload files. 我看不到任何要上传文件的表单元素。 Not an expert in JForms but I believe you need a file upload control that will pass its value to the args array in your code. 不是JForms的专家,但我相信您需要一个文件上传控件,该控件会将其值传递给代码中的args数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.