/*
* 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);
}
}