View Single Post
  #1 (permalink)  
Old 10-07-2008, 09:50 PM
furry furry is offline
Member
 
Join Date: Oct 2008
Posts: 3
furry is on a distinguished road
getSize() issue - Displaying object in 3 locations in Applet
Hello,

I have been going nuts trying to figure this out but have had absolutely no luck so I figured I'd come here and ask for help. If anyone could point me in the right direction that would be INCREDIBLE.

I am trying to draw 3 peace signs inside of a Java Applet with one being in the top left corner, one in the center, and one in the bottom right corner. The location of the signs are supposed to remain in the same location even if the Applet is resized, so Ive been trying to base them on getSize(), but do not think I am doing it right. I have yet to figure out how to get the lines inside of the circle, but am going to worry about that after I get the circles in the correct locations. Again, any help would be GREATLY appreciated!

Thanks in advance!

Code:
// This applet displays 3 peace signs, one in the top left corner, // one in the bottom right corner, and one in the center. All // are based on getSize(). A motto is also displayed in the // bottom left hand side of the applet. import java.awt.*; import java.applet.*; public class test1 extends Applet { public void init() { Color myColor; myColor = new Color(0, 0, 0); //Sets color to black setBackground(myColor); Color myColorA; myColorA = new Color(155, 155, 0); //Sets color to yellow setForeground(myColorA); } public void paint(Graphics g) { //Sets the width and height of the applet Dimension d = getSize(); int centerX = d.width/2; int centerY = d.height/2; int widthOfPicture = 200; int heightOfPicture = 200; int x = centerX - widthOfPicture/2; int y = centerY - heightOfPicture/2; //Declares myColor as a new color (yellow) Color myColor1; myColor1 = new Color(155, 155, 0); //Sets color to yellow g.setColor(myColor1.brighter()); //Draws a peace sign in upper left corner Dimension e = getSize(); int ulX = e.width +50; int ulY = e.height +50; int x1 = centerX; int y1 = centerY; //int widthOfPicture1 = 200; //int heightOfPicture1 = 200; g.drawArc(x1,y1,50,50,-360,360); //Draws a peace sign in the center Dimension f = getSize(); int centerX2 = f.width/45; int centerY2 = f.height/150; g.drawArc(centerX2, centerY2,50,50,-360,360); //g.drawLine(100,150,117,142); //Draws a peace sign in the lower right corner Dimension h = getSize(); int centerX3 = h.width-50; int centerY3 = h.height-50; g.drawArc(centerX3, centerY3,50,50,-360,360); //g.drawLine(100,150,117,142); //Sets Lucida as the new font in 18pt bold g.setFont(new Font("Lucida", Font.BOLD, 22)); //Declares myColor1 as a new color (white) Color myColor2; myColor2 = new Color(255, 255, 255); //Sets color to white g.setColor(myColor2.brighter()); //Displays a text string message g.drawString("Make Love, Not War!", 10, 580); } }
Reply With Quote
Sponsored Links