RonO (rono_60103) wrote,

Fun with Java

The DucKon registration program is written in Java. One of its functions is to print the badges, and somehow every year I end up tweaking the badges, at least a bit. This year I did a major tweak. Instead of doing badges that hang in "Portrait" (long way down), with an image located near the center of a white or colored badge, we will have badges that hang in "Landscape" with the image across the entire badge.

One result of this change was that instead of painting colored boarders by drawing a rectangle the size of the whole badge behind the artwork, I have to draw two rectangles of the boarder width down each side of the badge. (I decided early on that having the border on all 4 sides didn't look good, and made it too easy to cover the artwork). This worked well, except for one little problem, it kept printing (on paper, so far -- I haven't had a chance to try on the PVC badge printer) a box about the size of the badge to the right of any badge that had a border.

Off an on for months as I've worked on this, I've tried to figure out why this was happening. Finally today -- while resolving to solve this problem in case it caused the badge printer to print two badges, one just a solid colored badge -- I realized the problem.

I'm now going to get somewhat technical, and will be talking in official programming terms, so be prepared.

To draw the rectangles, I had to instantiate a Rectangle object. The constructor I was using for this takes 4 ints (numbers) as arguments. In all of the previous badges I'd done, these values were the coordinates of one corner, and the coordinates of the other, so I did the same for the new right border.

I finally got a clue when I tried replacing the rectangle with a sequence of lines -- themselves rectangles of zero width -- and got a series of boxes. The boxes were all the same height as the badge, and the total was the same width as the whole badge. What clued me in was that the vertical lines for the box on top of the artwork were closer together than the ones past the right edge. Looking at this, I finally got the "aha" I needed, which I quickly confirmed by checking the online documentation for Java. The parameters to the constructor for a Rectangle aren't the coordinates of two corners, but the coordinate of the upper left hand corner, followed by the length and width. I'd been drawing a rectangle the size of the badge a few pixels from the edge. Once I fixed it so that the width was the width of the border, everything worked perfectly.

I did ask my wife, and she confirmed that she would have made the same guess about how 4 numbers are used to define a rectangle as I had, so at least I don't think I'm too far off in my reasoning.


  • Life Report/Trip Report

    When last I posted way at the other end of this surprisingly long February, I had a job, and a potential house.  Since then, Tara and I have packed…

  • Life Updates

    For the few people who only see my updates from my blog (or LiveJournal which mirrors my blog), here are a couple of updates on my life: 1: I have…

  • Transitions

    This morning, I was called into a meeting with my bosses boss.  As soon as he asked for the meeting, I was pretty sure what the meeting was about,…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded