Friday, November 14, 2008

201 demo code for PolygonUI

Here's a file that I made in NetBeans using the Swing GUI palette. It's based on the technique that I found here and shows how to solve our serious UI problems, without really making a crack in the polygonal substance of the homework assignment.

Here's what I did:

  1. Created a new Project / Java / Java Application, changed the default project name, and UNCHECKED the "Create Main Class" checkbox.

  2. Right-clicked on the default package under the Source Packages and changed its name.

  3. Right-clicked on the newly named package and added to it a New JPanel Form. NetBeans created a class file that extends JPanel and tells Java how to customize a panel for my UI.

  4. Added a button, text field, and label for a very rudimentary UI. I changed their names with a right-click in the Inspector at the left: one of the choices on the menu is Change Variable Name.

  5. Added a few variables at the top of the class definition.

  6. Added import statements each time that the NetBeans UI asked me to.

  7. Right-clicked both the panel and the button to add mouse event handlers.

  8. Added main( ) and paintComponent( ) methods to the source.


Having tried many variations with JFrame and JPanel, I decided to just to draw a fake pane that you won't see until the program runs. I have some ideas about more elegant ways to draw on a panel/frame combination, but hey — I needed to get this baby done!

No comments: