java找不到主方法,请讲主方法定义为public static void main(String[] args)
importjava.awt.*;publicclassClock{privateinthour;privateintminute;privateintsecond;pu...
import java.awt.*;
public class Clock {
private int hour;
private int minute;
private int second;
public Clock() {
}
public Clock(int hrs,int min,int sec){
hour =hrs % 12;
minute = min;
second = sec;
}
void show (Graphics g,int cx,int cy,int rad){
int hourLenght = (int)(rad * 0.5);//时针的长度
int minuteLenght = (int)(rad * 0.6);//分针的长度
int secondLenght = (int)(rad * 0.9);//秒针的长度
double angle;//角度
//画出钟面
g.drawOval(cx-rad, cy - rad, rad * 2, rad * 2);
//画出时针
angle = (double)(hour*60*60 + minute*60 + second)/43200.0*2.0*Math.PI;
drawNiddle(g,Color.blue, cx, cy, hourLenght,angle);
//画分针
angle = (double)(minute*60 + second)/3600 * 2.0 * Math.PI;
drawNiddle(g,Color.blue, cx, cy, minuteLenght,angle);
// 画秒针
angle = (double)(second)/60*2.0*Math.PI;
drawNiddle(g,Color.blue, cx, cy, secondLenght,angle);
}
private void drawNiddle(Graphics g ,Color c,int x,int y,int len,double angle){
int ex = (int)(x + len * Math.sin(angle));
int ey = (int)(y - len * Math.cos(angle));
g.setColor(c);
g.drawLine(x,y,ex,ey);
}
}
我用的是JCreator软件,这是网上抄的代码,第一次可以运行,但后来不知道怎么回事,求更正。 展开
public class Clock {
private int hour;
private int minute;
private int second;
public Clock() {
}
public Clock(int hrs,int min,int sec){
hour =hrs % 12;
minute = min;
second = sec;
}
void show (Graphics g,int cx,int cy,int rad){
int hourLenght = (int)(rad * 0.5);//时针的长度
int minuteLenght = (int)(rad * 0.6);//分针的长度
int secondLenght = (int)(rad * 0.9);//秒针的长度
double angle;//角度
//画出钟面
g.drawOval(cx-rad, cy - rad, rad * 2, rad * 2);
//画出时针
angle = (double)(hour*60*60 + minute*60 + second)/43200.0*2.0*Math.PI;
drawNiddle(g,Color.blue, cx, cy, hourLenght,angle);
//画分针
angle = (double)(minute*60 + second)/3600 * 2.0 * Math.PI;
drawNiddle(g,Color.blue, cx, cy, minuteLenght,angle);
// 画秒针
angle = (double)(second)/60*2.0*Math.PI;
drawNiddle(g,Color.blue, cx, cy, secondLenght,angle);
}
private void drawNiddle(Graphics g ,Color c,int x,int y,int len,double angle){
int ex = (int)(x + len * Math.sin(angle));
int ey = (int)(y - len * Math.cos(angle));
g.setColor(c);
g.drawLine(x,y,ex,ey);
}
}
我用的是JCreator软件,这是网上抄的代码,第一次可以运行,但后来不知道怎么回事,求更正。 展开
展开全部
你没有main函数。main函数是程序的入口,main函数这样定义:
public static void main(String args[]){
//这里面是函数体
}
public static void main(String args[]){
//这里面是函数体
}
追问
我不知道要加在哪里程序才能运行起来
追答
你这代码都不完整啊,还有代码没贴上来么。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询