\nimage of the problem
\nthe ant debug error
import java.time.LocalDateTime;\nimport java.time.ZoneId;\nimport java.time.format.DateTimeFormatter;\nimport java.awt.*;\nimport javax.swing.*;\nimport java.awt.event.*;\nimport java.time.ZoneId;\nimport javax.swing.Timer;\n\npublic class Main {\n public static String GetTime(){\n ZoneId zoneid = ZoneId.of("Asia/Ho_Chi_Minh");\n\n DateTimeFormatter format = DateTimeFormatter.ofPattern("dd/MM/yyyy; HH:mm:ss");\n LocalDateTime localtime = LocalDateTime.now(zoneid);\n String time = localtime.format(format);\n return time;\n }\n public static void WindowOpen(){\n JFrame frame = new JFrame("Time");\n frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n JLabel label = new JLabel(GetTime(),SwingConstants.CENTER);\n label.setPreferredSize(new Dimension(300,100));\n frame.getContentPane().add(label,BorderLayout.CENTER);\n frame.getContentPane().setBackground(Color.decode("#f88379"));\n frame.setLocationRelativeTo(null);\n frame.pack();\n frame.setVisible(true);\n\n Timer timer = new Timer(1000,new ActionListener(){\n public void actionPerformed(ActionEvent a){\n label.setText(GetTime());\n }\n }\n );\n timer.start();\n }\n public static void main(String[] args){\n WindowOpen();\n }\n}\n
\n","author":{"@type":"Person","name":"someonewalkingby"},"upvoteCount":0,"answerCount":1,"acceptedAnswer":null}}Reputation: 1
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
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