0% found this document useful (0 votes)
25 views9 pages

Lab8c 8c

Lab Program

Uploaded by

ranganadh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

Lab8c 8c

Lab Program

Uploaded by

ranganadh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

// Displaying an Image (Lab8b)

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class ImageViewExample extends Application {
public void start(Stage stage) throws IOException {
//creating the image object
InputStream stream = new
FileInputStream("D:\images\[Link]");
Image image = new Image(stream);
//Creating the image view
ImageView imageView = new ImageView();
//Setting image to the image view
[Link](image);
//Setting the image view parameters
[Link](10);
[Link](10);
[Link](575);
[Link](true);
//Setting the Scene object
Group root = new Group(imageView);
Scene scene = new Scene(root, 595, 370);
[Link]("Displaying Image");
[Link](scene);
[Link]();
}
public static void main(String args[]) {
launch(args);
}
}
// Prg on Simple Calculator using JavaFX (Lab 8C)
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class Main extends Application {


private TextField num1Field;
private TextField num2Field;
private Label resultLabel;

public static void main(String[] args) {


launch(args);
}

@Override
public void start(Stage primaryStage) {
[Link]("Basic Calculator");

GridPane grid = new GridPane();


[Link](10);
[Link](10);
[Link](new Insets(10, 10, 10, 10));

num1Field = new TextField();


[Link]("Enter first number");
[Link](num1Field, 0, 0);
num2Field = new TextField();
[Link]("Enter second
number");
[Link](num2Field, 0, 1);

resultLabel = new Label("Result: ");


[Link](resultLabel, 0, 2);

Button addButton = new Button("Add");


[Link](e ->
performOperation('+'));
[Link](addButton, 1, 0);

Button subtractButton = new Button("Subtract");


[Link](e ->
performOperation('-'));
[Link](subtractButton, 2, 0);

Button multiplyButton = new Button("Multiply");


[Link](e ->
performOperation('*'));
[Link](multiplyButton, 1, 1);

Button divideButton = new Button("Divide");


[Link](e ->
performOperation('/'));
[Link](divideButton, 2, 1);

[Link]().addAll(num1Field, num2Field,
resultLabel, addButton, subtractButton, multiplyButton,
divideButton);

Scene scene = new Scene(grid, 300, 200);


[Link](scene);
[Link]();
}

private void performOperation(char operator) {


String num1Text = [Link]();
String num2Text = [Link]();

if (isValidNumber(num1Text) &&
isValidNumber(num2Text)) {
double num1 = [Link](num1Text);
double num2 = [Link](num2Text);
double result = 0.0;

switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
} else {
[Link]("Result: Error
(Division by zero)");
return;
}
break;
default:
break;
}

[Link]("Result: " + result);


} else {
[Link]("Result: Invalid Input");
}
}

private boolean isValidNumber(String text) {


return [Link]("-?\\d*\\.?\\d+");
}
}

You might also like