⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loop.java~3~

📁 java applet 仿真物理现象,不需帐号就可自由下载此源码
💻 JAVA~3~
字号:
package unari;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author not attributable * @version 1.0 *//** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author not attributable * @version 1.0 */// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2005-1-7 15:10:56// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!// Decompiler options: packimports(3)// Source File Name:   loop.javaimport java.applet.Applet;import java.awt.*;public class loop extends Applet    implements Runnable{    public void init()    {        d = size();        k = 1.0D;        f1 = 0;        f2 = 1;        f3 = 1;        ang = 0.78539820000000005D;        sr = 130;        sx = (int)((double)(d.width / 2) + 0.70710669999999998D * (double)sr);        sy = (int)((double)(d.width / 2) - 0.70710669999999998D * (double)sr);        l = 0;        v = 60D;        pa = 0.29999999999999999D;        buffer = createImage(d.width, d.height);        r = 6D;        x = 2D * r;        y = r;        dx = 0.0D;        dy = 0.0D;        setLayout(new BorderLayout());        Panel panel = new Panel();        panel.setLayout(new GridLayout(9, 1));        panel.add(new Button("A"));        panel.add(new Button("B"));        panel.add(new Button("C"));        panel.add(new Button("D"));        panel.add(new Button("E"));        panel.add(new Button("F"));        panel.add(new Button("Start"));        panel.add(new Button("Strobo"));        panel.add(new Button("Stop"));        add("East", panel);    }    void drawToBuffer()    {        int ai[] = {            0, 0, d.width / 2, d.width / 2        };        int ai1[] = {            0, d.height, d.height, d.width / 2        };        Graphics g = buffer.getGraphics();        if(f2 == 1)        {            g.setColor(Color.white);            g.clipRect(0, 0, d.width, d.height);            g.fillRect(0, 0, d.width, d.height);            g.setColor(bb);            g.fillPolygon(ai, ai1, n);            g.fillRect(d.width / 2, sy, d.height - sy, d.height - sy);            g.fillRect(sx, 0, d.width - sx, d.height);            g.setColor(Color.white);            g.fillOval(sx - sr, sy - sr, 2 * (sr - 1), 2 * (sr - 1));            g.setColor(Color.cyan);            g.drawLine(0, sy + sr, sx, sy + sr);            g.drawLine((int)(((double)sy - 1.5D * (double)sr) + 10D), (int)(((double)sy - 1.5D * (double)sr) + 11D), (int)(((double)sy - 1.5D * (double)sr) + 10D), sy + sr);            g.drawLine((sy - sr) + 6, (sy - sr) + 7, (sy - sr) + 6, sy + sr);            g.drawLine(sy, sy + 1, sy, sy + sr);            g.setColor(Color.blue);            g.drawString("A", (int)r, (int)(4D * r));            g.drawString("B", (int)(3D * r + 12D), (int)(6D * r + 12D));            g.drawString("C", (sy - sr) + 6, (sy - sr) + 18 + 6);            g.drawString("D", sy - sr / 2 - 8, (sy - sr / 2) + 10);            g.drawString("E", sy, sy + 18);            g.drawString("F", (sy + sr / 2) - 3, (sy + sr / 2 + 18) - 3);            g.setColor(Color.black);            g.drawString("2.5R", (int)(((double)sy - 1.5D * (double)sr) + 15D), (sy + sr) - 50);            g.drawString("2R", (sy - sr) + 10, (sy + sr) - 50);            g.drawString("R", sy + 5, (sy + sr) - 50);            f2 = 0;        }        if(strobo != 1)        {            g.setColor(Color.white);            g.clipRect(0, 0, d.width, d.height);            g.fillRect(0, 0, d.width, d.height);            g.setColor(bb);            g.fillPolygon(ai, ai1, n);            g.fillRect(d.width / 2, sy, d.height - sy, d.height - sy);            g.fillRect(sx, 0, d.width - sx, d.height);            g.setColor(Color.white);            g.fillOval(sx - sr, sy - sr, 2 * (sr - 1), 2 * (sr - 1));            g.setColor(Color.cyan);            g.drawLine(0, sy + sr, sx, sy + sr);            g.drawLine((int)(((double)sy - 1.5D * (double)sr) + 10D), (int)(((double)sy - 1.5D * (double)sr) + 11D), (int)(((double)sy - 1.5D * (double)sr) + 10D), sy + sr);            g.drawLine((sy - sr) + 6, (sy - sr) + 7, (sy - sr) + 6, sy + sr);            g.drawLine(sy, sy + 1, sy, sy + sr);            g.setColor(Color.blue);            g.drawString("A", (int)r, (int)(4D * r));            g.drawString("B", (int)(3D * r + 12D), (int)(6D * r + 12D));            g.drawString("C", (sy - sr) + 6, (sy - sr) + 18 + 6);            g.drawString("D", sy - sr / 2 - 8, (sy - sr / 2) + 10);            g.drawString("E", sy, sy + 18);            g.drawString("F", (sy + sr / 2) - 3, (sy + sr / 2 + 18) - 3);            g.setColor(Color.black);            g.drawString("2.5R", (int)(((double)sy - 1.5D * (double)sr) + 15D), (sy + sr) - 50);            g.drawString("2R", (sy - sr) + 10, (sy + sr) - 50);            g.drawString("R", sy + 5, (sy + sr) - 50);        }        g.setColor(Color.blue);        g.fillOval((int)x, (int)y, (int)(2D * r), (int)(2D * r));    }    void move()    {        dy = dy + pa * (double)f1;        x = x + dx * (double)f1;        y = y + dy * (double)f1;        if(x >= (double)d.width - 2D * r)        {            x = (double)d.width - 2D * r;            dx = 0.0D;            dy = 0.0D;            f1 = 0;        }        if(y >= -2D * r + x && x <= (double)(d.width / 2))        {            y = -1.5D * r + x;            double d5 = dx * Math.cos(ang) + dy * Math.sin(ang);            double d7 = -1D * (dy * Math.cos(ang) - dx * Math.sin(ang));            double d1 = d5 * Math.cos(ang) - d7 * Math.sin(ang);            double d3 = d5 * Math.sin(ang) + d7 * Math.cos(ang);            dx = d1;            dy = d3;        }        double d9 = (double)sx - (x + r);        double d10 = (y + r) - (double)sy;        double d11 = d9 * d9 + d10 * d10;        double d12 = Math.sqrt(d11);        if(d11 > ((double)sr - r) * ((double)sr - r) && x >= (double)sx || d11 > ((double)sr - r) * ((double)sr - r) && x <= (double)sx && x >= (double)(d.width / 2) && y >= (double)(d.width / 2))        {            x = x + (((d12 - (double)sr) + 0.83999999999999997D * r) * d9) / d12;            y = y - (((d12 - (double)sr) + 0.83999999999999997D * r) * d10) / d12;            double d6 = (dx * d10) / d12 + (dy * d9) / d12;            double d8 = -1D * ((dy * d10) / d12 - (dx * d9) / d12);            double d2 = (d6 * d10) / d12 - (d8 * d9) / d12;            double d4 = (d6 * d9) / d12 + (d8 * d10) / d12;            dx = d2;            dy = d4;        }        if(x > (double)sx - 2D * r && y < (double)(sy - sr) - 2D * r && dx > 0.0D)        {            x = (double)sx - 2D * r;            dx = -dx;        }    }    public void start()    {        if(th == null)        {            th = new Thread(this);            th.start();        }    }    public boolean action(Event event, Object obj)    {        if(event.target instanceof Button)        {            if("Start".equals(obj))            {                f1 = 1;                f2 = 1;                strobo = 0;            }            if("Stop".equals(obj))            {                f1 = 0;                f2 = 0;                dx = 0.0D;                dy = 0.0D;            }            if("A".equals(obj))            {                f1 = 0;                f2 = 1;                strobo = 0;                x = (double)sy - 1.5D * (double)sr;                y = (double)sy - 1.5D * (double)sr - 2D * r;                pa = 0.29999999999999999D;                dx = 0.0D;                dy = 0.0D;                return true;            }            if("B".equals(obj))            {                f1 = 0;                f2 = 1;                f3 = 0;                strobo = 0;                x = (sy - sr) / 2 - 5;                y = (double)(sy - sr - 5) - 2D * r;                dx = 0.0D;                dy = 0.0D;                pa = 0.29999999999999999D;                return true;            }            if("C".equals(obj))            {                f1 = 0;                f2 = 1;                f3 = 1;                strobo = 0;                x = (double)(sy - sr) + 2D * r;                y = sy - sr;                dx = 0.0D;                dy = 0.0D;                pa = 0.59999999999999998D;                repaint();                return true;            }            if("D".equals(obj))            {                f1 = 0;                f2 = 1;                f3 = 1;                strobo = 0;                x = sy - 70;                y = (double)(sy - 70) - 2D * r;                dx = 0.0D;                dy = 0.0D;                pa = 0.59999999999999998D;                repaint();                return true;            }            if("E".equals(obj))            {                f1 = 0;                f2 = 1;                f3 = 1;                strobo = 0;                x = sy;                y = (double)sy - 2D * r;                dx = 0.0D;                dy = 0.0D;                pa = 0.29999999999999999D;                repaint();                return true;            }            if("F".equals(obj))            {                f1 = 0;                f2 = 1;                f3 = 1;                strobo = 0;                x = sy + 60;                y = (double)(sy + 60) - 2D * r;                dx = 0.0D;                dy = 0.0D;                pa = 0.29999999999999999D;                repaint();                return true;            }            if("Strobo".equals(obj))            {                strobo = 1;                f2 = 1;                f1 = 1;                repaint();                return true;            } else            {                return true;            }        } else        {            return super.handleEvent(event);        }    }    public void run()    {        while(th != null)        {            move();            drawToBuffer();            repaint();            try            {                Thread.sleep(30L);            }            catch(InterruptedException _ex) { }        }    }    public void update(Graphics g)    {        paint(g);    }    public void paint(Graphics g)    {        g.drawImage(buffer, 0, 0, this);    }    public void stop()    {        if(th != null)        {            th.stop();            th = null;        }    }    public loop()    {        n = 4;        aa = Color.blue;        bb = Color.orange;        cc = Color.blue;    }    Thread th;    double pa;    double x;    double y;    double dx;    double dy;    double r;    double v1;    double v2;    double u1;    double u2;    double vx1;    double vx2;    double ux1;    double ux2;    double v;    int sx;    int sy;    int sr;    int i;    int l;    int f1;    int f2;    int f3;    int strobo;    int kaku;    int n;    double ang;    double k;    Image buffer;    Dimension d;    Color aa;    Color bb;    Color cc;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -