如何在JavaFX中创建按钮?
例
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class ButtonExample extends Application {
@Override
public void start(Stage stage) {
//创建一个按钮
Button button = new Button();
//将文本设置为按钮
button.setText("Sample Button");
//设置按钮的位置
button.setTranslateX(150);
button.setTranslateY(60);
//设置舞台
Group root = new Group(button);
Scene scene = new Scene(root, 595, 150, Color.BEIGE);
stage.setTitle("Button Example");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}输出结果
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短