我正在尝试运行一年前为一个班级制作的 Java 项目,但是我遇到了一些问题。
当我尝试运行这个 java 项目时,eclipse 中没有选项可以将它作为 java 应用程序运行。相反,它只允许我 select Ant Build
,它在选择时会引发错误:Unable to find Ant file to run.
我的代码包含一个 main 函数,因此出现了问题:为什么我的代码不只是运行 main 函数?
注意:我不想发布我的整个代码,因为它有近一千行长并分为 6 个类,但是如果我收到要求全部的评论,我会的。包括的只是主要课程。
我注意到其他类的顶部包括该行package edu.truman.cs260.talpersP3;
。我只是从我的电子邮件收件箱中下载了这些 java 文件,所以我需要以某种方式打包它们吗?
我的主要课程:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import edu.truman.cs260.talpersP3.*;
public class TalpersProject3
{
private static final int FRAMES_PER_SECOND = 24;
private static final int ICON_WIDTH = 500;
private static final int ICON_HEIGHT = 500;
private static final int DELAY = 1000 / FRAMES_PER_SECOND;
public static void main(String[] args)
{
//constructs the AnimationComponent
final AnimationComponent a = new AnimationComponent();
//creates frame and buttonpanel
JFrame frame = new JFrame();
JPanel buttonpanel;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//declares the two buttons
JButton squarebutton = new JButton("Square");
JButton circlebutton = new JButton("Circle");
//button implementation
squarebutton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
a.add(new BouncySquare(50, 50, 100));
a.repaint();
}
});
circlebutton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
a.add(new BouncyCircle(50, 50, 50));
a.repaint();
}
});
//sets the size of the AnimationComponent
a.setSize(ICON_WIDTH,ICON_HEIGHT);
//constructs the buttonpanel
buttonpanel = new JPanel();
//adds the 2 buttons to the panel
buttonpanel.add(squarebutton);
buttonpanel.add(circlebutton);
//frame layout and formatting
frame.setLayout(new BorderLayout());
frame.add(buttonpanel, BorderLayout.SOUTH);
frame.add(a, BorderLayout.CENTER);
frame.setSize(ICON_WIDTH, ICON_HEIGHT+100);
frame.setVisible(true);
//construction of the timer
Timer t = new Timer(DELAY, new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
a.bounceCall(); //checks bounds and translates
a.repaint();
}
});
//timer starts
t.start();
}
}