So i have this input.txt file, and there are 5 entries in it, I want to take each entry( in the format of Image1.jpg, Image2,jpg, etc) and store it into an arraylist. Then use java GUI to display each image by clicking a button, from image1 to image5.
First I stored each image name into an arraylist:
The input file:
Test1.jpg
Test2.jpg
Test3.jpg
Test4.jpg
Test5.jpg
The code to store these into arrayList:
try{
BufferedReader inputFile = new BufferedReader(new FileReader(filename));
String temp="";
List<String> names = new ArrayList<String>();
while ((temp=inputFile.readLine()) != null)
{
names.add(temp);
}
String[] stringArray = names.toArray(new String[0]);
String testOne = stringArray[0];
String testTwo = stringArray[2];
String testThree = stringArray[4];
String testFour = stringArray[6];
String testFive = stringArray[8];
//System.out.println(testOne);
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
testOne - testFive are the 5 image's names
But i am stuck on how to make a button that will update by click, first time clicking will give me image1, then if i click again, it will show image 2, then if i click again, it will show image 3 and so on.. I already have the GUI layout done, just not sure what to put under the event for the click.
private void jButtonActionPerformed(java.awt.event.ActionEvent evt) {
// ?
}
any help?