Eclipse running the wrong class

I have been encountering a problem with Eclipse IDE for quite a while.Whenever I try to create a new class inside a project and run it, another class of the same or different project runs instead.When I try running the Circle class shown below another class called Main runs. I tried fixing the issue by clicking Run As---->Run Configurations but could not find an item of this class under Java Application.I also tried deleting the main method of the other classes that run instead of the Circle1 class, but it did not work

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class Circle1 extends Application {

    @Override 
    public void start(Stage PrimaryStage) {
        StackPane pane = new StackPane(); 
        Circle circle = new Circle(40); 
        circle.setStroke(new Color(0.7,0.5,0.6,0.76));
        circle.setFill(Color.BLACK); 
        pane.getChildren().add(circle); 
        HBox hBox = new HBox(); 
        hBox.setSpacing(10);
        hBox.setAlignment(Pos.CENTER);
        Button btEnlarge = new Button("Enlarge"); 
        Button btShrink = new Button("Shrink");
        hBox.getChildren().addAll(btEnlarge,btShrink); 
        BorderPane borderPane = new BorderPane(); 
        borderPane.setCenter(pane);
        borderPane.setBottom(hBox);
        BorderPane.setAlignment(hBox, Pos.CENTER);
        Scene scene = new Scene (borderPane,200,150); 
        PrimaryStage.setTitle("ControlCircle"); 
        PrimaryStage.setScene(scene); 
        PrimaryStage.show(); 
    }

    public void main(String[]args) {
        launch(args); 
    }
}

Solution 1:

I tried fixing the issue by clicking Run As---->Run Configurations but could not find an item of this class under Java Application

So , you probably have to create a java application for your project by clicking java application -> New_configuration -> Give a name to the configuration -> browse the project from your workspace and search for your main class . Eclipse should find it for you automatically . Then , to run this specific configuration press the drop down option from the Run button in Eclipse and select the name you just gave . Also the last configuration you run in eclipse is saved ,so to run a different project you need to select it.

.I also tried deleting the main method of the other classes that run instead of the Circle1 class, but it did not work

In my experience each java or javafx applications has one main method ,which launches your scene in your example . Every other class you create in your project shouldn't have a main method . In order to create a class for your project : right click on the src folder of your Java project. In the menu that pops up, open the submenu New ,Eclipse will then show you a dialog for new class creation ,give your class a name and it should look like this:

package com.yourpackage

public class Circle{

}