Esempio n. 1
0
  // App class constructor
  public App() {
    // Print out a test message to the console to confirm running program
    // Uses java.lang library System.out to do priting to console
    System.out.println("App constructor success!");

    // Delare and instantiate objects
    MainWindow myWindow = new MainWindow();
    InputBox inBox = new InputBox(myWindow);
    OutputBox outBox = new OutputBox(myWindow);

    // Render the main window
    myWindow.show();

    // Declare and initialise variables to default values
    double baseDimension = -1;
    double heightDimension = -1;
    double area = -1;

    // Get input form the user
    baseDimension = inBox.getDouble("Please enter the size of the base in mm: ");
    heightDimension = inBox.getDouble("Please enter the height in mm: ");

    // Debug output
    System.out.println("The base entered was: " + baseDimension);
    System.out.println("The height entered was: " + heightDimension);

    // Create the Triangle object
    Triangle myTriangle = new Triangle();
    // Set values from user
    myTriangle.setBaseDimension(baseDimension);
    myTriangle.setHeightDimension(heightDimension);
    // Calculate the area
    myTriangle.computeArea();
    area = myTriangle.getArea();

    // Show the feedback dialog
    outBox.show();

    // Return the calculated area
    outBox.println("The triangle area was computed to be: " + area);
  }