Advertisement
PadmaJS

finished javafx lab 9?

Nov 26th, 2022
2,765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 2.79 KB | None | 0 0
  1. import javafx.application.Application;
  2. import javafx.geometry.Insets;
  3. import javafx.scene.Scene;
  4. import javafx.scene.control.Button;
  5. import javafx.scene.control.Label;
  6. import javafx.scene.control.TextField;
  7. import javafx.scene.layout.AnchorPane;
  8. import javafx.scene.layout.GridPane;
  9. import javafx.stage.Stage;
  10.  
  11. public class Microwave extends Application {
  12.     public static void main(String[] args) throws Exception {
  13.         launch(args);
  14.     }
  15.  
  16.     @Override
  17.     public void start(Stage stage) throws Exception {
  18.         // creating label
  19.         Label label = new Label("Place Food Here");
  20.         AnchorPane anchor_pane = new AnchorPane(label);
  21.         AnchorPane.setTopAnchor(label, 70.0);
  22.  
  23.         // creating textfield
  24.         TextField text_field = new TextField("Time to be displayed here");
  25.         text_field.setMinWidth(250.0);
  26.         AnchorPane.setLeftAnchor(text_field, 85.0);
  27.         anchor_pane.getChildren().add(text_field);
  28.  
  29.         // creating buttons on gridpane
  30.         GridPane grid_pane = new GridPane();
  31.  
  32.         // Add buttons to the panel 1 to 9
  33.         int count = 1;
  34.         for (int row = 0; row < 3; row++) {
  35.             for (int col = 0; col < 3; col++) {
  36.                 Button btn = buttonContent(String.valueOf(count));
  37.                 btn.setOnMouseClicked(e -> {
  38.                     checkTextField(text_field);
  39.                     text_field.setText(text_field.getText() + btn.getText());
  40.                 });
  41.                 grid_pane.add(btn, col, row);
  42.                 count++;
  43.             }
  44.         }
  45.         // 0 button
  46.         Button btn0 = buttonContent(String.valueOf(0));
  47.         btn0.setOnMouseClicked(e -> {
  48.             checkTextField(text_field);
  49.             text_field.setText(text_field.getText() + btn0.getText());
  50.         });
  51.         grid_pane.add(btn0, 0, 3);
  52.  
  53.         // start button
  54.         grid_pane.add(buttonContent("Start"), 1, 3);
  55.  
  56.         // stop button
  57.         grid_pane.add(buttonContent("Stop"), 2, 3);
  58.  
  59.         grid_pane.setStyle("-fx-border-color:rgba(255,0,0,1);");
  60.         grid_pane.setHgap(4);
  61.         grid_pane.setVgap(4);
  62.         grid_pane.setPadding(new Insets(10, 9, 10, 13));
  63.         AnchorPane.setTopAnchor(grid_pane, 25.0);
  64.         AnchorPane.setLeftAnchor(grid_pane, 85.0);
  65.         anchor_pane.getChildren().add(grid_pane);
  66.  
  67.         Scene scene = new Scene(anchor_pane, 318, 159);
  68.         stage.setTitle("Microwave Oven");
  69.         stage.setScene(scene);
  70.         stage.show();
  71.     }
  72.  
  73.     private static Button buttonContent(String text) {
  74.         Button b = new Button(text);
  75.         b.setMinWidth(67);
  76.  
  77.         return b;
  78.     }
  79.  
  80.     private static void checkTextField(TextField tx) {
  81.         if (tx.getText().equals("Time to be displayed here")) {
  82.             tx.setText("");
  83.         }
  84.     }
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement