Netbeans is a GUI tool used to write Java programs. Every now and then I like to dabble in Java, writing small programs to improve my Java knowledge. For the past couple of day's I've been thinking that I need to dust off my Java and write something that is useful, relevant, and instructional.
So, I chose to do a very small project that has two jLists, three jButtons, and a jText for output. One of the jLists contains the names of several Hawaiian Islands, the other has "737-1, 737-2, ,737-3, 737-4". jButton one is for "go", the second jButton is to "clear", the third jButton is "quit". The jText area is to display various textual items while the program runs. What the output should look like is:
Kauai 737-1
Oahu 737-1
Maui 737-1
Lanai 737-1
Molokai 737-1
Hawaii 737-1
Then, repeats with the other 737's, -2 through -4.
Using the Netbeans GUI, it is fairly easy to create the GUI, create and populate the jList's, add and rename the three jButtons, and add that jText area. Using the "Properties" for each of these elements, having Netbeans add in the EventListener code is not that straight forward and to master Netbeans, this would take a lot of repetition. The jList EventListeners took the longest to figure out. Well, once the GUI and EventListeners were up and running, time to move to part two. Being able to get those selections from the jList's and do something with them. That turned out to be a challenge.
Seem's (which is fine), the EventListener code that is generated are of type,
//private void ClearButtonActionPerformed(java.awt.event.ActionEvent evt).
The private void functions are just that, private functions. The various data inside them are private to that function. Well, the information I need is in that function, just how will I be able to access these strings and take them out of this function. Answer is, use a Vector data type that is defined outside of all private functions. Using Netbeans, the only place to put publicly accessible datatypes such as a Vector is outside all called functions. So I created the below Vector datatype, so I can load in all the information (Strings) from both jLists into a a vSite and vSat Vector. These code snippet's do not capture everything, I hope you can get the idea. It's fairly straight forward.
//Vector vSite=new Vector();
So, now, the Vectors have been created. Not quite done yet. In order for that "private void" to put information into the vSite and vSat Vectors, the below function needed to be written,
//public void addSiteSatObject(int i, Object o){
//System.out.println("addSatObject:"+"type: " +i +" "+o);
//j++;
//String s;
//s=o.toString();
// sites is the 1, sat is the 2
//if(i == 1) vSite.add(s);
//if(i == 2) vSat.add(s);
//System.out.println("addSatObject:"+"type: " +s+" "+j);
//}
then invoked from inside,
//private void ClearButtonActionPerformed(java.awt.event.ActionEvent evt).
With that up and running, continued on by putting together a function to dump the contents of both Vectors to the System.out.println.
//public void dumpSiteSatObject(){
// v.size() inform number of elements in Vector
//System.out.println("Vector vSite Size :"+vSite.size());
//System.out.println("Vector vSat Size :"+vSat.size());
// get elements of Vector
//for(int i=0;i
// System.out.println("Vector Element "+i+" :"+v.get(i));
//}
//for(int j = 0; j < vSat.size(); j++){
//for(int i = 0; i < vSite.size(); i++){
//System.out.println(vSite.elementAt(i)+" "+vSat.elementAt(j));
//}
//}
//}
Overall, the biggest challenge was figuring out the EventListeners for the jList's, then, being able to access the data from the jLists which are inside private voids. There is still a problem. I'm getting duplicate Islands. So if I choose one Island, my output has two of the same, like "Kauai, Kauai". But that is cool, we'll get that one next time.