SHARE
TWEET

Untitled

a guest Jan 17th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.function.DoubleToLongFunction;
  2.  
  3. import javafx.application.Application;
  4. import javafx.collections.ObservableList;
  5. import javafx.event.ActionEvent;
  6. import javafx.geometry.Insets;
  7. import javafx.geometry.Pos;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.Alert;
  10. import javafx.scene.control.Alert.AlertType;
  11. import javafx.scene.control.Button;
  12. import javafx.scene.control.ComboBox;
  13. import javafx.scene.control.Label;
  14. import javafx.scene.control.TextField;
  15. import javafx.scene.layout.BorderPane;
  16. import javafx.scene.layout.FlowPane;
  17. import javafx.scene.layout.GridPane;
  18. import javafx.stage.Stage;
  19.  
  20. public class Digitron extends Application{
  21.     private Label l1 = new Label("Prvi broj");
  22.     private Label l2 = new Label("drugi broj");
  23.     private Label l3 = new Label("operacija");
  24.     private Label l4 = new Label("rezultaj");
  25.     private Label rez = new Label("");
  26.     private TextField b1 = new TextField();
  27.     private TextField b2 = new TextField();
  28.     private Button racunaj = new Button("izracunaj");
  29.     private Button ocisti = new Button("ocisti");
  30.     private ComboBox<String> operacija = new ComboBox<>();
  31.     @Override
  32.     public void start(Stage primaryStage) throws Exception {
  33.        
  34.         l1.setPadding(new Insets(15));
  35.         l2.setPadding(new Insets(15));
  36.         l3.setPadding(new Insets(15));
  37.         l4.setPadding(new Insets(15));
  38.         rez.setPadding(new Insets(15));
  39.         racunaj.setPadding(new Insets(5));
  40.         ObservableList<String> lista = operacija.getItems();
  41.         lista.add("+");
  42.         lista.add("-");
  43.         lista.add("*");
  44.         lista.add("/");
  45.         operacija.getSelectionModel().select(0);
  46.         GridPane matrica = new GridPane();
  47.         matrica.add(l1, 0, 0);
  48.         matrica.add(b1, 1, 0);
  49.         matrica.add(l2, 0, 1);
  50.         matrica.add(b2, 1, 1);
  51.         matrica.add(l3, 0, 2);
  52.         matrica.add(operacija, 1, 2);
  53.         matrica.add(l4, 0, 3);
  54.         matrica.add(rez, 1, 3);
  55.         FlowPane dole = new FlowPane();
  56.         dole.getChildren().add(racunaj);
  57.         dole.getChildren().add(ocisti);
  58.         racunaj.setOnAction(this::racunaj);
  59.         ocisti.setOnAction(this::reset);
  60.         BorderPane kontejner = new BorderPane();
  61.         kontejner.setCenter(matrica);
  62.         kontejner.setBottom(dole);
  63.         Scene scena = new Scene(kontejner,300,300);
  64.         primaryStage.setScene(scena);
  65.         primaryStage.show();
  66.        
  67.     }
  68.  
  69.     public void racunaj(ActionEvent e) {
  70.         double br1 = Double.parseDouble(b1.getText());
  71.         double br2 = Double.parseDouble(b2.getText());
  72.         int op = operacija.getSelectionModel().getSelectedIndex();
  73.         double rez1 = 0;
  74.         if(op==4 && br2==0) {
  75.             new Alert(AlertType.INFORMATION,"deljenje sa 0").showAndWait();
  76.             return;
  77.         }
  78.         switch (op) {
  79.         case 0:
  80.             rez1 = br1+br2;
  81.             break;
  82.         case 1:
  83.             rez1 = br1-br2;
  84.             break;
  85.         case 2:
  86.             rez1= br1*br2;
  87.             break;
  88.         case 3:
  89.             rez1 = br1/br2;
  90.         }
  91.         rez.setText(rez1+"");
  92.     }
  93.     public void reset(ActionEvent e) {
  94.         b1.setText("");
  95.         b2.setText("");
  96.         rez.setText("");
  97.     }
  98.    
  99.     public static void main(String[] args) {
  100.         launch();
  101.        
  102.     }
  103.  
  104. }
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