package fx.com;
import javafx.application.Application;
import javafx.application.ConditionalFeature;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.geometry.Insets;
import javafx.geometry.Rectangle2D;
import javafx.scene.*;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.input.*;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Screen;
import javafx.stage.Stage;
import sun.net.www.content.image.png;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
public class Main extends Application {
public static void main(String[] args) {
launch(Main.class, args);
}
@Override
public void start(Stage primaryStage) throws IOException, InterruptedException {
Button button1 = new Button("这是按钮");
button1.setLayoutX(10);
button1.setLayoutY(10);
button1.setPrefWidth(200);
button1.setPrefHeight(100);
button1.setFont(Font.font(20));
Group group = new Group();
group.getChildren().add(button1);
Scene scene = new Scene(group);
//第一种 win10可能有问题
KeyCombination kc1 = new KeyCodeCombination(KeyCode.C, KeyCombination.ALT_DOWN, KeyCombination.CONTROL_DOWN);
Mnemonic mnemonic1 = new Mnemonic(button1, kc1);
scene.addMnemonic(mnemonic1);
//第二种 win10可能有问题
KeyCombination kc2 = new KeyCharacterCombination("O", KeyCombination.ALT_DOWN);
Mnemonic mnemonic2 = new Mnemonic(button1, kc2);
scene.addMnemonic(mnemonic2);
//第三种 SHORTCUT_DOWN = ctrl 苹果系统也支持
KeyCombination kc3 = new KeyCodeCombination(KeyCode.Z,KeyCombination.SHORTCUT_DOWN);
scene.getAccelerators().put(kc3, new Runnable() {
@Override
public void run() {
System.out.println("方法");
button1.fire();
}
});
button1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("按钮的方法");
}
});
primaryStage.setScene(scene);
URL qunlogoUrl = new URL("http://www.haotuo.net.cn/Resources/cq/qunlogo.png");
primaryStage.setWidth(800);
primaryStage.setHeight(500);
primaryStage.getIcons().add(new Image(qunlogoUrl.toExternalForm()));
primaryStage.setTitle("JavaFX");
primaryStage.show();
}
}