JAVA改错和程序解释
这是我看书打的,,但运行时有个错误....说符号找不到是什么原因..另外判断秒针,分针,时针位置是怎么算来的,,看不懂,,希望明白的解释下import java.awt.*;
import java.util.Date;
import java.applet.Applet;
import java.util.Calendar;
import java.text.SimpleDateFormat;
public class CLOCK extends Applet implements Runnable
{
private Thread athread;
private SimpleDateFormat sdateformat;
private int second_lastx=0,second_lasty=0;
private int minute_lastx=0,minute_lasty=0;
private int hour_lastx=0,hour_lasty=0;
public void init(){
this.setBackground(Color.white);
this.athread=null;
this.sdateformat=new SimpleDateFormat("yyyy年mm月dd日hh时mm分ss秒a EEEEE");
}
public void paint(Graphics g)
{
Calendar rightnow=Calendar.getInstance();
int second=rightnow.get(Calendar.SECOND);
int minute=rightnow.get(Calendar.MINUTE);
int hour=rightnow.get(Calendar.HOUR);
int center_x=this.getWidth()/2;
int center_y=60;
int second_x=(int)(Math.cos(second*Math.PI/30-Math.PI/2)*45+center_x);
int second_y=(int)(Math.sin(second*Math.PI/30-Math.PI/2)*45+center_y);
int minute_x=(int)(Math.cos(minute*Math.PI/30-Math.PI/2)*40+center_x);
int minute_y=(int)(Math.sin(minute*Math.PI/30-Math.PI/2)*40+center_y);
int hour_x=(int)(Math.cos((hour*30+minute/2)*Math.PI/180-Math.PI/2)*30+center_x);
int hour_y=(int)(Math.sin((hour*30+minute/2)*Math.PI/180-Math.PI/2)*30+center_y);//这里是怎么来的??
g.setFont(new Font("TimesRoman",Font.PLAIN,14));
g.setColor(Color.blue);
g.drawOval(center_x-50,center_y-50,100,100);
g.setColor(Color.darkGray);
g.drawString("9",center_x-45,center_y+3);
g.drawString("3",center_x+40,center_y+3);
g.drawString("12",center_x-5,center_y-37);
g.drawString("6",center_x-3,center_y+45);
g.setColor(this.getBackground());
if(second_x!=second_lastx||second_y!=second_lasty)
g.drawLine(center_x,center_y,second_lastx,second_lasty);
if(minute_x!=minute_lastx||minute_y!=minute_lasty)
{
g.drawLine(center_x,center_y-1,minute_lastx,minute_lasty);
g.drawLine(center_x-1,center_y,minute_lastx,minute_lasty);
}
if(hour_x!=hour_lastx||hour_lasty!=hour_lasty)
{
g.drawLine(center_x,center_y-1,hour_lastx,hour_lasty);
g.drawLine(center_x-1,center_y,hour_lastx,hour_lasty);
}
g.setColor(Color.darkGray);
g.drawString(sdateformat.format(new Date(),0,150));
g.setColor(Color.blue);
g.drawLine(center_x,center_y,second_x,second_y);
g.drawLine(center_x,center_y-1,minute_x,minute_y);
g.drawLine(center_x-1,center_y,minute_x,minute_y);
g.drawLine(center_x,center_y-1,hour_x,hour_y);
g.drawLine(center_x-1,center_y,hour_x,hour_y);
second_lastx=second_x;
second_lasty=second_y;
minute_lastx=minute_x;
minute_lasty=minute_y;
hour_lastx=hour_x;
hour_lasty=hour_y;
}
public void start()
{
if(athread==null)
{
athread=new Thread(this);
athread.start();
}
}
public void stop()
{
if(athread!=null)
{
athread.interrupt();
athread=null;
}
}
public void run()
{
while(athread!=null)
{
repaint();
try{
athread.sleep(1000);}
catch(InterruptedException e){
}
}
}
}
[[it] 本帖最后由 zacom 于 2008-10-2 22:06 编辑 [/it]]