someonewalkingby
someonewalkingby

Reputation: 1

Eclipse's not Run As does not show Java Application

I am using Eclipse IDE for Java Developers - 2021-12. The code I am working on here works fine on every other code editor, but I cannot run it on this one. I had tried other ways to fix this but it has not worked so far.
image of the problem
the ant debug error

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

Upvotes: 0

Views: 73

Answers (1)

nitind
nitind

Reputation: 20033

You source file is not under a Java Project's Source Folder, it's on your Desktop. You can't arbitrarily run .java source files in Eclipse--there's no place from which to construct the correct runtime classpath, including which JRE.

Create a Java Project using the wizard and put your source file into the Source Folder that's created for you. Then you will be able to run it.

Upvotes: 1

Related Questions