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

Re: get value from combo box to add data to JList by McKirahan

McKirahan
Mon Dec 03 05:13:28 PST 2007

<christopher_board@yahoo.co.uk> wrote in message
news:8f1f69d1-eb98-412c-9133-e108fcbaea0a@s36g2000prg.googlegroups.com...
> Hi all,
>
> I am currently trying to develop a java program ...

[snip]

Why are you posting a Java question in a VBScript ng?



Re: get value from combo box to add data to JList by mr_unreliable

mr_unreliable
Mon Dec 03 06:03:36 PST 2007

Christopher,

If you _DO_ decide to use vbScript, then I would suggest using
an xml "database". Microsoft provides a convenient xml actX
object for implementing an xml database, with the progid:
"MSXML2.DOMDocument".

I like xml because you can set up your "database" in memory,
and/or write it to disk. You can use the node structure to
contain the room numbers, and sub-nodes to contain the pc
systems located in the rooms. To get the subnodes, you can
access the nodes by name, and then get a collection of
subnodes for display.

You could also use a more formal database (via adodb), but
imho that would be a little over-kill for this app. Also,
you could use the vbScript "dictionary object". With oDic
you could key off the room numbers, and set up the corresponding
dic item as an array of computers. But (again) imho oDic
is a little under-powered, as it would be a little awkward
adding and/or subtracting computers from your computer array.
XML is "just right".

However, if you are determined to stick with Java, then
there are other ng's where you can find better advice than
here.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)


christopher_board@yahoo.co.uk wrote:
> 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