繁体   English   中英

Eclipse 的 not Run As 不显示 Java Application

[英]Eclipse's not Run As does not show Java Application

我正在为 Java 开发人员使用 Eclipse IDE - 2021-12。 我在这里处理的代码在所有其他代码编辑器上都可以正常工作,但我无法在这个代码编辑器上运行它。 我曾尝试过其他方法来解决此问题,但到目前为止还没有奏效。
问题的图像
ant 调试错误

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.time.ZoneId;
import javax.swing.Timer;

public class Main {
  public static String GetTime(){
    ZoneId zoneid = ZoneId.of("Asia/Ho_Chi_Minh");

    DateTimeFormatter format = DateTimeFormatter.ofPattern("dd/MM/yyyy; HH:mm:ss");
    LocalDateTime localtime = LocalDateTime.now(zoneid);
    String time = localtime.format(format);
    return time;
  }
  public static void WindowOpen(){
    JFrame frame = new JFrame("Time");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel(GetTime(),SwingConstants.CENTER);
    label.setPreferredSize(new Dimension(300,100));
    frame.getContentPane().add(label,BorderLayout.CENTER);
    frame.getContentPane().setBackground(Color.decode("#f88379"));
    frame.setLocationRelativeTo(null);
    frame.pack();
    frame.setVisible(true);

    Timer timer = new Timer(1000,new ActionListener(){
      public void actionPerformed(ActionEvent a){
        label.setText(GetTime());
      }
    }
    );
    timer.start();
  }
  public static void main(String[] args){
    WindowOpen();
  }
}

您的源文件不在Java ProjectSource Folder下,它在您的桌面上。 您不能在 Eclipse 中任意运行.java源文件——没有地方可以构建正确的运行时类路径,包括哪个 JRE。

使用向导创建Java 项目,并将源文件放入为您创建的源文件夹中。 然后你就可以运行它了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM