0

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();
}
}
1
  • 1
    Didn't you crete a project starting from the Ant template? Try to create a new project with the default Java template, and copy the source code. Commented Jan 8, 2013 at 16:27

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

7 Comments

Run->Run As->(none applicable) It's greyed out.
How do I check to make sure that's true? I created a new java project, pasted the .java files into that project's /src folder, and dragged the files into the IDE so they are open, then tried to Run. Is that correct?
Right-Click in the Java file in the editor and select 'run as ...' from the context menu, not from the top bar menu.
It says selection does not contain a main type. It appears that the 6 class files are not listed in the editor. Is there a faster way than creating 6 new files and pasting the contents of the old files into the new files?
You can copy them to your project src directory, under your Eclipse workspace. Follow the package statement to create the original directory structure, in your example create a directory tree under src/edu/truman/cs260/talpersP3/ and put the files there. You need to refresh the Eclipse browser afterwards.
|
0

As you class has the proper main(..), it should really show "Run as application" in the context menu. Maybe Eclipse project is broken in one or another way. Get the recent version of Eclipse, create a new, empty, simple Java project and copy your files in the source folder of the new project.

1 Comment

I have the most recent build of Eclipse, and I used a simple Java project. I'm guessing this isn't anything I did wrong and should just go and file a trouble ticket.
0

Is your java file on a build path ? If it is not, the eclicpse icon has an outlined 'J' as shown at the icons of eclipse helios.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.