Why is the grid not lining up properly?

relevant code:
     private static final int SCREEN_WIDTH = 640;
     private static final int SCREEN_HEIGHT = 640;
     private final int[][] a;
     private final int width;
     private final int height;
     private final int boxSizeX;
     private final int boxSizeY;
     private final int startX;
     private final int startY;
     private final char[]answer;
     private boolean userAnswer;
public project3main(int[][] array, int boxsize, char[]answer, boolean userAnswer) {
          this.a=array;//the array representing the walls
          this.width = a[0].length;
          this.height = a.length;
          this.answer = answer;
          this.setPreferredSize(new Dimension(SCREEN_WIDTH,SCREEN_HEIGHT));
          this.boxSizeX = (SCREEN_WIDTH)/(width+2);
          this.boxSizeY = (SCREEN_HEIGHT)/(height+2);
          this.startX = boxSizeX/2;
          this.startY = boxSizeY/2;
          this.userAnswer = userAnswer;
     public void paintComponent(Graphics g) {
          //draw the ceiling
               this.a[height-1][this.a[height-1].length-1] = SOUTH_WALL;
               g.drawLine(this.boxSizeX, this.boxSizeY, (SCREEN_WIDTH-(this.boxSizeX)), this.boxSizeY);     
               g.drawLine(this.boxSizeX, this.boxSizeY+this.boxSizeY, this.boxSizeX, (SCREEN_HEIGHT-(this.boxSizeY)));     
               int currY=this.boxSizeY;
               int currX=this.boxSizeX;
               for(int i=0;i<this.height;i++)
                    currY = (this.boxSizeY)*(i+1);
                    for(int j=0;j<this.width;j++)
                         currX = (this.boxSizeX)*(j+1);
                         if(a[i][j] == EAST_WALL)
                              g.drawLine(currX+this.boxSizeX, currY, currX+this.boxSizeX, currY+this.boxSizeY);
                         else if(a[i][j] == SOUTH_EAST_WALL)
                              g.drawLine(currX+this.boxSizeX, currY, currX+this.boxSizeX, currY+this.boxSizeY);
                              g.drawLine(currX, currY+this.boxSizeY, currX+this.boxSizeX, currY+this.boxSizeY);
                         else if(a[i][j] == SOUTH_WALL)
                              g.drawLine(currX, currY+this.boxSizeY, currX+this.boxSizeX, currY+this.boxSizeY);
               }basically, this takes in a matrix which is filled with integers that represent if each node has a south, east, or a combination of the two.
It creates a standard box-size relative to the width of the screen and the height of the screen (set at 640 for each)
It then draws the ceiling and the left wall.
However, the ceiling and the left wall do not line up. That is, the outside wall does not occur at the rightmost point of the ceilling.
Can anyone see why just by looking at the code?
further code furnished upon request
Edited by: thenextbesthang on May 4, 2008 10:03 AM

thenextbesthang wrote:
how do you post a jframe?? You just make a minimal JFrame and post the code:
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class FooFrame
    private static final int EAST_WALL = 0; // TODO change as appropriate
    private static final int SOUTH_WALL = 0; // TODO change as appropriate
    private static final int SOUTH_EAST_WALL = 0; // TODO change as appropriate
    private static int SCREEN_WIDTH = 640;
    private static int SCREEN_HEIGHT = 640;
    private int[][] a =
        // TODO put in reasonable numbers here.
    private int width;
    private int height;
    private int boxSizeX;
    private int boxSizeY;
    private int startX;
    private int startY;
    //private char[] answer;
    //private boolean userAnswer;
    public FooFrame()
        width = a[0].length;
        height = a.length;
        //this.answer = answer;
        //this.setPreferredSize(new Dimension(SCREEN_WIDTH, SCREEN_HEIGHT));
        boxSizeX = (SCREEN_WIDTH) / (width + 2);
        boxSizeY = (SCREEN_HEIGHT) / (height + 2);
        startX = boxSizeX / 2;
        startY = boxSizeY / 2;
        //userAnswer = userAnswer;
    public JPanel createMyPanel()
        JPanel panel = new JPanel()
            @Override
            protected void paintComponent(Graphics g)
                super.paintComponent(g);
                myPaint(g);
        panel.setPreferredSize(new Dimension(SCREEN_WIDTH, SCREEN_HEIGHT));
        return panel;
    private void myPaint(Graphics g)
        a[height - 1][a[height - 1].length - 1] = SOUTH_WALL;
        g.drawLine(boxSizeX, boxSizeY,
            (SCREEN_WIDTH - (boxSizeX)), boxSizeY);
        g.drawLine(boxSizeX, boxSizeY + boxSizeY, boxSizeX,
            (SCREEN_HEIGHT - (boxSizeY)));
        int currY = boxSizeY;
        int currX = boxSizeX;
        for (int i = 0; i < height; i++)
            currY = (boxSizeY) * (i + 1);
            for (int j = 0; j < width; j++)
                currX = (boxSizeX) * (j + 1);
                if (a[i][j] == EAST_WALL)
                    g.drawLine(currX + boxSizeX, currY, currX
                        + boxSizeX, currY + boxSizeY);
                else if (a[i][j] == SOUTH_EAST_WALL)
                    g.drawLine(currX + boxSizeX, currY, currX
                        + boxSizeX, currY + boxSizeY);
                    g.drawLine(currX, currY + boxSizeY, currX
                        + boxSizeX, currY + boxSizeY);
                else if (a[i][j] == SOUTH_WALL)
                    g.drawLine(currX, currY + boxSizeY, currX
                        + boxSizeX, currY + boxSizeY);
    public static void main(String[] args)
        JFrame frame = new JFrame("Foo Frame");
        frame.getContentPane().add(new FooFrame().createMyPanel());
        frame.pack();
        frame.setVisible(true);
}

