GeSHi (java):
import java.awt.Container;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
/*--------------------------------------------------------------------------
//Author List:
// deAppel <Creator>
//
//Description:
// My demo that displays an image using the commandline interface.
//
//Environment:
// This software was developed using Eclipse and Java 1.6
//
//Copyright Information:
// Copyright (C) 2007 <Institution><None>
// Ark de Appel www.engineeringserver.com
//
//----------------------------------------------------------------------*/
public class ChooseImage
extends JFrame{
public void testImage(){ //show demo image, not needed now..
//Container c = getContentPane();
add(showImage);
setTitle("My Image number: DEMO");
pack();
setLocationRelativeTo(null);
setVisible(true);
}
public void showImageGui(int a){
//Container c = getContentPane();
add(showImage);
setTitle("My Image number: " + a);
pack();
setLocationRelativeTo(null);
setVisible(true);
toFront(); //show image to front.
}
public static void main
(String[] args
){ /* Not needed anymore
* System.out.println("First version:");
* MyString m = new MyString();
* m.testImage();
*/
//second version
System.
out.
println("Second version:");
try {
for(;;){
System.
out.
print("# Enter image number: ");
try{
String askNumber = br.
readLine();
//System.out.println("get: " + askNumber); Extra output not needed anymore
int b =
Integer.
parseInt(askNumber
);
ChooseImage mm = new ChooseImage();
f =
new File("" + myString
);
//Check file existence before continuing. if (f.exists()){
System.
out.
println("# loading: " + myString +
"\n");
mm.showImageGui(b);
}
else{
System.
out.
println("# Image not found.\n");
}
}
System.
out.
println("# Please enter a number");
}
}//end infinite forloop
}
}
}
}
Created by GeSHI 1.0.7.20
Works with *.gif files but should be able to work with png or other formats.
Output:Second version:
# Enter image number: 19
# Image not found.
# Enter image number: 1
# loading: c:\1.gif