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);
    }
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题