I'm trying to run a jar file but have got 2 problems:
I can only run it from cmd and not by double clicking on it - Have exported it as a runnable jar file from Eclipse and I've installed java runtime enviroment. When I double click on it nothing happens
The image I've imported in eclipse isn't exported the project
The jar file has to ask for a username/password and then open an image but it can't.
Code:
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class OpenImage {
public static void main(String[] args){
String un;
int pass;
Image image = null;
System.out.println("Welcome, please enter the username and password to open the image");
Scanner scan = new Scanner(System.in);
System.out.println("Username?:");
un = scan.nextLine();
System.out.println("Password?:");
pass = scan.nextInt();
if(un.equals("Hudhud") && pass==123){
System.out.println("");
System.out.println("Here you got the picture");
try{
File sourceimage = new File("index.jpg");
image = ImageIO.read(sourceimage);
}
catch (IOException e){
e.printStackTrace();
}
JFrame frame = new JFrame();
frame.setSize(300, 300);
JLabel label = new JLabel(new ImageIcon(image));
frame.add(label);
frame.setVisible(true);
}
else{
System.out.println("You ain't the boss");
}
}
}
This is my project: http://www.filedropper.com/capture