Image

Imagesugarplumkitty wrote in Imagejava_dev 😊accomplished

Another day, another lab I'm stuck on

I'm using netbeans because it was pretty easy to pick up and it had all the JSP support programs installed with it.

Lab 6
Working with JSP's
Write a program using JSP's to provide an application to simulate message dispatch to cabs. Your application must provide the following features 1. Select a vehicle label from a pre-defined list and dispatch message (80 characters) to one vehicle or multiple vehicle(s). 2. After sending the message display last 10 messages on the form.


I thought I'd finished it until I re-read the description before packaging it up and realized I'd missed the multiple cabbies option. The java.awt.Choice object I'd gotten to work will only do one cabbie. Darn it!

So I've switched to java.awt.List instead and it looks straightforward. I've filled the list with five first names. They display perfectly. I can select them just fine. However, when I try to fill a String array with getSelectedItems() it seems to be giving me addresses or hex values or something. I tried getSelectedIndexes() into an int array instead and got the same result.



Here are the statements that create the List:

list2 = new java.awt.List();
list2.add("George");
list2.add("Jim");
list2.add("Ralph");
list2.add("Earl");
list2.add("Bob");

list2.setMultipleMode(true);
list2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
list2ActionPerformed(evt);
}
});
list2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
list2MouseClicked(evt);
}
});

panel5.add(list2, java.awt.BorderLayout.CENTER);
list2.getAccessibleContext().setAccessibleName("cabbies");


Here are the statements generating my debug lines: cabChoice is defined elsewhere as:

String [] cabChoice;

private void list2MouseClicked(java.awt.event.MouseEvent evt) {
cabChoice = list2.getSelectedItems();
int [] cabIdx = list2.getSelectedIndexes();
System.out.println(" mouse click selected cabbies: " + cabChoice );
System.out.println(" mouse click selected cabbies #s: " + cabIdx );
}



Because I've got the same code in a couple of places for different events, I've put a description on the front of my debug statements so I know which event is triggering it.

mouse click selected cabbies: [Ljava.lang.String;@995a79
mouse click selected cabbies #s: [I@2c35e
mouse click selected cabbies: [Ljava.lang.String;@e49dcd
mouse click selected cabbies #s: [I@1343ed0
mouse click selected cabbies: [Ljava.lang.String;@979e8b
mouse click selected cabbies #s: [I@29ce8c
mouse click selected cabbies: [Ljava.lang.String;@b754b2
mouse click selected cabbies #s: [I@197bb7


Any clues?


Once I get this solved I'm on to the final lab with roughly 24 hours to deadline. I might just make it!

Thanks! This community rocks!