Similar Messages

  • Why is the map not displaying correctly on "find my phone"  I am getting large grid squares on the map

    why is the map not displaying correctly on "find my phone"  on my computer.  I am getting large grid squares on the map.  I have tried deleting my history, tried zooming in & out, but the grid squares won't go away..

    Welcome to Apple Support Communities
    It means that it is not connected to the Internet, so it may be turned off. Another option would be that somebody has resetted it to default settings and has changed the Apple ID, being impossible to track your son's iPhone. Anyway, report it to the police because it is the only thing you can do at the moment

  • I had to restore my computer. After reinstalling itunes and sincronizing with my ipod, the music files were not organized in itunes as in the ipod: some songs were missing, some albums has no cover? Why is the sincronization not working properly?

    I had to restore my computer. After reinstalling itunes and sincronizing with my ipod, the music files were not organized in itunes as in the ipod: some songs were missing, some albums has no cover? Why is the sincronization not working properly?

    See Recover your iTunes library from your iPod or iOS device.
    tt2

  • The printer is not lined up properly on portrait orientation.

    HP Photo smart 7520  The printer is not lined up properly on portrait orientation. The margin at the top is too high and chops off all but the bottom portion of the letters on the website address. On Word all of my documents are set to close to the top with a larger margin at the bottom than the set up calls for.
    Windows 7 Professional

    Please check the paper size loaded in the printer input tray, the size requested from application (document size) and the paper size configured in the printer drivers.
    Please mark the post that solves your problem as Accepted Solution
    Click the 'Kudos Thumbs Up' if this was helpful. Thank You!
    (Although I am an HP employee, I am speaking for myself and not for HP)

  • One column in check remittance of smartform not lined up properly...

    I created a check form, and it has 4 columns in the remittance advice portion of the check.  One of the columns is not lining up properly, and is about a half line below where it needs to be lined up, anybody have ideas?

    Hi Daniel,
    Try to display the columns using the patterns for the line types in the template/table accordingly.
    Regards,
    Sravanthi

  • I can no longer edit the info for my songs, movies and tv shows.  This occurred since I loaded Windows 7 Pro on my C drive, and then fownloaded ITunes 10.  Why will the program not allow me to access the track info to edit it?

    I can no longer edit the info for my songs, movies and tv shows.  This occurred since I loaded Windows 7 Pro on my C drive, and then fownloaded ITunes 10.  Why will the program not allow me to access the track info to edit it?

    Ah yes school boy error there out of frustration and discontent..
    My issue is with music/apps/films etc not downloading from iTunes / App Store.
    They initially fail and message is displayed stating unable to download / purchase at this time, yet if I retry it says I've already purchased (?) or alternatively I go to the purchased section and there they are waiting with the cloud symbol..
    However some items get frozen in the download window and cannot be retried or deleted. Message appears stating to tap to retry, but even if you stole every bath and sink in the uk you'd still not have enough taps.
    I post here as the iTunes guys are useless in there 'help' and have only advised posting here or phoning apple, at my expense, to explain a problem that could be rectified by forwarding my original email to a techie. However the tech team apparently don't have an email address as they're from ye olde Middle Ages..!
    Anyways I digress.
    So I tried sync to pc, but instead of showing the file as ready to listen/use/view, the iCloud symbol shows and I'm back to square one as the item is unable to download..
    At frustration station waiting for a train from pain...
    All my software is up to date, and had all worked fine prior to the last big iOS update that resulted in all the changes in display and dismay.
    Answers in a postcard :-)
    Much love

  • Why is the app not available for my device?

    I've no problem using BT wifi on my device (Nook BNTV400) so why is the app not available for that device? It's not like the nook is proprietory, everything else I've tried to find in the play store works fine.
    Is the apk available for download direct from bt?

    if you can connect to btwifi without the app then I wouldn't bother trying to find the apk file
    if you have an android smartphone then you can download the app and get the apk file to sideload on to your nook
    If you like a post, or want to say thanks for a helpful answer, please click on the Ratings star on the left-hand side of the post.
    If someone answers your question correctly please let other members know by clicking on ’Mark as Accepted Solution’.

  • Why is the text not the visible in the protected PDF opened on Mac?

    Long story short:
    I've created a document in Microsoft Word 2010 and saved it as PDF. With the .pdf open now in Acrobat Reader 9.4.1 I have enabled the protection over the .pdf file by only allowing Printing and saved the protected .pdf. All of these actions are made on Windows 7 machine. Now when trying to open the protected .pdf on Mac (with Snow Leopard 10.6.6 and Preview) the .pdf opened only shows the lines and bullets but not the text.
    Why is the text not visible in the protected PDF opened on Mac?
    (is this bug or a "feature"?)
    Note: the protected .pdf looks good on Windows 7 and it works on Mac if the .pdf has no protection.
    Thanks!

    A. What application are you using to add the protection? Reader cannot add any file security and I don't think the PDF feature of Word will either.
    B. Mac Preview has issues with PDF standards so there may be some features that you will experience issues with that have no workarounds.
    C. Have you checked the file after adding security to see if all fonts are embedded?

  • Why are the iPhotos not listed in the finder?

    why are the iPhotos not listed in the finder?

    There are many, many ways to access your files in iPhoto:   You can use any Open / Attach / Browse dialogue. On the left there's a Media heading, your pics can be accessed there. Command-Click for selecting multiple pics.
    (Note the above illustration is not a Finder Window. It's the dialogue you get when you go File -> Open)
    You can access the Library from the New Message Window in Mail:
    There's a similar option in Outlook and many, many other apps.  If you use Apple's Mail, Entourage, AOL or Eudora you can email from within iPhoto.
    If you use a Cocoa-based Browser such as Safari, you can drag the pics from the iPhoto Window to the Attach window in the browser.
    If you want to access the files with iPhoto not running:
    For users of 10.6 and later:  You can download a free Services component from MacOSXAutomation  which will give you access to the iPhoto Library from your Services Menu.
    Using the Services Preference Pane you can even create a keyboard shortcut for it.
    For Users of 10.4 and 10.5 Create a Media Browser using Automator (takes about 10 seconds) or use this free utility Karelia iMedia Browser
    Other options include:
    Drag and Drop: Drag a photo from the iPhoto Window to the desktop, there iPhoto will make a full-sized copy of the pic.
    File -> Export: Select the files in the iPhoto Window and go File -> Export. The dialogue will give you various options, including altering the format, naming the files and changing the size. Again, producing a copy.
    Show File:  a. On iPhoto 09 and earlier:  Right- (or Control-) Click on a pic and in the resulting dialogue choose 'Show File'. A Finder window will pop open with the file already selected.    3.b.
    b: On iPhoto 11 and later: Select one of the affected photos in the iPhoto Window and go File -> Reveal in Finder -> Original. A Finder window will pop open with the file already selected.

  • Why is the template not being used when dynamic page called ?

    Hi,
    I have created a dynamic page and assigned a template to it. When I call the dynamic page using the 'show' procedure from a form, I do not see the template.
    Why is the template not being used ? How can I get the template working when I call the dynamic page ?
    I even tried to show the page from the dynamic page's manage components tab and there is same problem. Template is not being used.
    thanks,
    Mainak

    You can alter the generated package body to include the following function in the header and footer sections.
    Header:
    PORTAL.wwv_headings.show_header(
    p_template => 'PUBLIC.TEMPLATE_3',
    p_heading => 'Dynamic Page',
    p_help_link => 'PORTAL_DEMO.EXAMPLE_DYNAMIC_PAGE.help',
    p_about_link => 'PORTAL_DEMO.EXAMPLE_DYNAMIC_PAGE.about');
    Footer:
    PORTAL.wwv_headings.show_footer(
    p_template => 'PUBLIC.TEMPLATE_3',
    p_help_link => 'PORTAL_DEMO.EXAMPLE_DYNAMIC_PAGE.help');
    where
    <PORTAL_DEMO> indicates application schema
    <PORTAL> indicates the name of the portal (normally this will be portal30 by default).

  • Why does the charger not charge my battery?  I just bought and installed a new battery from Apple (direct) today

    Why does the charger not charge my battery?  I just bought and installed a new battery from Apple (direct) today

    yes, the charger was working before. 
    so far i have:
    1.  updated my software
    2.  updated to battery 1.2
    3.  took off the "duck" plug and used the macbook pro cord that was provided
    4.  checked and cleaned the pins on the magsafe
    5. checked and cleaned the magsafe port
    any ideas?  i appreciate your response!

  • Why does the trash not fully empty?

    Why does the trash not fully empty?

    try this:
    in the finder, choose empty trash from the finder menu while holding the option key.
    if that doesn't work, see this article on how to resolve Trash Problems.

  • Why Does the iPhone not send/receive MMS?

    Why Does the iPhone not send/receive MMS? this in the works?

    "Why Does the iPhone not send/receive MMS?"
    Apple chose not to offer this as a feature of iphone. E-mail can accomplish the same thing.
    "is in the works?"
    This has been asked and answered countless times. The forum search bar is on the right side of this page.
    Apple has announced that MMS will be included in the 3.0 software due out this summer. Before you ask, all that has been announced is in this link:
    http://www.apple.com/iphone/preview-iphone-os/
    Apples developer conference begins tomorrow.

  • Why does the page not move smothe when i scroll?

    Why does the page not move smothe when i scroll?
    Sometimes it even move slower then i Scroll?
    I use a Mac and i have tried to reinstall the program.

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    In Firefox 4 [http://kb.mozillazine.org/Safe_mode Safe mode] disables extensions and disables hardware acceleration.
    * Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    See:
    * [[Troubleshooting extensions and themes]]

  • Why did the trace NOT show the other switches in between?

    I have a PC that is connected to a switch (A) in a network. Switch A has many switches in between and connects to another switch B. When I did a trace to the server, the last switch I see in the result is switch B. Also, when I checked to which port of switch B that the server was connected, It showed as Po1. When I did a show cdp neighbor for the interfaces for the interfaces involved inthe bundle, I get a switch and then another. Why did the trace NOT show the other switches in between? Why did I get an arp on Switch B? Could some one explain?

    It's hard to tell, but if you have L2 switches, the addresses on those L2 switches are for management purposes only and you won't see a response from a trace. The only time you'll see a response is when the packet is routed between devices and not switched. You'll get an arp request/response across a single vlan. If you have vlan 10 across 10 switches, all 10 switches will see an arp request because they're broadcasted throughout the whole vlan.
    HTH,
    John
    *** Please rate all useful posts ***

Maybe you are looking for

  • Graphics card

    I've recently upgraded my graphics card, which works fine. It has two mini display ports and one dvi. I've decided i want to run a dual display setup using my old monitor. Can I reinstall my old card and run the vga monitor off that? I daren't instal

  • Blackberry Logo on Facebook

    When I post on Facebook, The Blackberry logo appears to the left of the timestamp on my post. Is this by default? I have seen posts that just say "via Blackberry". I was wondering if there is a setting to not show the BB logo. I downloaded the Facebo

  • Drawing a Box with many rectangles inside

    I've been trying to make an applet that has 100 equally defined rectangles going across. They will have different shades going from light to dark. This is what I have gotten so far: import java.applet.Applet; import java.awt.Graphics; import java.awt

  • Help me download a free trial of MS Project 2013

    Thank you, Malcolm510

  • Re: No ASMLIB for Unbreakable Enterprise Kernel - over-sight or ASMLib death?

    Hi, I originally resurrected a years-old thread that was down in the Oracle Linux forum that was vaguely related to my question but a kind forum moderator split my post away to let it stand on its own -- then moved it to the RAC installation forum wh