Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package Primer1;
- import java.util.Locale;
- import javafx.scene.control.TextField;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.FlowPane;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.StackPane;
- import javafx.stage.Stage;
- import javax.swing.JOptionPane;
- /**
- *
- * @author student
- */
- public class Primer1 extends Application
- {
- @Override
- public void start(Stage primaryStage)
- {
- BorderPane root = new BorderPane();
- Button clear = new Button("Clear");
- FlowPane top = new FlowPane();
- TextField txtUnos = new TextField("");
- txtUnos.setDisable(true);
- top.getChildren().add(txtUnos);
- top.getChildren().add(clear);
- top.setAlignment(Pos.CENTER);
- top.setPadding(new Insets(20));
- root.setTop(top);
- //Grid center
- GridPane center = new GridPane();
- Button btn1 = new Button("1");
- Button btn2 = new Button("2");
- Button btn3 = new Button("3");
- Button btn4 = new Button("4");
- Button btn5 = new Button("5");
- Button btn6 = new Button("6");
- Button btn7 = new Button("7");
- Button btn8 = new Button("8");
- Button btn9 = new Button("9");
- Button btn0 = new Button("0");
- Button btnZarez = new Button(".");
- Button btnJednako = new Button("=");
- center.add(btn7, 0, 0);
- center.add(btn8, 1, 0);
- center.add(btn9, 2, 0);
- center.add(btn4, 0, 1);
- center.add(btn5, 1, 1);
- center.add(btn6, 2, 1);
- center.add(btn1, 0, 2);
- center.add(btn2, 1, 2);
- center.add(btn3, 2, 2);
- center.add(btnZarez, 0, 3);
- center.add(btn0, 1, 3);
- center.add(btnJednako, 2, 3);
- root.setCenter(center);
- center.setAlignment(Pos.CENTER);
- center.setHgap(25);
- center.setVgap(25);
- GridPane right = new GridPane();
- Button btnMnozenje = new Button("*");
- Button btnDeljenje = new Button("/");
- Button btnSabiranje = new Button("+");
- Button btnOduzimanje = new Button("-");
- right.add(btnMnozenje, 0, 1);
- right.add(btnDeljenje, 0, 2);
- right.add(btnOduzimanje, 0, 3);
- right.add(btnSabiranje, 0, 4);
- root.setRight(right);
- right.setAlignment(Pos.CENTER);
- right.setHgap(25);
- right.setVgap(25);
- Scene scene = new Scene(root, 300, 300);
- primaryStage.setTitle("Digitron");
- primaryStage.setScene(scene);
- primaryStage.setResizable(false);
- primaryStage.show();
- btn1.setOnAction(e->
- {
- txtUnos.appendText("1");
- });
- btn2.setOnAction(e->
- {
- txtUnos.appendText("2");
- });
- btn3.setOnAction(e->
- {
- txtUnos.appendText("3");
- });
- btn4.setOnAction(e->
- {
- txtUnos.appendText("4");
- });
- btn5.setOnAction(e->
- {
- txtUnos.appendText("5");
- });
- btn6.setOnAction(e->
- {
- txtUnos.appendText("6");
- });
- btn7.setOnAction(e->
- {
- txtUnos.appendText("7");
- });
- btn8.setOnAction(e->
- {
- txtUnos.appendText("8");
- });
- btn9.setOnAction(e->
- {
- txtUnos.appendText("9");
- });
- btn0.setOnAction(e->
- {
- txtUnos.appendText("0");
- });
- clear.setOnAction(e->
- {
- txtUnos.clear();
- });
- btnMnozenje.setOnAction(e->
- {
- txtUnos.appendText("*");
- });
- btnDeljenje.setOnAction(e->
- {
- txtUnos.appendText("/");
- });
- btnSabiranje.setOnAction(e->
- {
- txtUnos.appendText("+");
- });
- btnOduzimanje.setOnAction(e->
- {
- txtUnos.appendText("-");
- });
- btnZarez.setOnAction(e->
- {
- txtUnos.appendText(".");
- });
- btnJednako.setOnAction(e->
- {
- String pom = txtUnos.getText();
- char niz[] = pom.toCharArray();
- int i = 0;
- for(i = 0; i < pom.length(); i++)
- {
- if(niz[i] == '*' || niz[i] == '/' || niz[i] == '+' || niz[i] == '/')
- {
- break;
- }
- }
- String a = pom.substring(0, i);
- a = a.trim();
- String b = pom.substring(i+1, pom.length());
- b = b.trim();
- if(niz[i] == '*')
- {
- double broj1 = Double.parseDouble(a);
- double broj2 = Double.parseDouble(b);
- double rez = broj1 * broj2;
- JOptionPane.showMessageDialog(null, "Rezultat je :" + rez);
- }
- else if(niz[i] == '/')
- {
- double broj1 = Double.parseDouble(a);
- double broj2 = Double.parseDouble(b);
- double rez = broj1 / broj2;
- JOptionPane.showMessageDialog(null, "Rezultat je :" + rez);
- }
- else if(niz[i] == '+')
- {
- double broj1 = Double.parseDouble(a);
- double broj2 = Double.parseDouble(b);
- double rez = broj1 + broj2;
- JOptionPane.showMessageDialog(null, "Rezultat je :" + rez);
- }
- else if(niz[i] == '-')
- {
- double broj1 = Double.parseDouble(a);
- double broj2 = Double.parseDouble(b);
- double rez = broj1 - broj2;
- JOptionPane.showMessageDialog(null, "Rezultat je :" + rez);
- }
- });
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package crtanje;
- import javafx.animation.PathTransition;
- import javafx.animation.Timeline;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.ColorPicker;
- import javafx.scene.control.ComboBox;
- import javafx.scene.layout.Pane;
- import javafx.scene.layout.StackPane;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Circle;
- import javafx.scene.shape.LineTo;
- import javafx.scene.shape.MoveTo;
- import javafx.scene.shape.Path;
- import javafx.scene.shape.Polygon;
- import javafx.scene.shape.Rectangle;
- import javafx.stage.Stage;
- import javafx.util.Duration;
- /**
- *
- * @author student
- */
- public class Crtanje extends Application
- {
- @Override
- public void start(Stage primaryStage)
- {
- Pane p = new Pane();
- ComboBox<Integer> combo = new ComboBox<>();
- combo.getItems().addAll(1, 2, 3, 4, 5);
- combo.setLayoutX(150);
- combo.setValue(1);
- ColorPicker picker = new ColorPicker();
- Path path = new Path();
- path.setStroke(Color.BLACK);
- path.setStrokeWidth(2);
- p.getChildren().addAll(path, picker, combo);
- p.setOnMousePressed(e->
- {
- if(e.isPrimaryButtonDown())
- {
- path.setStroke(picker.getValue());
- path.setStrokeWidth(combo.getValue());
- path.getElements().add(new MoveTo(e.getX(),e.getY()));
- }
- else
- {
- path.getElements().clear();
- }
- });
- p.setOnMouseDragged(e->
- {
- path.getElements().add(new LineTo(e.getX(),e.getY()));
- });
- primaryStage.setScene(new Scene(p, 500, 500));
- primaryStage.setTitle("Crtanje");
- primaryStage.show();
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- launch(args);
- }
- }
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package primer2;
- import java.io.File;
- import java.util.Scanner;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.Pane;
- import javafx.scene.layout.StackPane;
- import javafx.stage.FileChooser;
- import javafx.stage.FileChooser.ExtensionFilter;
- import javafx.stage.Stage;
- /**
- *
- * @author student
- */
- public class Primer2 extends Application {
- @Override
- public void start(Stage primaryStage)
- {
- Pane p = new Pane();
- Button dugme = new Button("Otvori Fajl");
- dugme.setLayoutX(200);
- dugme.setLayoutY(200);
- p.getChildren().add(dugme);
- primaryStage.setScene(new Scene(p, 500, 500));
- primaryStage.setTitle("Fajlovi");
- primaryStage.show();
- dugme.setOnAction(e->
- {
- FileChooser fc = new FileChooser();
- fc.getExtensionFilters().addAll(new ExtensionFilter("Text","*.txt"));
- File izabranFajl = fc.showOpenDialog(null);
- if(izabranFajl != null)
- {
- try
- {
- Scanner scanner = new Scanner(izabranFajl);
- while(scanner.hasNextLine())
- {
- System.out.println(scanner.nextLine());
- }
- scanner.close();
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- }
- }
- });
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package fade;
- import java.util.concurrent.TimeUnit;
- import javafx.animation.FadeTransition;
- import javafx.animation.Timeline;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.input.KeyCode;
- import javafx.scene.layout.Pane;
- import javafx.scene.layout.StackPane;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Circle;
- import javafx.scene.shape.Rectangle;
- import javafx.stage.Stage;
- import javafx.util.Duration;
- /**
- *
- * @author student
- */
- public class Fade extends Application
- {
- @Override
- public void start(Stage primaryStage)
- {
- Circle krug = new Circle();
- krug.setRadius(50);
- krug.setFill(Color.RED);
- krug.setLayoutX(250);
- krug.setLayoutY(160);
- krug.setVisible(false);
- Circle krug1 = new Circle();
- krug1.setRadius(50);
- krug1.setFill(Color.ORANGE);
- krug1.setLayoutX(250);
- krug1.setLayoutY(280);
- krug1.setVisible(false);
- Circle krug2 = new Circle();
- krug2.setRadius(50);
- krug2.setFill(Color.GREEN);
- krug2.setLayoutX(250);
- krug2.setLayoutY(400);
- krug2.setVisible(false);
- Rectangle pravougaonik = new Rectangle();
- pravougaonik.setFill(Color.TRANSPARENT);
- pravougaonik.setStroke(Color.BLACK);
- pravougaonik.setWidth(200);
- pravougaonik.setHeight(370);
- pravougaonik.setLayoutX(150);
- pravougaonik.setLayoutY(100);
- Pane p = new Pane();
- Button start = new Button("Start");
- Button pauza = new Button("Pauza");
- p.getChildren().addAll(krug, start, pauza, pravougaonik, krug1, krug2);
- start.setLayoutX(50);
- start.setLayoutY(50);
- pauza.setLayoutX(150);
- pauza.setLayoutY(50);
- FadeTransition fade = new FadeTransition();
- fade.setNode(krug);
- fade.setAutoReverse(true);
- fade.setFromValue(1);
- fade.setToValue(0);
- fade.setCycleCount(Timeline.INDEFINITE);
- fade.setDuration(Duration.seconds(1));
- fade.setDelay(Duration.seconds(2));
- Scene scena = new Scene(p, 500, 500);
- primaryStage.setScene(scena);
- primaryStage.setResizable(false);
- primaryStage.setTitle("Fade");
- primaryStage.show();
- scena.setOnKeyPressed(e->
- {
- if(e.getCode() == KeyCode.NUMPAD8)
- {
- krug.setVisible(true);
- krug1.setVisible(false);
- krug2.setVisible(false);
- animacija(krug);
- }
- else if(e.getCode() == KeyCode.NUMPAD5)
- {
- krug.setVisible(false);
- krug1.setVisible(true);
- krug2.setVisible(false);
- animacija(krug1);
- }
- else if(e.getCode() == KeyCode.NUMPAD2)
- {
- krug.setVisible(false);
- krug1.setVisible(false);
- krug2.setVisible(true);
- animacija(krug2);
- }
- });
- start.setOnAction(e->
- {
- fade.play();
- });
- pauza.setOnAction(e->
- {
- fade.pause();
- });
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- launch(args);
- }
- public void animacija(Circle krug)
- {
- FadeTransition fade = new FadeTransition();
- fade.setNode(krug);
- fade.setAutoReverse(false);
- fade.setFromValue(0);
- fade.setToValue(1);
- fade.setCycleCount(1);
- fade.setDuration(Duration.seconds(1));
- fade.play();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement