import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MoveString extends Applet implements Runnable,ActionListener,TextListener{
Color darkblue = new Color(255,0,128);
Graphics offscreenG;
Image offscreenImage;
Image pictop;
Image picbuttom;
int d = 2;
int r = 140;
int angle = 0;
int x = 270;
int y = 400;
int x0 = 260;
int y0 = 200;
int font = 65;
Thread runner;
TextField textString;
String request;
String name="Wan YanKai";
public void init(){
offscreenImage = createImage(getSize().width, getSize().height);
offscreenG = offscreenImage.getGraphics();
pictop = getImage(getCodeBase(),"top.gif");
setLayout(null);
picbuttom = getImage(getCodeBase(),"buttom.gif");
setLayout(null);
textString = new TextField(name,21);
textString.addTextListener(this);
add (textString);
textString.setBounds(210,350,100,20);
Button submitButton = new Button("Submit");
submitButton.addActionListener(this);
add (submitButton);
submitButton.setBounds(330,350,50,20);
Button clearButton = new Button("Restore");
clearButton.addActionListener(this);
add (clearButton);
clearButton.setBounds(400,350,50,20);
}
public void change(){
name = textString.getText();
repaint();
}
public void textValueChanged(TextEvent t){
change();
}
public void actionPerformed(ActionEvent e) {
request = e.getActionCommand();
if (request == "Submit")
change();
else if (request == "Restore")
{name = "Wan YanKai";
textString.setText("Wan YanKai");
repaint();
}
}
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){
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){}
if (angle == 360) angle=0;
}
}
public void update(Graphics g){
paint(g);
}
public void paint(Graphics g){
Font f = new Font("Arial",Font.BOLD,font);
offscreenG.setColor(Color.white);
offscreenG.fillRect(0,0,1500,500);
offscreenG.setColor(Color.black);
offscreenG.setFont(f);
offscreenG.drawImage(picbuttom,215,145,this);
offscreenG.drawString(name,x+d,y-d);
offscreenG.setColor(darkblue);
offscreenG.drawString(name,x,y);
offscreenG.drawImage(pictop,255,30,this);
g.drawImage(offscreenImage,0,0,this);
}
}