日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java的解释程序_JAVA改错和程序解释

發(fā)布時間:2024/2/28 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java的解释程序_JAVA改错和程序解释 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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]]

搜索更多相關的解決方案:

JAVA??改錯??解釋

----------------解決方案--------------------------------------------------------

int second_x=(int)(Math.cos(second*Math.PI/30-Math.PI/2)*45+center_x);

這個是算秒針末尾的坐標X。用秒數(shù)換算成角度(比如30秒,剛好是PI(180度))具體點就是:指針的長度是固定的,所以它的橫坐標是根據(jù)其水平夾角去算,你畫個圖就知道了

45是指指針的長度,分針短點(40)

g.drawString(sdateformat.format(new Date(),0,150));

就是畫一個字符串(時間格式)

----------------解決方案--------------------------------------------------------

回復 2# nuciewth 的帖子

你說的我明白。。但是我不知道為什么second*Math.PI/30-Math.PI/2這個能求出角度。。請解釋下

----------------解決方案--------------------------------------------------------

貌似你會解釋下面一道題的話就OK了

數(shù)學題:已知一圓的半徑R和圓心坐標(X,Y),以垂直向上為起始邊,圓心為端點,做圓心角為A的射線交圓與M,求M 的坐標

畫個圖吧,你就會很清楚

還有就是秒數(shù)就對應了角度。

----------------解決方案--------------------------------------------------------

你說的那個我會做。。但還是不明白我那問題。。MATH。PI能做什么,煩了很久了

[[it] 本帖最后由 zacom 于 2008-10-4 19:21 編輯 [/it]]

----------------解決方案--------------------------------------------------------

角度換算成弧度啊,不是要用到PI(3.1415926)

----------------解決方案--------------------------------------------------------

回復 6# nuciewth 的帖子

難道我用的方法和你的不一樣。。我都不用使用到PI。。暈

----------------解決方案--------------------------------------------------------

你的程序就是這樣做的。

----------------解決方案--------------------------------------------------------

這個是教材上的基本例題。。。自己看看啊

----------------解決方案--------------------------------------------------------

呵呵 鉆進牛角尖了

他肯定是被 Math.PI 給弄得頭暈了

----------------解決方案--------------------------------------------------------

總結

以上是生活随笔為你收集整理的java的解释程序_JAVA改错和程序解释的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。