Giter Site home page Giter Site logo

java-2d-drawing-app's Introduction

Java-2D-drawing-app

//please help debug this java code for meme

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.GridPane; import javafx.stage.Stage;

public class AdditionApp extends Application {

public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Addition App");

    GridPane grid = new GridPane();
    grid.setPadding(new Insets(10, 10, 10, 10));
    grid.setVgap(5);
    grid.setHgap(5);

    Label firstNumberLabel = new Label("First Number:");
    GridPane.setConstraints(firstNumberLabel, 0, 0);

    TextField firstNumberInput = new TextField();
    GridPane.setConstraints(firstNumberInput, 1, 0);

    Label operatorLabel = new Label("Operator:");
    GridPane.setConstraints(operatorLabel, 0, 1);

    TextField operatorInput = new TextField();
    GridPane.setConstraints(operatorInput, 1, 1);

    Label secondNumberLabel = new Label("Second Number:");
    GridPane.setConstraints(secondNumberLabel, 0, 2);

    TextField secondNumberInput = new TextField();
    GridPane.setConstraints(secondNumberInput, 1, 2);

    Button addButton = new Button("Add");
    GridPane.setConstraints(addButton, 1, 3);

    Label resultLabel = new Label("Result:");
    GridPane.setConstraints(resultLabel, 0, 4);

    Label resultOutput = new Label();
    GridPane.setConstraints(resultOutput, 1, 4);

    addButton.setOnAction(e -> {
        try {
            double num1 = Double.parseDouble(firstNumberInput.getText());
            double num2 = Double.parseDouble(secondNumberInput.getText());
            String operator = operatorInput.getText();

            if (operator.equals("+")) {
                double result = num1 + num2;
                resultOutput.setText(Double.toString(result));
            } else {
                resultOutput.setText("Invalid operator!");
            }
        } catch (NumberFormatException ex) {
            resultOutput.setText("Invalid input!");
        }
    });

    grid.getChildren().addAll(firstNumberLabel, firstNumberInput, operatorLabel, operatorInput,
            secondNumberLabel, secondNumberInput, addButton, resultLabel, resultOutput);

    Scene scene = new Scene(grid, 300, 200);
    primaryStage.setScene(scene);
    primaryStage.show();
}

}

java-2d-drawing-app's People

Contributors

danjumakolo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.