Hi all,
I am currently trying to develop a java program which has two files
loaded into it. One is for room rumbers which are listed in a combo
box like RM01, RM02, RM03 etc, and the other files has the computer
names which are loaded into the JList like RM01_01, RM01_02, RM02_01,
RM02_02 etc.
What I would like to do is when I click RM01 on the combo box the
JList automatically repopulates with all the computers that start with
RM01 so it would only show the computer names which are RM01_01,
RM01_02 etc.
I have tried this and it is not working properly. What I have got I am
not sure if it is working properly as I can not anything to display
inside the vector for the JList. This is what I have so far. I know
that this is probably completely wrong as I am a newbie to java:
public void lstComputerNamesInitiate() {
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("" +
DataFile.txtNamePath.getText());
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new
InputStreamReader(in));
String strLine = "";
//Read File Line By Line
String computerNaming = strLine;
String startsWith = (String)
cboRoomNumber.getSelectedItem();
System.err.println("startswith: " + startsWith);
while ((strLine = br.readLine()) != null) {
boolean computer = computerNaming.startsWith(startsWith);
System.err.println("boolean: " + computer);
System.out.println("selected room number is: " +
cboRoomNumber.getSelectedItem());
// Print the content on the console
System.out.println(strLine);
String computerName = strLine;
// data.add(computerName);
data.add(computerNaming);
System.out.println("inside the vector is: " + data);
lstComputerNames.setListData();
}
//Close the input stream
in.close();
} catch (Exception e) { //Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
Any help in this matter would be highly appreciated.
Thank you