初学者; GUI没有出现?

时间:2017-04-10 22:32:30

标签: java javafx

我是java和编码的新手。我尝试搜索此问题但无法找到解决方案。

我在纸上给出了这个代码作为例子。我试图在Eclipse中重新创建它,但是当我运行代码时,没有任何反应(没有gui popup或类似的东西)。它也无法在jGrasp中运行。谁知道出了什么问题?

由于

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;

import javafx.scene.layout.FlowPane;

import javafx.stage.Stage;
import javafx.scene.media.AudioClip;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;

public class AudioShuffle extends Application {
    private AudioClip audio1;
    private AudioClip audio2;
    private AudioClip audio3;
    private AudioClip audio4;
    private Button play, stop, shuffle;

    @Override
    public void start(Stage primaryStage) {

        String clipURL = "http://www.music.helsinki.fi/tmt/opetus/uusmedia/esim/a2002011001-e02-16kHz.wav";
        audio1 = new AudioClip(clipURL);
        play=new Button("PLAY");
        play.setStyle("-fx-font:20 Arial");
        stop=new Button("STOP");
        stop.setStyle("-fx-font:20 Arial");

        play.setOnAction(this::processButtonPress);
        stop.setOnAction(this::processButtonPress);

        FlowPane pane = new FlowPane(play, stop);
        pane.setAlignment(Pos.CENTER);
        pane.setHgap(20);
        pane.setStyle("=fx=background=color: cyan");

        Scene scene = new Scene(pane, 300,100);

        primaryStage.setTitle("Audio Playlist");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public void processButtonPress(ActionEvent event){
        if(event.getSource()==play){
            audio1.play();
        }
        else if(event.getSource()==stop){
            audio1.stop();
        }
    }

    public static void main(String[] args){
    }
}

0 个答案:

没有答案