weixin_40125606 2018-05-27 17:01 采纳率: 50%
浏览 1049
已结题

JAVA中提示我在类 Clock 中找不到主方法要怎么解决

代码如下:
图片说明
运行后一直提示错误: 在类 Clock 中找不到主方法, 请将主方法定义为:
public static void main(String[] args)

初学小白求解答

  • 写回答

7条回答 默认 最新

  • weixin_40125606 2018-05-27 17:03
    关注

    这是完整代码:
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    import java.text.SimpleDateFormat;
    public class Clock extends JApplet implements Runnable
    {
    Thread clockThread1;
    Thread clockThread2;
    Thread clockThread3;
    boolean f1,f2,f3;

    SimpleDateFormat formatter;
    
    Date currentDate1,currentDate2,currentDate3;
    String lastdate1,lastdate2,lastdate3;
    
    public void init()
    {
        super.setBackground(Color.LIGHT_GRAY);
        formatter=new SimpleDateFormat("hh:mm:ss",Locale.getDefault());
        currentDate1=new Date();
        lastdate3=lastdate2=lastdate1=formatter.format(currentDate1);
    
        clockThread1=new Thread(this,"Clock-thread1");
        clockThread2=new Thread(this,"Clock-thread2");
        clockThread3=new Thread(this,"Clock-thread3");
        clockThread1.start();
        clockThread2.start();
        clockThread3.start();
    }
    public void run()
    {
        boolean flag=true;
        while(flag)
        {
            try
            {
                if (Thread.currentThread() == clockThread1){
                    Thread.sleep(1000);
                    f1 = true;
                }
                if (Thread.currentThread() == clockThread2){
                    Thread.sleep(2000);
                    f2 = true;
                }
                if (Thread.currentThread() == clockThread3){
                    Thread.sleep(3000);
                    f3 = true;
                }
                super.repaint();
            }
            catch(InterruptedException e)
            {
                flag=false;
            }
        }
    }
    public void paint (Graphics g)
    {
        g.setColor(this.getBackground());
        if (f1){
            currentDate1=new Date();
            lastdate1=formatter.format(currentDate1);
            g.fillRect(5, 0, 50, 10);
            f1 = false;
        }
        if (f2){
            currentDate2=new Date();
            lastdate2=formatter.format(currentDate2);
            g.fillRect(125, 0, 50, 10);
            f2 = false;
        }
        if (f3){
            currentDate3=new Date();
            lastdate3=formatter.format(currentDate3);
            g.fillRect(225, 0, 50, 10);
            f3 =false;
        }
        g.setColor(getForeground());
        g.drawString(lastdate1,5,10);
        g.drawString(lastdate2,125,10);
        g.drawString(lastdate3,225,10);
    }
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试