aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Khalid exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Khalid exam" Watch "Khalid exam" New topic
Author

Khalid exam

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Everybody,
What is the height in pixels for the following rectangle ?
g.drawRect(5,5,10,10);
I thought it is 10. But the given answer was 11.
Can anybody explain this ? If possible, please quote from Java API or books.
cheers
Sankar
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
This is explained very clearly in the book of Khalid..if the rect is fill it is 10, if it isn't fill it is 11..
Aamir
Rose
Greenhorn

Joined: Sep 08, 2002
Posts: 6
Friends,
What is meant by 10 and 11?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi,
Amir might be saying that incase of fillrect() it might be 10 and in case of drawRect it might be 11.
iMO for drawRect it is definetly 11 check this program out. this is because drawRect(5,5,10,10) would mean the width is 5-6-7-8-9-10-11-12-13-14-15. which is 11. same is the case for the length. uncomment the portions for drawRect to check this out.

import java.awt.event.*;
import java.awt.*;
class JxFrame extends Frame
{
public JxFrame(String title){
super(title);
setCloseClick();
}
public static void main(String[] args)
{
JxFrame x = new JxFrame("Demo Application");
x.setSize(200,200);
x.show();
System.out.println("Hello World!");
}
private void setCloseClick(){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void paint(Graphics g){
/*
g.setColor(Color.blue);
g.drawRect(100,100,100,100);
g.setColor(Color.red);
g.drawRect(50,100,50,50);
g.setColor(Color.green);
g.drawRect(100,50,50,50);
*/
g.setColor(Color.blue);
g.fillRect(100,100,100,100);
g.setColor(Color.red);
g.fillRect(50,100,50,50);
g.setColor(Color.white);
g.drawRect(200,100,50,50);
}
}
Hope this helps.
regds.
Rahul.

[This message has been edited by rahul_mkar (edited June 16, 2000).]
 
 
subject: Khalid exam