Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 21-11-2009
Member
 
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);
	}
}
Reply With Quote
  #2  
Old 21-11-2009
Member
 
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.
Reply With Quote
  #3  
Old 21-11-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 10:25 AM.