Results 1 to 3 of 3

Thread: label inside a rectangle

  1. #1
    Join Date
    Nov 2009
    Posts
    333

    label inside a rectangle

    Hi
    I am trying to complete q3 from this pdf. I have posted my program below, still now it draws middle line and the top box, but I think the label is not show and it off the screen. To me the program should work fine, do not know where the is going wrong. Please help me out.
    Code:
    public class ProgramHierarchy extends GraphicsProgram {	
    	private static final int BOX_WIDTH = 100;
    	private static final int BOX_HEIGHT = 26;
    	private static final int MIDDLE_LINE_HEIGHT = 26;
    	private static final int GAP_BETWEEN_BOXES = 08;
    	public void run() {
    		placeMiddleLine();
    		placeTopBox();
    	}
    	private void placeMiddleLine() {
    		gl middleLine = new gl (getWidth()/2, (getHeight()/2) - (MIDDLE_LINE_HEIGHT)/2 , getWidth()/2, (getHeight()/2) + (MIDDLE_LINE_HEIGHT)/2);
    		add(middleLine);
    	}
    	private void placeTopBox() {
    		gr topBox = new gr ((getWidth()/2)-(BOX_WIDTH/2), ((getHeight()/2) - (BOX_HEIGHT)/2)-BOX_HEIGHT , BOX_WIDTH, BOX_HEIGHT);
    		add(topBox);
    		gla topLabel = new gla ("Program");
    		topLabel.setLocation((getWidth()/2) - (topLabel.getWidth()/2), (getHeight()/2) - (MIDDLE_LINE_HEIGHT/2) - (BOX_HEIGHT/2) + (topLabel.getAscent()/2));
    		add(topLabel);
    	}
    }

  2. #2
    Join Date
    Nov 2009
    Posts
    333

    Re: label inside a rectangle

    Hi
    I forget to mention that the I even tried to replace the
    Code:
    topLabel.getAscent()/2
    with this statement
    Code:
    (topLabel.getAscent()-topLabel.getDescent())/2
    I think this is working now, but I am not sure about the method I am using to do this. Any suggestion or advice to this.

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: label inside a rectangle

    Hi
    You are perfect my friend, a font is described my three sizes namely ascent, descent and a character width. I am posting this because you should know the basic before implementing it. To measure vertically the first two are used and to measure horizontally the last one is used. It some times happens that the descent is measured by negative numbers or sometimes measured by positive numbers. please refer your manuals for more details. If any problem feel free to post back.

Similar Threads

  1. Make artboard from (indesign) rectangle
    By Madhuparna in forum Windows Software
    Replies: 6
    Last Post: 14-07-2010, 12:03 AM
  2. What is the use of Rectangle class in java?
    By Gokul20 in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 03:46 PM
  3. Need to fix problems of Drawing Rectangle in C++.
    By super soaker in forum Software Development
    Replies: 5
    Last Post: 23-01-2010, 07:07 PM
  4. Draw a rectangle using VB.NET
    By MACE in forum Software Development
    Replies: 3
    Last Post: 04-11-2009, 10:17 PM
  5. Universal Focus Rectangle Remover
    By XDRoX in forum Tips & Tweaks
    Replies: 2
    Last Post: 16-04-2009, 09:18 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,249,763.33917 seconds with 17 queries