0

I'm writing a GUI application in Java, and using Eclipse. However, the result of the code behaves differently when I compile and run using command line vs in the IDE itself. Here's the code:

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.PasswordField;

public class MainGUI extends Application
{
    public static void main (String args[])
    {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception 
    {
     primaryStage.setTitle("Citation Machine");
     GridPane grid1 = new GridPane();
     grid1.setAlignment(Pos.CENTER);
     grid1.setHgap(10);
     grid1.setVgap(10);
     grid1.setPadding(new Insets(20, 0, 0, 0));
     Label l = new Label("Welcome. Please enter your URL.");
     grid1.add(l, 0, 0);
     TextField urlField = new TextField();
     grid1.add(urlField, 0, 1);
     Button submit = new Button("OK");
     submit.setOnAction(e -> System.out.println(urlField.getText()));
     grid1.add(submit, 1, 1);

     GridPane grid = new GridPane();
     grid.setAlignment(Pos.TOP_CENTER);
     grid.setHgap(10);
     grid.setVgap(10);
     grid.setPadding(new Insets(20, 0, 0, 0));
     Text scenetitle = new Text("Welcome");
     scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
     grid.add(scenetitle, 0, 0, 2, 1);

     Label titleLabel = new Label("Article Title:");
     grid.add(titleLabel, 0, 1);

     TextField title = new TextField();
     grid.add(title, 1, 1);

     Label authorLabel = new Label("Author:");
     grid.add(authorLabel, 0, 2);

     TextField author = new TextField();
     grid.add(author, 1, 2);

     Label webTitleLabel = new Label("Website Title:");
     grid.add(webTitleLabel, 0, 3 );

     TextField webTitle = new TextField();
     grid.add(webTitle, 1, 3);

     Label publisherLabel = new Label("Website Publisher:");
     grid.add(publisherLabel, 0, 4);

     TextField publisher = new TextField();
     grid.add(publisher, 1, 4);

     Label urlLabel = new Label("URL:");
     grid.add(urlLabel, 0, 5);

     TextField url = new TextField();
     grid.add(url, 1, 5);

     Label monthLabel = new Label("Month of Publication:");
     grid.add(monthLabel, 0, 6);

     TextField month = new TextField();
     grid.add(month, 1, 6);

     Label dayLabel = new Label("Day of Publication");
     grid.add(dayLabel, 0, 7);

     TextField day = new TextField();
     grid.add(day, 1, 7);

     Label yearLabel = new Label("Year of Publication:");
     grid.add(yearLabel, 0, 8);

     TextField year = new TextField();
     grid.add(year, 1, 8);

   //  grid.setGridLinesVisible(true);
     Scene urlChecker = new Scene(grid1, 300, 150);
     Scene information = new Scene(grid, 400, 500);
     primaryStage.setScene(urlChecker);
     primaryStage.show();
    }

}

When I compile and run through CL, it works as expected, printing "pressed" to the CL when the button is clicked. When I run it through the IDE, nothing happens. Why does this occur?

  • is a different Java version associated with the IDE compared to the command line? – brw59 Apr 23 '18 at 23:35
  • @brw59 how would I check that? –  Apr 23 '18 at 23:35
  • Convert your lambda expression to a method so you can set a breakpoint in it. – Thorbjørn Ravn Andersen Apr 23 '18 at 23:36
  • 1
    Works fine for me, using Eclipse. Most likely explanation is that the project needs rebuilding, and it's somehow running an old version of the project which was compiled before you added the button handler. Try cleaning and rebuilding the project in your IDE. – James_D Apr 23 '18 at 23:37
  • to check version: https://stackoverflow.com/questions/22385457/how-to-check-for-the-jre-version-in-eclipse – brw59 Apr 23 '18 at 23:38
  • @James_D I cleaned it and tried running it again, but it gives me a ClassNotFound exception. –  Apr 23 '18 at 23:38
  • What class can't it find? – James_D Apr 23 '18 at 23:38
  • @James_D MainGUI –  Apr 23 '18 at 23:39
  • Sounds like you cleaned the project but it hasn't been rebuilt. Is it set to build automatically? – James_D Apr 23 '18 at 23:39
  • @James_D It might not be set to rebuild automatically. How would I rebuild? –  Apr 23 '18 at 23:40
  • I don't even know which IDE you are using. – James_D Apr 23 '18 at 23:41
  • @James_D It actually is set to build automatically, my bad. –  Apr 23 '18 at 23:41
  • @James_D Eclipse –  Apr 23 '18 at 23:41
  • Well, if it can't find your main class, it clearly isn't built.... Try unchecking "Build Automatically" from the Project menu, then choose "Build Project" to force a build... – James_D Apr 23 '18 at 23:42
  • @James_D I did that, it still throws the same exception –  Apr 23 '18 at 23:43
  • 1
    Something is seriously messed up in your project configuration if it can't find the class you're trying to execute after building. Check through the build configurations and run configurations to make sure everything makes sense. – James_D Apr 23 '18 at 23:45

0 Answers0