Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.application.Application;
- import javafx.geometry.Insets;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.AnchorPane;
- import javafx.scene.layout.GridPane;
- import javafx.stage.Stage;
- public class Microwave extends Application {
- public static void main(String[] args) throws Exception {
- launch(args);
- }
- @Override
- public void start(Stage stage) throws Exception {
- // creating label
- Label label = new Label("Place Food Here");
- AnchorPane anchor_pane = new AnchorPane(label);
- AnchorPane.setTopAnchor(label, 70.0);
- // creating textfield
- TextField text_field = new TextField("Time to be displayed here");
- text_field.setMinWidth(250.0);
- AnchorPane.setLeftAnchor(text_field, 85.0);
- anchor_pane.getChildren().add(text_field);
- // creating buttons on gridpane
- GridPane grid_pane = new GridPane();
- // Add buttons to the panel 1 to 9
- int count = 1;
- for (int row = 0; row < 3; row++) {
- for (int col = 0; col < 3; col++) {
- Button btn = buttonContent(String.valueOf(count));
- btn.setOnMouseClicked(e -> {
- checkTextField(text_field);
- text_field.setText(text_field.getText() + btn.getText());
- });
- grid_pane.add(btn, col, row);
- count++;
- }
- }
- // 0 button
- Button btn0 = buttonContent(String.valueOf(0));
- btn0.setOnMouseClicked(e -> {
- checkTextField(text_field);
- text_field.setText(text_field.getText() + btn0.getText());
- });
- grid_pane.add(btn0, 0, 3);
- // start button
- grid_pane.add(buttonContent("Start"), 1, 3);
- // stop button
- grid_pane.add(buttonContent("Stop"), 2, 3);
- grid_pane.setStyle("-fx-border-color:rgba(255,0,0,1);");
- grid_pane.setHgap(4);
- grid_pane.setVgap(4);
- grid_pane.setPadding(new Insets(10, 9, 10, 13));
- AnchorPane.setTopAnchor(grid_pane, 25.0);
- AnchorPane.setLeftAnchor(grid_pane, 85.0);
- anchor_pane.getChildren().add(grid_pane);
- Scene scene = new Scene(anchor_pane, 318, 159);
- stage.setTitle("Microwave Oven");
- stage.setScene(scene);
- stage.show();
- }
- private static Button buttonContent(String text) {
- Button b = new Button(text);
- b.setMinWidth(67);
- return b;
- }
- private static void checkTextField(TextField tx) {
- if (tx.getText().equals("Time to be displayed here")) {
- tx.setText("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement