|
Somebody please help me.... I have made an animated primitive (eg. swan) object and i'm just wonderin how can i include it on the lake applet in a way that it looks like swimming on the lake....
thank you
here's the code:
//LAKE.JAVA//
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
public class Lake extends Applet
implements Runnable
{
public void start()
{
if(A == null)
{
A = new Thread(this);
A.start();
}
}
public void stop()
{
if(A != null)
{
A.stop();
A = null;
}
}
public void run()
{
P = 0;
do
try
{
while(!V)
Thread.sleep(500L);
repaint();
if(++P == 12)
P = 0;
if(++W == X)
W = 0;
Thread.sleep(50L);
}
catch(InterruptedException _ex)
{
stop();
}
while(true);
}
public String getAppletInfo()
{
return "Name: Lake Version 3.0\r\nAuthor: David Griffiths\r\nLake is an applet class which takes in an \r\nimage and reflects it in a virtual lake.\r\nLast compiled: 24 August 1998 at 08:47 \r\nFor more information about this and other applets\r\ngo to http://www.demon.co.uk/davidg/spigots.htm\r\nCreated with Sun JDK 1.1";
}
public Image A()
{
return G;
}
public void Q(Image image)
{
G = image;
Q = image.getWidth(this);
R = image.getHeight(this);
F();
}
public void I(String s)
{
Q(R(s));
}
private Image R(String s)
{
Image image = null;
MediaTracker mediatracker = new MediaTracker(this);
image = getImage(getDocumentBase(), s);
mediatracker.addImage(image, 0);
try
{
mediatracker.waitForID(0);
}
catch(InterruptedException _ex) { }
return image;
}
public Image G()
{
return H;
}
public void C(Image image)
{
H = image;
S = image.getWidth(this);
T = image.getHeight(this);
F();
}
public void P(String s)
{
C(R(s));
}
public String K()
{
return I;
}
public void H(String s)
{
I = s;
}
public URL L()
{
return J;
}
public void O(URL url)
{
J = url;
}
public boolean B()
{
return K;
}
public void M(boolean flag)
{
K = flag;
}
public String[][] getParameterInfo()
{
String as[][] = {
{
"image", "Image", "JPG or GIF file to reflect"
}, {
"overlay", "Image", "JPG or GIF file to use as an overlay"
}, {
"target", "String", "Target frame"
}, {
"hRef", "URL", "URL to link to"
}, {
"rocking", "boolean", "TRUE if boat rocking"
}, {
"", "", ""
}
};
return as;
}
private void D()
{
String s = getParameter("image");
if(s != null)
Q(R(s));
s = getParameter("overlay");
if(s != null)
C(R(s));
s = getParameter("target");
s = getParameter("hRef");
if(s != null)
try
{
O(new URL(getDocumentBase(), s));
}
catch(MalformedURLException _ex)
{
getAppletContext().showStatus("Bad URL: " + s);
return;
}
s = getParameter("rocking");
if(s != null)
M(s.toUpperCase().equals("TRUE"));
}
public Lake()
{
X = 50;
V = true;
I = "_self";
M(false);
U = false;
}
public void init()
{
repaint();
System.out.println(getAppletInfo());
D();
U = true;
}
public Dimension preferredSize()
{
return new Dimension(Q, (int)((double)R * 1.8D));
}
public boolean mouseUp(Event event, int i, int j)
{
super.mouseUp(event, i, j);
if(J == null)
{
V = !V;
if(j < R)
getAppletContext().showDocument(N("http://www.demon.co.uk/davidg/spigots.htm"), I);
} else
{
showStatus(String.valueOf(J));
getAppletContext().showDocument(J, I);
}
return true;
}
private URL N(String s)
{
URL url = null;
try
{
url = new URL(getDocumentBase(), s);
}
catch(MalformedURLException _ex)
{
getAppletContext().showStatus("Bad URL: " + s);
}
return url;
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
if(U)
{
E(g);
return;
} else
{
g.setFont(new Font("Helvetica", 20, 0));
String s = "Lake v. 3.0 loading...";
FontMetrics fontmetrics = g.getFontMetrics();
int i = fontmetrics.stringWidth(s);
int j = fontmetrics.getHeight();
int k = size().width;
int l = size().height;
g.setColor(Color.lightGray);
g.fillRect(0, 0, k, l);
g.setColor(Color.white);
g.drawString(s, (k - i) / 2, (l + j) / 2);
g.setColor(Color.black);
g.drawString(s, (k - i) / 2 + 2, (l + j) / 2 + 2);
g.setColor(Color.lightGray);
g.drawString(s, (k - i) / 2 + 1, (l + j) / 2 + 1);
return;
}
}
private void E(Graphics g)
{
int i = (int)(((double)R * Math.sin((6.2831853070000001D * (double)W) / (double)X)) / 8D) - R / 8;
if(!U)
return;
if(O != null)
{
if(B())
{
g.drawImage(O, -P * Q, R + i, this);
g.drawImage(O, (12 - P) * Q, R + i, this);
g.drawImage(G, 0, i - 1, this);
return;
}
g.drawImage(O, -P * Q, R, this);
g.drawImage(O, (12 - P) * Q, R, this);
g.drawImage(G, 0, -1, this);
}
}
public void F()
{
Image image = createImage(Q, R + 1);
Graphics g = image.getGraphics();
g.drawImage(G, 0, 1, this);
for(int i = 0; i < R >> 1; i++)
{
g.copyArea(0, i, Q, 1, 0, R - i);
g.copyArea(0, R - 1 - i, Q, 1, 0, -R + 1 + (i << 1));
g.copyArea(0, R, Q, 1, 0, -1 - i);
}
O = createImage(13 * Q, R);
N = O.getGraphics();
N.drawImage(image, 12 * Q, 0, this);
int j = 0;
do
J(N, j);
while(++j < 12);
g.drawImage(G, 0, 1, this);
if(H != null)
g.drawImage(H, Q - S >> 1, R - (T >> 1), this);
G = image;
}
public void J(Graphics g, int i)
{
double d = (6.2831853071795862D * (double)i) / 12D;
int j = (12 - i) * Q;
for(int k = 0; k < R; k++)
{
int l = (int)(((double)(R / 14) * ((double)k + 28D) * Math.sin((double)((R / 14) * (R - k)) / (double)(k + 1) + d)) / (double)R);
if(k < -l)
g.copyArea(12 * Q, k, Q, 1, -j, 0);
else
g.copyArea(12 * Q, k + l, Q, 1, -j, -l);
}
if(H != null)
g.drawImage(H, i * Q + (Q - S >> 1), -T >> 1, this);
}
private transient Thread A;
private static final String B = "image";
private static final String C = "overlay";
private static final String D = "target";
private static final String E = "hRef";
private static final String F = "rocking";
private Image G;
private Image H;
private String I;
private URL J;
private boolean K;
private final int L = 12;
private transient Graphics M;
private transient Graphics N;
private transient Image O;
private transient int P;
private transient int Q;
private transient int R;
private transient int S;
private transient int T;
private transient boolean U;
private transient boolean V;
private transient int W;
private transient int X;
}
------------------------------------------------------------------------
//SWAN.JAVA//
import java.applet.Applet;
import java.awt.*;
import java.awt.Graphics;
public class Swan extends java.applet.Applet implements Runnable {
Thread runner;
boolean right = true;
int xpos=10;
Image bufferimg;
Graphics G;
public void init() {
bufferimg = createImage(size().width, size().height);
G = bufferimg.getGraphics();
}
public void start() {
if (runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void stop() {
if (runner != null) {
runner.stop();
runner = null;
}
}
public void run() {
while (true) {
repaint();
try { Thread.sleep(150); }
catch (InterruptedException e) { }
}
}
public void update(Graphics g) {
G.setColor(getBackground());
G.fillRect(0,0,this.size().width,this.size().height);
G.setColor(Color.black);
Polygon swan=new Polygon();
swan.addPoint(xpos+146,19);
swan.addPoint(xpos+140,14);
swan.addPoint(xpos+138,12);
swan.addPoint(xpos+134,11);
swan.addPoint(xpos+129,10);
swan.addPoint(xpos+126,10);
swan.addPoint(xpos+122,11);
swan.addPoint(xpos+119,13);
swan.addPoint(xpos+116,17);
swan.addPoint(xpos+113,27);
swan.addPoint(xpos+112,35);
swan.addPoint(xpos+113,41);
swan.addPoint(xpos+115,48);
swan.addPoint(xpos+131,87);
swan.addPoint(xpos+132,94);
swan.addPoint(xpos+129,95);
swan.addPoint(xpos+118,87);
swan.addPoint(xpos+111,82);
swan.addPoint(xpos+103,80);
swan.addPoint(xpos+95,76);
swan.addPoint(xpos+88,74);
swan.addPoint(xpos+80,73);
swan.addPoint(xpos+73,74);
swan.addPoint(xpos+52,77);
swan.addPoint(xpos+41,82);
swan.addPoint(xpos+37,84);
swan.addPoint(xpos+24,86);
swan.addPoint(xpos+5,86);
swan.addPoint(xpos+2,86);
swan.addPoint(xpos+-5,84);
swan.addPoint(xpos+-7,86);
swan.addPoint(xpos+16,105);
swan.addPoint(xpos+22,110);
swan.addPoint(xpos+30,116);
swan.addPoint(xpos+39,121);
swan.addPoint(xpos+48,124);
swan.addPoint(xpos+55,127);
swan.addPoint(xpos+62,129);
swan.addPoint(xpos+70,129);
swan.addPoint(xpos+79,130);
swan.addPoint(xpos+89,130);
swan.addPoint(xpos+98,131);
swan.addPoint(xpos+104,131);
swan.addPoint(xpos+111,130);
swan.addPoint(xpos+115,130);
swan.addPoint(xpos+124,130);
swan.addPoint(xpos+132,130);
swan.addPoint(xpos+135,129);
swan.addPoint(xpos+143,129);
swan.addPoint(xpos+149,127);
swan.addPoint(xpos+153,124);
swan.addPoint(xpos+157,116);
swan.addPoint(xpos+159,111);
swan.addPoint(xpos+159,106);
swan.addPoint(xpos+153,93);
swan.addPoint(xpos+156,100);
swan.addPoint(xpos+131,53);
swan.addPoint(xpos+128,44);
swan.addPoint(xpos+127,40);
swan.addPoint(xpos+128,36);
swan.addPoint(xpos+131,35);
swan.addPoint(xpos+135,35);
swan.addPoint(xpos+139,36);
swan.addPoint(xpos+144,37);
swan.addPoint(xpos+147,39);
swan.addPoint(xpos+154,45);
swan.addPoint(xpos+156,46);
swan.addPoint(xpos+158,44);
swan.addPoint(xpos+156,41);
swan.addPoint(xpos+154,38);
swan.addPoint(xpos+151,34);
swan.addPoint(xpos+151,32);
swan.addPoint(xpos+150,29);
swan.addPoint(xpos+151,25);
swan.addPoint(xpos+149,22);
swan.addPoint(xpos+147,21);//outer swan//
G.setColor(Color.white);
G.fillPolygon(duck);
G.setColor(Color.black);
G.drawPolygon(swan);
G.fillOval(xpos+136,23,3,3);
G.drawLine(xpos+148,20,xpos+149,22);
G.drawLine(xpos+149,22,xpos+136,25);
G.drawArc(xpos+126,20,14,14,130,270);
G.drawArc(xpos+55,76,20,8,90,270);
G.drawArc(xpos+63,83,20,8,90,270);
G.drawArc(xpos+70,89,20,8,90,270);
G.drawArc(xpos+28,82,28,15,160,160);
G.drawArc(xpos+40,96,15,6,130,270);
G.drawLine(xpos+34,103,xpos+35,104);
G.drawLine(xpos+35,104,xpos+37,106);
G.drawLine(xpos+37,106,xpos+46,110);
G.drawLine(xpos+46,110,xpos+53,111);
G.drawLine(xpos+53,111,xpos+57,111);
G.drawLine(xpos+52,112,xpos+55,114);
G.drawLine(xpos+55,114,xpos+61,117);
G.drawLine(xpos+61,117,xpos+65,117);
G.drawLine(xpos+63,118,xpos+65,120);
G.drawLine(xpos+65,120,xpos+68,123);
G.drawLine(xpos+68,123,xpos+70,124);
G.drawLine(xpos+70,124,xpos+73,125);
G.drawLine(xpos+73,125,xpos+105,127);
G.drawLine(xpos+105,127,xpos+108,125);
G.drawLine(xpos+108,125,xpos+110,124);
G.drawLine(xpos+110,124,xpos+116,118);
G.drawLine(xpos+116,118,xpos+115,108);
G.drawLine(xpos+115,108,xpos+118,103);
G.drawPolygon(swan);
if(right) {
xpos+=2;
if(xpos==200) right=false;
}
else {
xpos-=2;
if(xpos == 10) right=true;
}
g.drawImage(bufferimg,0,0,this);
}
}
|
|
|
|
|
|
|
|