Lab8c 8c
Lab8c 8c
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
public class ImageViewExample extends Application {
public void start(Stage stage) throws IOException {
//creating the image object
InputStream stream = new
FileInputStream("D:\images\elephant.jpg");
Image image = new Image(stream);
//Creating the image view
ImageView imageView = new ImageView();
//Setting image to the image view
imageView.setImage(image);
//Setting the image view parameters
imageView.setX(10);
imageView.setY(10);
imageView.setFitWidth(575);
imageView.setPreserveRatio(true);
//Setting the Scene object
Group root = new Group(imageView);
Scene scene = new Scene(root, 595, 370);
stage.setTitle("Displaying Image");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]) {
launch(args);
}
}
// Prg on Simple Calculator using JavaFX (Lab 8C)
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;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Basic Calculator");
grid.getChildren().addAll(num1Field, num2Field,
resultLabel, addButton, subtractButton, multiplyButton,
divideButton);
if (isValidNumber(num1Text) &&
isValidNumber(num2Text)) {
double num1 = Double.parseDouble(num1Text);
double num2 = Double.parseDouble(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 {
resultLabel.setText("Result: Error
(Division by zero)");
return;
}
break;
default:
break;
}