Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Screen Size Question



A simple example which demonstrates how to draw using Insets:

// Draw an inverted triangle
public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;

Dimension d = getSize();

Insets insets = this.getInsets();

int top = insets.top;
int left = insets.left;
int bottom = d.height - insets.bottom;
int right = d.width - insets.right;

// int triWidth = d.width - (insets.left + insets.right );
// int triHeight = d.height - (insets.top + insets.bottom);
int triWidth = right - left;
int triHeight = bottom - top;

int[] x = { left, right, (left + right)>>1 };
int[] y = { top , top , bottom };

Polygon triangle = new Polygon(x, y, 3);

g2d.setPaint(Color.yellow);
g2d.fillPolygon(triangle);

g2d.setPaint(Color.red);
g2d.draw(triangle);

System.out.println("Window width : " + d.width );
System.out.println("Window height: " + d.height );
System.out.println("Triangle width : " + triWidth );
System.out.println("Triangle height: " + triHeight);
}
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.