Netbeans JavaFx Cant选择主类 [英] Netbeans JavaFx Cant select Main class

查看:82
本文介绍了Netbeans JavaFx Cant选择主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在NetBeans中运行代码时,出现一个空窗口,显示浏览JavaFX应用程序类",但没有可供选择的窗口.我该如何解决?我试图创建一个纸牌游戏. 这是main方法的开始.

When I try to run my code in NetBeans I get a empty window saying "Browse JavaFX Application classes" but there are none to select. How can I solve this? Im trying to create a card game. This is the start to the main method.

import cardutils.Deck;
public class Main {

    public static void main(String[] args) {         
            Deck deck = new Deck();
            System.out.println(deck.toString());
    }
}

推荐答案

如果要创建JavaFX应用程序,则需要创建一个类,该类扩展JavaFX的Application类,并且还包含您的main方法.像这样:

If you want to make a JavaFX application, you need to create a class which extends the Application class of JavaFX and which also contains your main method. So something like this:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class Deck extends Application {

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


   @Override
   public void start(Stage stage) {
      Group root = new Group(new Label("Hello JavaFX!"));
      Scene scene = new Scene(root, 1024, 786);
      stage.setScene(scene);
      stage.show();
   }
}

然后简单地运行项目,Netbeans将找到此类,因为它包含一个main方法,您可以选择它.

And then simply run the project and Netbeans will find this class because it contains a main method and will let you select it.

但是,如果该项目确实不需要JavaFX(我只是想知道,因为您只是在命令行中打印出一些内容),则在创建Netbeans项目时可能选择了错误的项目类型(而不是JavaFX Project)普通的Java项目).在这种情况下,请创建一个新的标准Java项目,并从旧项目中复制代码.

If, however, this project does not really need JavaFX (I just wondered because you're simply printing out something to the command line), you might have selected the wrong project type when creating your Netbeans project (JavaFX Project instead of normal Java Project). In this case create a new standard Java project and copy the code over from the old project.

编辑:具有可用类"的列表为空,因为Netbeans在您似乎已创建的JavaFX项目中找不到任何扩展javafx.application.Application的类.

The list with "available classes" is empty because Netbeans can't find any classes that extend javafx.application.Application inside the JavaFX project you seem to have created.

这篇关于Netbeans JavaFx Cant选择主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