[4424] in java-interest
How to size the graphics of my applet
daemon@ATHENA.MIT.EDU (Michael Mehrle)
Fri Dec 22 20:34:44 1995
Date: Fri, 22 Dec 1995 16:08:07 -0700
To: tribbles@natural.com, java-interest@java.Eng.Sun.COM
From: michael@w3media.com (Michael Mehrle)
Cc: nelson@cs.ualberta.ca
Here's an applet, that draws a bunch of squares and supposedly repaints the
whole thing when it receives the mouseDown() event. I'm trying to get that
thing to resize the graphics when I resize the applet window.
Unfortunatley, the graphcis sticks with the sizes it receives from the HTML
file.
My guess is that the size() component method gets its value from the HTML
<applet> tag, but how do I dynamically pass the current x/y values of my
component (in this case - my applet panel) to my applet?
Any ideas :( ?
import java.awt.*;
import java.applet.*;
public class FiftySquares extends Applet
{
float xA, yA, xB, yB, xC, yC, xD, yD,
xA1, yA1, xB1, yB1, xC1, yC1, xD1, yD1,p,q,r;
int i;
int x_center, y_center;
int v_size;
public void init()
{
x_center = size().width /2;
y_center = size().height /2;
v_size = size().height;
q = (float)0.05;
p = 1 - q;
r = (float)0.95 * v_size;
resize(size().width, size().height);
}
public void paint(Graphics g)
{
xA = xD = x_center - r;
xB = xC = x_center + r;
yA = yB = y_center - r;
yC = yD = y_center + r;
for(i=0; i<50; i++)
{
g.drawLine((int)xA, (int)yA, (int)xB, (int)yB);
g.drawLine((int)xB, (int)yB, (int)xC, (int)yC);
g.drawLine((int)xC, (int)yC, (int)xD, (int)yD);
g.drawLine((int)xD, (int)yD, (int)xA, (int)yA);
xA1= p*xA+q*xB;yA1= p*yA+q*yB;
xB1= p*xB+q*xC;yB1= p*yB+q*yC;
xC1= p*xC+q*xD;yC1= p*yC+q*yD;
xD1= p*xD+q*xA;yD1= p*yD+q*yA;
xA=xA1;xB=xB1;xC=xC1;xD=xD1;
yA=yA1;yB=yB1;yC=yC1;yD=yD1;
}
}
public boolean mouseDown(Event evt, int x, int y)
{
repaint();
return true;
}
}
\\///
[ o-o ]
____________OOOo___(.)___oOOO_______________
http://www.w3media.com/w3media
michael@w3media.com
Tel. 310.441.9599
Fax 310.441.5919
"One man's mundane and desperate existence
is someone else's Technicolor."
-Strange Days-
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com