62,628
社区成员
发帖
与我相关
我的任务
分享
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
public class windows extends Application{
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage mystage) {
Text text = new Text("JavaFx");
//text.setFont(Font.font("Times New Roman", 35));
text.setFont(new Font("Times New Roman", 35));
Circle circle = new Circle(100, Color.LIGHTGRAY);
circle.setStroke(Color.BLACK);
StackPane stack = new StackPane(circle, text);
Scene scene = new Scene(stack, 500, 500);
mystage.setScene(scene);
mystage.setTitle("JavaFX");
mystage.show();
}
}

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
public class windows extends Application{
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage mystage) {
Text text = new Text("JavaFx");
//text.setFont(Font.font("Times New Roman", 35));
text.setFont(new Font("Times New Roman", 35));
Circle circle = new Circle(100, Color.LIGHTGRAY);
circle.setStroke(Color.BLACK);
StackPane stack = new StackPane(circle, text);
Scene scene = new Scene(stack, 500, 500);
mystage.setScene(scene);
mystage.setTitle("JavaFX");
mystage.show();
}
}
[/quote]
new对象和万物皆对象有什么矛盾的呢?
你觉得这种方式麻烦,是因为,当时设计这个模块的时候,更加宽松的耦合性。如果你想只调用setFont而不new Font,都没必要用Font.font这种静态方法,使用少又占资源。可以自己包装一层,你想传什么进去,达到什么效果,都自己写。
对于程序来讲,没有好坏,只有不同场景下的适用程度。
再说题主的疑问,个人角度认为,所谓万物皆对象,是指任何物都有它的描述和行为。光线如果是一个对象,肯定是个接口或者抽象类。有不同的光,一束紫外线就是new出来一个实体,属性可以波长、速度、方向等,行为可以是各种发生的事情。
重点是人用语言去总结万物,所以万物成了对象,而不是,天生对象。