-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
88 lines (88 loc) · 2.09 KB
/
Calculator.java
File metadata and controls
88 lines (88 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.scene.control.*;
import javafx.scene.input.*;
import javafx.event.*;
public class Calculator extends Application
{
public static void main(String args[]) throws Exception
{
launch(args);
}
public void start(Stage stage)
{
stage.setTitle("Calculator");
FlowPane f=new FlowPane();
Scene s=new Scene(f, 400, 400);
Label l1=new Label("X: ");
TextField t1=new TextField();
Label l2=new Label("Answer: ");
Label l3=new Label(" ");
ToggleGroup tg=new ToggleGroup();
RadioButton rb1=new RadioButton("X+X");
RadioButton rb2=new RadioButton("Cube of X");
RadioButton rb3=new RadioButton("Square of X");
RadioButton rb4=new RadioButton("1/X");
rb1.setToggleGroup(tg);
rb2.setToggleGroup(tg);
rb3.setToggleGroup(tg);
rb4.setToggleGroup(tg);
rb1.setOnAction(new EventHandler <ActionEvent> ()
{
public void handle(ActionEvent ae)
{
if(rb1.isSelected())
{
int a=Integer.parseInt(t1.getText());
l3.setText(" "+(a+a));
}
}
});
rb2.setOnAction(new EventHandler <ActionEvent> ()
{
public void handle(ActionEvent ae)
{
if(rb2.isSelected())
{
int a=Integer.parseInt(t1.getText());
l3.setText(" "+(a*a*a));
}
}
});
rb3.setOnAction(new EventHandler <ActionEvent> ()
{
public void handle(ActionEvent ae)
{
if(rb3.isSelected())
{
int a=Integer.parseInt(t1.getText());
l3.setText(" "+(a*a));
}
}
});
rb4.setOnAction(new EventHandler <ActionEvent> ()
{
public void handle(ActionEvent ae)
{
if(rb4.isSelected())
{
int a=Integer.parseInt(t1.getText());
l3.setText(" "+(1/a));
}
}
});
f.getChildren().add(l1);
f.getChildren().add(t1);
f.getChildren().add(l2);
f.getChildren().add(l3);
f.getChildren().add(rb1);
f.getChildren().add(rb2);
f.getChildren().add(rb3);
f.getChildren().add(rb4);
stage.setScene(s);
stage.show();
}
}