【发布时间】:2017-11-10 17:47:00
【问题描述】:
我是面向对象编程的新手(VBA 是我的原始语言),现在我正在学习 Java 以获得有关它的线索。
我的第一个控制台程序是一个小型文本冒险,其中包含 Enemies、Player、Items 等类,这确实帮助我进入了 OOP。
第二个应用是JavaFX中的GUI计算器
我想构建另一个更复杂的 GUI 应用程序,例如 Task-Planner,其中包含更多场景和按钮等。
我真的不明白如何在这样的项目中使用类和对象。
我倾向于像下面这个示例那样把它写下来:
public class FirstGUI extends Application {
Scene scene1, scene2;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("My First JavaFX GUI");
//Scene 1
Label label1 = new Label("This is the first scene");
Button button1 = new Button("Go to scene 2");
button1.setOnAction(e -> primaryStage.setScene(scene2));
VBox layout1 = new VBox(20);
layout1.getChildren().addAll(label1, button1);
scene1 = new Scene(layout1, 300, 250);
//Scene 2
Label label2 = new Label("This is the second scene");
Button button2 = new Button("Go to scene 1");
button2.setOnAction(e -> primaryStage.setScene(scene1));
VBox layout2 = new VBox(20);
layout2.getChildren().addAll(label2, button2);
scene2 = new Scene(layout2, 300, 250);
primaryStage.setScene(scene1);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
我计划了更多的场景和不同的按钮。但是打破一切,我看不出在哪里制作 Classes 或 Object 会帮助我。我觉得定义我所有的按钮、图片、表格和东西并将它们放入布局中是我的natural 方式。
我想错了吗?如果只是 “VBA 思维” 在欺骗我,有人可以帮助我吗?
【问题讨论】:
-
虽然是一个有趣且重要的话题,但这个问题对于 Stack Overflow 来说太宽泛了。这里的问题必须通过特定的解决方案来解决一个狭隘的编程问题。广泛的讨论是题外话。我建议访问JavaRanch.com。
标签: java oop user-interface javafx