📄 00000004.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: andrewleu (Andy), 信区: Java <BR>标 题: An applet written by me <BR>发信站: BBS 水木清华站 (Fri May 1 09:12:47 1998) WWW-POST <BR> <BR>
<BR>/*
<BR>这是我写的一个小程序
<BR>类似xwindows中的Xeyes
<BR>希望你能喜欢
<BR>*/
<BR>/*
<BR><html>
<BR><head>
<BR><title>The J Eyes </title>
<BR><!created by Liu Shu, 28-Apr-1998 -->
<BR></head>
<BR><applet code="Jeyes.class" width=500 height=300>
<BR></applet>
<BR><font SIZE="-1" FACE="Arial"><a HREF="<A HREF="mailto:mailto:andrewleu@hotmail.com">andrewleu@hotmail.com</a></font>
">mailto:andrewleu@hotmail.com">andrewleu@hotmail.com</a></font>
</A> <BR></html>
<BR>**/
<BR>
<BR>import java.applet.*;
<BR>import java.awt.*;
<BR>import java.lang.Math;
<BR>
<BR>public class Jeyes extends Applet implements Runnable
<BR>{
<BR> Dimension d;
<BR> Thread motor ;
<BR> Image offScreen;
<BR> Graphics offScreenGraphics;
<BR> boolean loaded ;
<BR> int w , h;
<BR> int x, y;
<BR> //mouse Position
<BR> boolean first=true;
<BR> int eyeX,eyeY;
<BR> //eyeball position
<BR> public void init(){
<BR> d=this.size();
<BR> w=d.width;h=d.height;
<BR> offScreen=createImage(w,h);
<BR> offScreenGraphics=offScreen.getGraphics();
<BR> }
<BR>public void paint(Graphics g)
<BR> {
<BR> int leftCoX,leftCoY,rightCoX,rightCoY;
<BR> float arcLeft,arcRight;
<BR> if (first)
<BR> {
<BR> g.setColor(Color.black);
<BR> g.fillOval(20,20,w/2-40,h-40);
<BR> g.fillOval(w/2+20,20,w/2-40,h-40);
<BR> g.setColor(Color.white);
<BR> g.fillOval(35,35,w/2-70,h-70);
<BR> g.fillOval(w/2+35,35,w/2-70,h-70);// Eyes
<BR> g.setColor(Color.black);
<BR> g.fillOval(w/4, h/2,50,50);
<BR> g.fillOval(3*w/4,h/2,50,50); //Eye balls
<BR> first=false;
<BR> }
<BR> else
<BR> {
<BR> offScreenGraphics.setColor(Color.black);
<BR> offScreenGraphics.fillOval(20,20,w/2-40,h-40);
<BR> offScreenGraphics.fillOval(w/2+20,20,w/2-40,h-40);
<BR> offScreenGraphics.setColor(Color.white);
<BR> offScreenGraphics.fillOval(35,35,w/2-70,h-70);
<BR> offScreenGraphics.fillOval(w/2+35,35,w/2-70,h-70); //Eyes
<BR> offScreenGraphics.setColor(Color.black);
<BR> // next line to calculate the arc
<BR> leftCoX=x-w/4;leftCoY=y-h/2;
<BR> rightCoX=x-3*w/4;rightCoY=y-h/2;
<BR> arcLeft=(float) Math.atan((double)leftCoY/leftCoX);
<BR> if(leftCoX<0) arcLeft+=3.1415926;//since atan result is between -pi/2 --p/2
<BR> arcRight=(float)Math.atan((double)rightCoY/rightCoX);
<BR> if(rightCoX<0) arcRight+=3.1415926;
<BR> eyeBallPosition(leftCoX ,leftCoY,arcLeft);
<BR> offScreenGraphics.fillOval(w/4+eyeX-25,h/2+eyeY-25,50,50);
<BR>
<BR> eyeBallPosition(rightCoX,rightCoY,arcRight);
<BR> offScreenGraphics.fillOval(3*w/4+eyeX-25,h/2+eyeY-25,50,50);
<BR> //offScreenGraphics.fillOval(w/4, h/2,50,50);
<BR> //offScreenGraphics.fillOval(3*w/4,h/2,50,50); //Eye balls
<BR> g.drawImage(offScreen,0,0,null);
<BR> }
<BR>
<BR> }
<BR>public void eyeBallPosition(int CoX, int CoY, float Arc)
<BR>{
<BR>if((CoX*CoX+CoY*CoY)<h/5*h/5)
<BR>//the mouse in the eye pit
<BR> {
<BR> eyeX=CoX;eyeY=CoY;
<BR> }
<BR>else
<BR> {
<BR> eyeX=(int)(Math.cos((double)Arc)*h/5);
<BR> eyeY=(int)(Math.sin((double)Arc)*h/5);
<BR> }
<BR>}
<BR>public void update(Graphics g)
<BR> {
<BR> paint(g);
<BR> }
<BR> public void run()
<BR> {
<BR> while(true)
<BR> {
<BR> //mouseMove(new Event e, new int x,new int y);
<BR> repaint();
<BR> try{
<BR> motor.sleep(100);
<BR> }
<BR> catch(Exception e)
<BR> {
<BR> System.out.println("Exception\n");
<BR> }
<BR> }
<BR> }
<BR> public void start()
<BR> {
<BR> motor=new Thread(this);
<BR> motor.setPriority(Thread.MIN_PRIORITY);
<BR> motor.start();
<BR> }
<BR> public void stop()
<BR> {
<BR> }
<BR>public boolean mouseMove(Event e,int X,int Y)
<BR> {
<BR> x=X;
<BR> y=Y;
<BR> //System.out.println("x="+x+" "+"y="+y);
<BR> return (true);
<BR> }
<BR>}
<BR>
<BR>
<BR>
<BR> <BR>-- <BR>爱在不言中...... <BR> <BR>※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 202.99.61.172] <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -