当前位置: 技术问答>java相关
求救,关于一个简单的APPLET的问题!
来源: 互联网 发布时间:2015-04-07
本文导语: 下面是我编写的一个时钟的APPLET! 但运行的结果却不是我想的那样,秒针很正常,但分针和时针却不正常, 我认为,分针和秒针是一样的,但就是不一样,不知道哪里出的问题, 请高手指点一二!谢谢! import java...
下面是我编写的一个时钟的APPLET!
但运行的结果却不是我想的那样,秒针很正常,但分针和时针却不正常,
我认为,分针和秒针是一样的,但就是不一样,不知道哪里出的问题,
请高手指点一二!谢谢!
import java.awt.*;
import java.applet.*;
import java.util.*;
/*
*/
public class Timeapplet extends Applet implements Runnable {
Thread thrd = null;
final int center_x=250,center_y=150;
int lastXSecond = 0,lastYSecond = 0;
int lastXMinute = 0,lastYMinute = 0;
int lastXHour = 0,lastYHour = 0;
Date dumy = new Date();
String lastTime = dumy.toLocaleString();
public void init() {
setBackground(new Color(132, 90, 66));
}
public void paint(Graphics g) {
int x,y,x_second,y_second,second,x_minute,y_minute;
int minute,x_hour,y_hour,hour;
drawScale(g);
Date Thetime = new Date();
second = Thetime.getSeconds();
minute = Thetime.getMinutes();
hour = Thetime.getHours();
String nowTime = Thetime.toLocaleString();
x_second = center_x+(int)(80.0*Math.cos((second-15)/30.0*Math.PI));
y_second = center_y+(int)(80.0*Math.sin((second-15)/30.0*Math.PI));
x_minute = center_x+(int)(70.0*Math.cos((minute-15)/30.0*Math.PI));
y_minute = center_y+(int)(70.0*Math.sin((minute-15)/30.0*Math.PI));
x_hour = center_x+(int)(50.0*Math.cos((hour*30.0+minute/2-90)/180.0*Math.PI));
y_hour = center_y+(int)(50.0*Math.sin((hour*30.0+minute/2-90)/180.0*Math.PI));
g.setColor(getBackground());
if(x_second != lastXSecond) {
g.drawString(lastTime, 200, 40 );
g.drawLine(center_x,center_y-1,lastXSecond,lastYSecond);
g.drawLine(center_x-1,center_y,lastXSecond,lastYSecond);
}
if(x_minute != lastXMinute) {
g.setColor(getBackground());
g.drawLine(center_x,center_y-1,lastXMinute,lastYMinute);
g.drawLine(center_x-1,center_y,lastXMinute,lastYMinute);
}
if(x_hour != lastXHour) {
g.drawLine(center_x,center_y,lastXHour,lastYHour);
g.drawLine(center_x,center_y-1,lastXHour,lastYHour);
g.drawLine(center_x-1,center_y,lastXHour,lastYHour);
g.drawLine(center_x,center_y-2,lastXHour,lastYHour);
g.drawLine(center_x-2,center_y,lastXHour,lastYHour);
}
g.setColor(Color.blue);
g.drawString("USXUE",231,120);
g.drawString(nowTime,200,40 );
g.drawLine(center_x,center_y-1,x_second,y_second);
g.drawLine(center_x-1,center_y,x_second,y_second);
g.setColor(Color.green);
g.drawLine(center_x,center_y-1,x_minute,y_minute);
g.drawLine(center_x-1,center_y,x_minute,y_minute);
g.setColor(Color.yellow);
g.drawLine(center_x,center_y,x_hour,y_hour);
g.drawLine(center_x,center_y-1,x_hour,y_hour);
g.drawLine(center_x-1,center_y,x_hour,y_hour);
g.drawLine(center_x,center_y-2,x_hour,y_hour);
g.drawLine(center_x-2,center_y,x_hour,y_hour);
lastXSecond = x_second;
lastYSecond = y_second;
lastXMinute = x_minute;
lastXMinute = y_minute;
lastXHour = x_hour;
lastXHour = y_hour;
lastTime = nowTime;
}
public void drawScale(Graphics g) {
int x,y;
g.setColor(Color.blue);
g.drawOval(center_x-96,center_y-96,192,192);
for(int i=0;i
但运行的结果却不是我想的那样,秒针很正常,但分针和时针却不正常,
我认为,分针和秒针是一样的,但就是不一样,不知道哪里出的问题,
请高手指点一二!谢谢!
import java.awt.*;
import java.applet.*;
import java.util.*;
/*
*/
public class Timeapplet extends Applet implements Runnable {
Thread thrd = null;
final int center_x=250,center_y=150;
int lastXSecond = 0,lastYSecond = 0;
int lastXMinute = 0,lastYMinute = 0;
int lastXHour = 0,lastYHour = 0;
Date dumy = new Date();
String lastTime = dumy.toLocaleString();
public void init() {
setBackground(new Color(132, 90, 66));
}
public void paint(Graphics g) {
int x,y,x_second,y_second,second,x_minute,y_minute;
int minute,x_hour,y_hour,hour;
drawScale(g);
Date Thetime = new Date();
second = Thetime.getSeconds();
minute = Thetime.getMinutes();
hour = Thetime.getHours();
String nowTime = Thetime.toLocaleString();
x_second = center_x+(int)(80.0*Math.cos((second-15)/30.0*Math.PI));
y_second = center_y+(int)(80.0*Math.sin((second-15)/30.0*Math.PI));
x_minute = center_x+(int)(70.0*Math.cos((minute-15)/30.0*Math.PI));
y_minute = center_y+(int)(70.0*Math.sin((minute-15)/30.0*Math.PI));
x_hour = center_x+(int)(50.0*Math.cos((hour*30.0+minute/2-90)/180.0*Math.PI));
y_hour = center_y+(int)(50.0*Math.sin((hour*30.0+minute/2-90)/180.0*Math.PI));
g.setColor(getBackground());
if(x_second != lastXSecond) {
g.drawString(lastTime, 200, 40 );
g.drawLine(center_x,center_y-1,lastXSecond,lastYSecond);
g.drawLine(center_x-1,center_y,lastXSecond,lastYSecond);
}
if(x_minute != lastXMinute) {
g.setColor(getBackground());
g.drawLine(center_x,center_y-1,lastXMinute,lastYMinute);
g.drawLine(center_x-1,center_y,lastXMinute,lastYMinute);
}
if(x_hour != lastXHour) {
g.drawLine(center_x,center_y,lastXHour,lastYHour);
g.drawLine(center_x,center_y-1,lastXHour,lastYHour);
g.drawLine(center_x-1,center_y,lastXHour,lastYHour);
g.drawLine(center_x,center_y-2,lastXHour,lastYHour);
g.drawLine(center_x-2,center_y,lastXHour,lastYHour);
}
g.setColor(Color.blue);
g.drawString("USXUE",231,120);
g.drawString(nowTime,200,40 );
g.drawLine(center_x,center_y-1,x_second,y_second);
g.drawLine(center_x-1,center_y,x_second,y_second);
g.setColor(Color.green);
g.drawLine(center_x,center_y-1,x_minute,y_minute);
g.drawLine(center_x-1,center_y,x_minute,y_minute);
g.setColor(Color.yellow);
g.drawLine(center_x,center_y,x_hour,y_hour);
g.drawLine(center_x,center_y-1,x_hour,y_hour);
g.drawLine(center_x-1,center_y,x_hour,y_hour);
g.drawLine(center_x,center_y-2,x_hour,y_hour);
g.drawLine(center_x-2,center_y,x_hour,y_hour);
lastXSecond = x_second;
lastYSecond = y_second;
lastXMinute = x_minute;
lastXMinute = y_minute;
lastXHour = x_hour;
lastXHour = y_hour;
lastTime = nowTime;
}
public void drawScale(Graphics g) {
int x,y;
g.setColor(Color.blue);
g.drawOval(center_x-96,center_y-96,192,192);
for(int i=0;i