真希望一觉醒来这个问题能被解决!
import java.applet.*;//引入java.applet包
import java.awt.*;//引入java.awt包
import java.awt.event.*;//引入java.awt.event包
//MoveString类是Applet的子类
//Runnable接口用于建立线程
//ActionListener接口提供感知鼠标操作的“顺风耳”的方法
//TextListener接口提供感知文本框中字符变化的方法
public class MoveString extends Applet implements Runnable,ActionListener,TextListner{
Color darkblue=new Color(15,69,190);
Graphics offscreenG;
Image offscreemImage;
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="Wan YanKai";
public void init(){
offscreenImage=createImage(getSize().width,getSize().height);
offscreenG=offscreenImage.getGraphics();
pictop=getImage(getCodeBase(),"top.gif");
picbuttom=getImage(getCodeBase(),"buttom.gif");
setLayout(null);
textString=new TextField(name,21);
textString.addTextListener(this);
add(textString);
textString.setBounds(160,370,100,20);
Button submitButton=new Button("Submit");
submitButton.addActionListener(this);
add(submitButton);
submitButton.setBounds(280,370,50,20);
Button resButton=new Button("Restore");
resButton.addActionListener(this);
add(resButton);
resButton.setBounds(350,370,50,20);
}
public void change(){
name=textString.getText();
repaint();
}
public void textValueChanged(TextEvent t){
}
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("Symbol",Font.BOLD,font);
offscreenG.setColor(Color.white);
offscreenG.fillRect(0,0,1500,500);
offscreenG.setColor(Color.black);
offscreenG.setFont(f);
offscreenG.drawImage(picbuttom,135,78,this);
offscreenG.drawString(name,x+d,y-d);
offscreenG.setColor(darkblue);
offscreenG.drawString(name,x,y);
offscreenG.drawImage(pictop,217,-15,this);
g.drawImage(offscreenImage,0,0,this);
}
}
[解决办法]
你要问什么呢
[解决办法]
import java.applet.*; //引入java.applet包import java.awt.*; //引入java.awt包import java.awt.event.*; //引入java.awt.event包//MoveString类是Applet的子类//Runnable接口用于建立线程//ActionListener接口提供感知鼠标操作的“顺风耳”的方法//TextListener接口提供感知文本框中字符变化的方法public class MoveString extends Applet implements Runnable,ActionListener,TextListener{Color darkblue=new Color(15,69,190);Graphics offscreenG;Image offscreemImage;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="Wan YanKai";private Image offscreenImage;private String request;public void init(){offscreenImage=createImage(getSize().width,getSize().height);offscreenG=offscreenImage.getGraphics();pictop=getImage(getCodeBase(),"top.gif");picbuttom=getImage(getCodeBase(),"buttom.gif");setLayout(null);textString=new TextField(name,21);textString.addTextListener(this);add(textString);textString.setBounds(160,370,100,20);Button submitButton=new Button("Submit");submitButton.addActionListener(this);add(submitButton);submitButton.setBounds(280,370,50,20);Button resButton=new Button("Restore");resButton.addActionListener(this);add(resButton);resButton.setBounds(350,370,50,20);}public void change(){name=textString.getText();repaint();}public void textValueChanged(TextEvent t){}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("Symbol",Font.BOLD,font);offscreenG.setColor(Color.white);offscreenG.fillRect(0,0,1500,500);offscreenG.setColor(Color.black);offscreenG.setFont(f);offscreenG.drawImage(picbuttom,135,78,this);offscreenG.drawString(name,x+d,y-d);offscreenG.setColor(darkblue);offscreenG.drawString(name,x,y);offscreenG.drawImage(pictop,217,-15,this);g.drawImage(offscreenImage,0,0,this);}}