未完成的字体大小缩放

本文介绍了一个使用 Java Applet 实现的文字移动效果案例,该应用通过改变角度和字体大小来实现文字的动态显示,并提供了用户输入和重置功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author lifeng
 */
import java.awt.*;
import java.awt.event.*;
public class moveString  extends java.applet.Applet implements Runnable,ActionListener,TextListener{
    Color darkblue = new Color(15,69,190);
    Graphics offscreenG;
    Image offscreenImage;
   // Image pictop;
   // Image picButtom;
    int d = 2;
    int  r = 150;
    int angle =0;
    int x = 250;
    int y = 400;
    int x0 = 240;
    int y0 = 200;
    int font = 65;
    Thread runner;
    TextField textString;
    String name = "lifeng";

    @Override
    public void init()
    {
        offscreenImage = createImage(1000,800);
        offscreenG = offscreenImage.getGraphics();

       // pictop = getImage(getCodeBase(),"1.gif");
       // picButtom = getImage(getCodeBase(),"2.gig");
        setLayout(null);

        textString = new TextField(name,21);
        textString.addTextListener(this);
        add(textString);
        textString.setBounds(160,500,100,20);

        Button submitButton = new Button("Submit");
        submitButton.addActionListener(this);
        add(submitButton);
        submitButton.setBounds(280, 500,50,20);

        Button reset = new Button("reset");
        reset.addActionListener(this);
        add(reset);
        reset.setBounds(350,500,50,20);
    }
    public void change()
    {
        name = textString.getText();
        repaint();
    }

    public void actionPerformed(ActionEvent e)
    {

        if(e.getActionCommand().equals("Submit"))
            change();
        else if(e.getActionCommand().equals("reset"))
        {
            name = "lifeng";
            textString.setText("lifeng");
            repaint();
        }
    }

    public void textValueChanged(TextEvent t)
    {
        change();
    }

    @Override
    public void start()
    {
        if(runner == null)
        {
            runner = new Thread();
            runner.start();
        }
    }

    @Override
    public void stop()
    {
        if(runner != null)
            runner = null;
    }

    public void run()
    {
        while(true)
        {
            angle += 1;
            x = (int)(r*Math.sin(2*Math.PI*angle/360))+ x0;
            y = (int)(r*Math.cos(2*Math.PI*angle/360))+ y0;
            {
            if(((angle >=0)&&(angle<90))&&(angle%3==0))
                font -=1;
            else if(((angle >=90)&&(angle<180))&&(angle%3==0))
                font -= 1;
            else if(((angle >=180)&&(angle<270))&&(angle%3==0))
                font += 1;
            else if(((angle >=270)&&(angle<360))&&(angle%3==0))
                font += 1;
            }
            d =2;
            if(font <25)
                d=1;
            repaint();
            if(font == 66)
                font = 65;
            try
            {
                Thread.sleep(25);
            }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
            if(angle == 360)
                angle = 0;
        }
    }

    @Override
    public void update(Graphics g)
    {
        paint(g);
    }

    @Override
    public void paint(Graphics g)
    {
        Font f = new Font("Symbol",Font.BOLD,font);
        offscreenG.setColor(Color.BLUE);
        offscreenG.fillRect(0,0,1500,500);
        offscreenG.setColor(Color.black);
        offscreenG.setFont(f);
        //offscreenG.drawImage(pictop, 135,78, this);
        offscreenG.drawString(name, x+d, y-d);
        offscreenG.setColor(Color.white);
        offscreenG.drawString(name,x,y);
       // offscreenG.drawImage(picButtom, 217,-15, this);
        g.drawImage(offscreenImage, 0,0, this);

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值