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

📄 comix2.java.bak

📁 Java 范例实战 光盘使用说明 ========================== 本光盘的文件结构如下所示: =====================================
💻 BAK
字号:
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.net.URL;
import java.util.StringTokenizer;

public class Comix2 extends Atemplet
    implements Runnable
{

    Thread woohoo = null;
    Image background = null;
    Image bufimage = null;
    Graphics bufgraphic = null;
    URL hotlink = null;
    Dimension roo = null;
    String param = null;
    String temp = null;
    String fonttype = null;
    String parampiece = null;
    String type[] = null;
    String words[] = null;
    String mouth[] = null;
    int a = 0;
    int fontsize = 0;
    int bubblex[] = null;
    int bubbley[] = null;
    boolean bubbleon[] = null;
    boolean border = false;

    public void init()
    {
  
        roo = size();
        bufimage = createImage(roo.width, roo.height);
        bufgraphic = bufimage.getGraphics();
        temp = getParameter("FONTSIZE");
        fontsize = temp == null ? 14 : Integer.parseInt(temp);
        temp = getParameter("FONTTYPE");
        fonttype = temp == null ? "Courier" : temp;
        temp = getParameter("BORDER");
        if(temp != null)
            border = !temp.equalsIgnoreCase("no");
        
    }

    public void paint(Graphics g)
    {
  
        paintBuffer(bufgraphic);
        g.drawImage(bufimage, 0, 0, this);
  
    }

    public void paintBuffer(Graphics g)
    {

        g.setColor(Color.lightGray);
        g.fillRect(0, 0, roo.width, roo.height);
        if(background != null)
            g.drawImage(background, 0, 0, this);
        for(int i = 0; i < 6; i++)
            if(bubbleon[i])
                drawSentence(g, words[i], type[i], mouth[i], bubblex[i], bubbley[i]);

        if(border)
        {

            g.setColor(Color.black);
            g.drawRect(0, 0, roo.width - 1, roo.height - 1);
            g.setColor(Color.white);
            for(int j = 1; j < 4; j++)
                g.drawRect(j, j, roo.width - 2 * j - 1, roo.height - 2 * j - 1);

            g.setColor(Color.black);
            g.drawRect(4, 4, roo.width - 9, roo.height - 9);

        }

    }

    public void drawSentence(Graphics g, String s, String s1, String s2, int i, int j)
    {

        int k = i;
        int l = j;
        Font font = new Font(fonttype, 0, fontsize);
        g.setFont(font);
        FontMetrics fontmetrics = g.getFontMetrics();
        StringTokenizer stringtokenizer = new StringTokenizer(s + "/", "/");
        int i1 = stringtokenizer.countTokens();
        int ai[] = new int[i1];
        String as[] = new String[i1];
        int j1 = 0;
        for(int k1 = 0; stringtokenizer.hasMoreTokens(); k1++)
        {

            as[k1] = stringtokenizer.nextToken();
            StringTokenizer stringtokenizer1 = new StringTokenizer(as[k1], "{");
            ai[k1] = fontmetrics.stringWidth(as[k1]) - (stringtokenizer1.countTokens() - 1) * (fontmetrics.stringWidth("{") * 3);
            j1 = Math.max(j1, ai[k1]);

        }

        int l1 = (int)((double)j1 * 1.25D);
        int i2 = (fontmetrics.getHeight() * i1 + fontmetrics.getLeading() * (i1 - 1)) * 2;
        if(s1.equals("speech"))
        {

            if(s2.equals("ne"))
            {

                k = i;
                l = j - i2;

            }
            else
            if(s2.equals("se"))
            {

                k = i;
                l = j;

            }
            else
            if(s2.equals("sw"))
            {

                k = i - l1;
                l = j;

            }
            else
            {

                k = i - l1;
                l = j - i2;

            }
            g.setColor(Color.white);
            g.fillOval(k, l, l1, i2);
            g.setColor(Color.black);
            g.drawOval(k, l, l1, i2);
            g.setColor(Color.white);
            int ai1[] = new int[3];
            int ai2[] = new int[3];
            ai1[0] = i;
            ai2[0] = j;
            ai1[1] = (k + l1 / 2) - l1 / 6;
            ai2[1] = l + i2 / 2;
            ai1[2] = k + l1 / 2 + l1 / 6;
            ai2[2] = l + i2 / 2;
            g.fillPolygon(ai1, ai2, 3);
            g.setColor(Color.black);
            g.drawLine(ai1[0], ai2[0], ai1[1], ai2[1]);
            g.drawLine(ai1[0], ai2[0], ai1[2], ai2[2]);
            g.setColor(Color.white);
            g.fillOval(k + 1, l + 1, l1 - 2, i2 - 2);

        }
        else
        if(s1.equals("thought"))
        {

            for(int j2 = 1; j2 < 4; j2++)
            {

                int l2 = j2 * 4;
                int j3 = l2 / 2;
                g.setColor(Color.white);
                g.fillOval(k - j3, l - j3, l2, l2);
                g.setColor(Color.black);
                g.drawOval(k - j3, l - j3, l2, l2);
                if(j2 < 3)
                {

                    if(s2.equals("ne"))
                    {

                        k += l2;
                        l -= l2;

                    }
                    else
                    if(s2.equals("se"))
                    {

                        k += l2;
                        l += l2;

                    }
                    else
                    if(s2.equals("sw"))
                    {

                        k -= l2;
                        l += l2;

                    }
                    else
                    {

                        k -= l2;
                        l -= l2;

                    }

                }
                else
                if(s2.equals("ne"))
                    l -= i2 / 2;
                else
                if(s2.equals("se"))
                    l -= i2 / 2;
                else
                if(s2.equals("sw"))
                {

                    k -= l1;
                    l -= i2 / 2;

                }
                else
                {

                    k -= l1;
                    l -= i2 / 2;

                }

            }

            g.setColor(Color.white);
            g.fillOval(k, l, l1, i2);
            g.setColor(Color.black);
            g.drawOval(k, l, l1, i2);

        }
        else
        if(s1.equals("narrative"))
        {

            for(int k2 = 0; k2 < i1; k2++)
                ai[k2] = j1;

            l1 = (int)((double)l1 / 1.25D + 10D);
            i2 = i2 / 2 + 10;
            if(s2.equals("ne"))
            {

                k = roo.width - l1 - 4;
                l = 4;

            }
            else
            if(s2.equals("se"))
            {

                k = roo.width - l1 - 4;
                l = roo.height - i2 - 4;

            }
            else
            if(s2.equals("sw"))
            {

                k = 4;
                l = roo.height - i2 - 4;

            }
            else
            {

                k = 4;
                l = 4;

            }
            g.setColor(Color.white);
            g.fillRect(k, l, l1, i2);
            g.setColor(Color.black);
            g.drawRect(k, l, l1, i2);

        }
        g.setColor(Color.black);
        int i3 = k + l1 / 2;
        int k3 = l + i2 / 2;
        for(int j4 = 0; j4 < i1; j4++)
        {

            StringTokenizer stringtokenizer2 = new StringTokenizer(as[j4]);
            int l3 = (i3 - ai[j4] / 2) + fontmetrics.charWidth('a') / 2;
            int k4 = i1 * fontmetrics.getHeight();
            int i4 = ((k3 - k4 / 2) + (j4 + 1) * fontmetrics.getHeight()) - i1;
            while(stringtokenizer2.hasMoreTokens()) 
            {

                String s3 = stringtokenizer2.nextToken();
                boolean flag = false;
                flag = s3.indexOf("{") != -1;
                if(flag)
                {

                    if(s3.substring(1, 2).equalsIgnoreCase("b"))
                    {

                        s3 = s3.substring(3);
                        Font font1 = new Font(fonttype, 1, fontsize);
                        g.setFont(font1);
                        g.drawString(s3, l3, i4);

                    }
                    else
                    if(s3.substring(1, 2).equalsIgnoreCase("i"))
                    {

                        s3 = s3.substring(3);
                        Font font2 = new Font(fonttype, 2, fontsize);
                        g.setFont(font2);
                        g.drawString(s3, l3, i4);

                    }
                    else
                    if(s3.substring(1, 2).equalsIgnoreCase("u"))
                    {

                        s3 = s3.substring(3);
                        Font font3 = new Font(fonttype, 0, fontsize);
                        g.setFont(font3);
                        g.drawString(s3, l3, i4);
                        g.drawLine(l3, i4 + 1, l3 + fontmetrics.stringWidth(s3), i4 + 1);

                    }

                }
                else
                {

                    Font font4 = new Font(fonttype, 0, fontsize);
                    g.setFont(font4);
                    g.drawString(s3, l3, i4);

                }
                fontmetrics = g.getFontMetrics();
                l3 += fontmetrics.stringWidth(s3 + " ");

            }

        }

    }

    public void update(Graphics g)
    {

        paint(g);

    }

    public void start()
    {

        if(woohoo == null)
        {

            woohoo = new Thread(this);
            woohoo.start();

        }

    }

    public void stop()
    {

        woohoo.stop();
        woohoo = null;

    }

    public void run()
    {

        for(; getParameter("ACTION" + a) != null; a++)
        {

            param = getParameter("ACTION" + a);
            if(param != null)
            {

                int i = param.indexOf("|");
                parampiece = param.substring(0, i);
                if(parampiece.indexOf("BUBBLE") != -1)
                {

                    int j = Integer.parseInt(parampiece.substring(6));
                    bubbleon[j] = true;
                    for(StringTokenizer stringtokenizer1 = new StringTokenizer(param.substring(i + 1), "|"); stringtokenizer1.hasMoreTokens(); repaint())
                    {

                        type[j] = stringtokenizer1.nextToken();
                        mouth[j] = stringtokenizer1.nextToken();
                        bubblex[j] = Integer.parseInt(stringtokenizer1.nextToken());
                        bubbley[j] = Integer.parseInt(stringtokenizer1.nextToken());
                        words[j] = stringtokenizer1.nextToken();

                    }

                }
                else
                if(parampiece.equals("WAIT"))
                {

                    int k = Integer.parseInt(param.substring(i + 1));
                    try
                    {

                        Thread.sleep(k);

                    }
                    catch(InterruptedException _ex) { }

                }
                else
                if(parampiece.equals("CLEAR"))
                {

                    for(StringTokenizer stringtokenizer = new StringTokenizer(param.substring(i + 1), "|"); stringtokenizer.hasMoreTokens(); repaint())
                    {

                        int l = Integer.parseInt(stringtokenizer.nextToken().substring(6));
                        bubbleon[l] = false;

                    }

                }
                else
                if(parampiece.equals("BACKGROUND"))
                {

                    background = getImage(getDocumentBase(), param.substring(i + 1));
                    repaint();

                }
                else
                if(parampiece.equals("LOOPBACKTO"))
                    a = Integer.parseInt(param.substring(i + 1)) - 1;

            }

        }

    }

    public Comix2()
    {

        type = new String[6];
        words = new String[6];
        mouth = new String[6];
        bubblex = new int[6];
        bubbley = new int[6];
        bubbleon = new boolean[6];
        border = true;

    }

}

⌨️ 快捷键说明

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