Wednesday, November 21, 2007

Java: DII Character Simulator Update #3

I started to attach JTextFields, JComboBoxes and so forth between the different tabbedpanels. While doing so it started to get quite confusing as to what variables needed to be modified when a component's value changed. There was quite a bit of references between tabbedpanels and at this point I had to stop. I had plans of separating the Skills panel into seven separate panels, one for each character type. Since I was starting to reference variables from the Skills panel for the Stats panel, that separation had to be done before anything else.

This was not simple by any means. Each character received a variable in the Skills panel that is called when the corresponding value is chosen in the JComboBox for character selection. Originally I wanted to simply have these character panels extend JPanel and create a panel that is automatically added to the main program. As it turned out, an easier way was to pass a panel from Skills to the character sub-panel and allow that panel to be the framework for the character skill display.

After that is was simply a matter of copying the first character panel into 6 more copies and changing a few variable names. Along with this the Save button that was initially used to populate the characterField JTextField in the Stats panel was removed. The logic behind the button was Incorporated into the character panels. This lead to a new problem, a NullPointerException error occurs when the program is launched. NullPointerException occurs for one of a few reasons:
  • Calling the instance method of a null object
  • Accessing or modifying the field of a null object
  • Taking the length of null as if it were an array
  • Accessing or modifying the slots of null as if it were an array
  • Throwing null as if it were a Throwable value
In this case the second option was the culprit. The Skills panel is initialized before the Stats panel and Skills is giving the Stats variable characterField a value. It would have been possible to remove characterField from Stats and initialize it in Skills instead, but since that variable has nothing to do with the Skills panel that was avoided. Instead the solution was to change the order of the tabbedpanel creation. Stats would be generated first, followed by Skills and then lastly by Equipment.

With that out of the way the listeners for all 210 JComboBoxes in Skills had to be created and then linked to associated int arrays to store the selected data. While time consuming, it wasn't extremely difficult to do. In the end I was also able to put in checks to ensure that a skill wasn't assigned points if it's requirements did not already have points assigned. If that is the case an error message is generated.


This basically finished off the groundwork for the Skills tab. All that is left is to locate the equations that govern each of the 210 skills and create a separate method for each. These equations must be stored somewhere, I'm hoping the good folks at Diabloii.net will be able to point me in the right direction. I'm hoping it is an equation that drives each skill. If not then I'll have to store each skills values in an array of arrays and then create my own equation to generate the necessary information.

Once this is done I'll have a standalone skill calculator ready to go.

No comments: