Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package divisible.by.pkg3;
- import javafx.scene.control.*;
- import javafx.application.Application;
- import javafx.geometry.HPos;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.layout.GridPane;
- import javafx.stage.Stage;
- /**
- *
- * @author Monty
- */
- public class DivisibleBy3 extends Application {
- private TextField tfNum = new TextField();
- private TextField tfOut = new TextField();
- private Label lblOut = new Label();
- private Button btCheck = new Button("Check");
- private String end;
- @Override
- public void start(Stage stage1) {
- GridPane gp = new GridPane();
- gp.setHgap(5);
- gp.setVgap(5);
- gp.add(new Label("Enter int:"),0,0);
- gp.add(tfNum,1,0);
- gp.add(btCheck,0,1);
- gp.add(lblOut,1,1);
- btCheck.setOnAction(e -> checkInt());
- Scene scene = new Scene(gp, 300,100);
- stage1.setTitle("Divisible By 3");
- stage1.setScene(scene);
- stage1.show();
- }
- private void checkInt(){
- int num = Integer.parseInt(tfNum.getText());
- if(num%3 == 0){
- end = "Number is divisible by 3.";
- } else {
- end = "Number is not divisible by 3.";
- // gp.add(new Label(end),1,1);
- }
- lblOut.setText(end);
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment