SHARE
TWEET

Untitled

a guest Apr 19th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package oop;
  2.  
  3. import javafx.application.Application;
  4. import javafx.event.EventHandler;
  5. import javafx.scene.Group;
  6. import javafx.scene.Scene;
  7. import javafx.scene.canvas.Canvas;
  8. import javafx.scene.control.Button;
  9. import javafx.scene.control.Label;
  10. import javafx.scene.control.PasswordField;
  11. import javafx.scene.control.Slider;
  12. import javafx.scene.input.MouseEvent;
  13. import javafx.scene.layout.BorderPane;
  14. import javafx.scene.layout.StackPane;
  15. import javafx.scene.paint.Color;
  16. import javafx.scene.shape.Circle;
  17. import javafx.stage.Stage;
  18.  
  19. import java.util.Random;
  20.  
  21. public class Ylesanne4 extends Application {
  22.  
  23.     /*Kirjutada programm, mis loob akna ja lisab aknasse mingile kohale nupu. Sündmuste abil korraldada, et hiirega
  24.     nupule liikudes "hüppab" nupp eest ära juhuslikule kohale aknas. Tagada, et nupp ei hüppaks aknast välja (ka peale
  25.     akna suuruste muutmist).     */
  26.  
  27.     @Override
  28.     public void start(Stage peaLava) throws Exception {
  29.  
  30.         //StackPane juur = new StackPane();
  31.         Group juur=new Group();
  32.         Canvas lõuend=new Canvas(300,400);
  33.         juur.getChildren().add(lõuend);
  34.         Button nupp1 = new Button("Hihihii");
  35.         juur.getChildren().add(nupp1);
  36.  
  37.         nupp1.setOnMouseEntered(new EventHandler<MouseEvent>() {
  38.             public void handle(MouseEvent me) {
  39.  
  40.                 Random random = new Random();
  41.                 nupp1.setLayoutX(random.nextInt((int)(lõuend.getWidth())));
  42.                 nupp1.setLayoutY(random.nextInt((int)(lõuend.getHeight())));
  43.             }
  44.         });
  45.  
  46.         Scene stseen1 = new Scene(juur, 400, 500, Color.SNOW);
  47.  
  48.         lõuend.widthProperty().bind(peaLava.widthProperty());
  49.         lõuend.heightProperty().bind(peaLava.heightProperty());
  50.  
  51.         peaLava.setTitle("Paigutus");
  52.         peaLava.setScene(stseen1);
  53.         peaLava.show();
  54.  
  55.     }
  56.  
  57.     public static void main(String[] args) {
  58.         launch(args);
  59.     }
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top