The Java program can not run as a Java application

advertisements

I'm trying to run a Java project I made for a class a year ago, however I'm running into some issues.

When I try to run this java project, there is no option in eclipse to run it as a java application. Instead, it only allows me to select Ant Build, which upon selection, throws the error: Unable to find Ant file to run. My code includes a main function, therefore the question arises: why is my code not just running the main function?

Note: I don't want to have to post my entire code as it is nearly a thousand lines long and split into 6 classes, however if I get a comment requesting the entirety, I will. Included is just the main class.

I notice the top of the other classes includes the line package edu.truman.cs260.talpersP3;. I simply downloaded these java files from my email inbox, so do I need to somehow package them?

My main class:

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


Open the Java file with the main class in the editor, then right click and select 'run as ... Java Application' from the context menu.