【问题标题】:java and javafx integrated programsjava和javafx集成程序
【发布时间】:2012-01-02 06:24:44
【问题描述】:

我开发了一个桌面数据库应用程序。但是界面并不丰富。所以我想在我的代码中集成 javafx 接口。但是我是javafx的新手,请给出java和javafx集成程序的示例或教程。我在 javafx 站点和其他一些书籍中搜索,但没有得到 java 和 javafx 组合代码。

给我一​​个用 javafx 按钮替换 Jbutton 的代码。

import javax.swing.*;
class Javabutton extends JFrame
{
    JButton b;
    Container con;
    Javabutton()
    {
        b=JButton("hello");
        setLayout(new FlowLayout());
        setSize(400,500);
        con=getContentPane();
        con.add(b);
        setVisible(true);
    }
    public static void main(String args[])
    {
        new Javabutton();
    }
}

`

【问题讨论】:

    标签: java user-interface javafx


    【解决方案1】:

    编写纯javaFX代码比使用JFX和swing更好。

    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.stage.Stage;
    
    public class Hello extends Application
    {
    
        public static void main(String[] args)
        {
            Application.launch(args);
        }
    
        @Override
        public void start(Stage primaryStage)
        {
            primaryStage.setTitle("Button");
            Group root = new Group();
            Scene scene = new Scene(root, 300, 250);
            Button btn = new Button();
    
            btn.setLayoutX(100);
            btn.setLayoutY(80);
            btn.setText("OK");
            btn.setOnAction(new EventHandler<ActionEvent>()
            {
    
                public void handle(ActionEvent event)
                {
                    System.out.println("Hello World");
                }
            });
            root.getChildren().add(btn);
            primaryStage.setScene(scene);
            primaryStage.show();
        }
    }
    

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 2014-04-12
        • 1970-01-01
        • 2012-01-12
        • 1970-01-01
        • 2013-06-01
        • 2014-11-07
        • 2018-07-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多