-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConverterinterface.java
195 lines (176 loc) · 7.27 KB
/
Converterinterface.java
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class Converterinterface extends Application{
Stage mainWindow;
Scene mainscene,scene1;
String qString="",aString="";
TextField field_output;
TextField field_input;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage arg0) throws Exception {
mainWindow=arg0;
mainWindow.setTitle("POSTFIXTOPREFIXANDVICEVERSA");
//main window
Label Question=new Label("Choose any option:");
ToggleGroup selection=new ToggleGroup();
RadioButton intopre=new RadioButton("Infix to prefix conversion");
RadioButton intopost=new RadioButton("Infix to postfix conversion");
RadioButton pretopost=new RadioButton("prefix to postfix conversion");
RadioButton pretoin=new RadioButton("Prefix to Infix conversion");
RadioButton posttopre=new RadioButton("Postfix to prefix conversion");
RadioButton posttoin=new RadioButton("Postfix to Infix conversion");
Button ok=new Button("Ok");
Button exit=new Button("Exit");
ok.setOnAction(e->{
gotonxtscene();
});
exit.setOnAction(e->{
exit();
});
exit.getStyleClass().add("button-red");
intopre.setToggleGroup(selection);
intopost.setToggleGroup(selection);
posttopre.setToggleGroup(selection);
pretopost.setToggleGroup(selection);
posttoin.setToggleGroup(selection);
pretoin.setToggleGroup(selection);
GridPane main_gp=new GridPane();
main_gp.setVgap(10);
main_gp.setHgap(10);
GridPane.setConstraints(Question,0,0);
GridPane.setConstraints(intopre,0,1);
GridPane.setConstraints(intopost,0,2);
GridPane.setConstraints(pretoin,0,3);
GridPane.setConstraints(pretopost,0,4);
GridPane.setConstraints(posttoin,0,5);
GridPane.setConstraints(posttopre,0,6);
GridPane.setConstraints(ok,0,7);
GridPane.setConstraints(exit,0,9);
main_gp.setAlignment(Pos.CENTER);
selection.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
if (newValue ==intopre) {
qString="INFIX";
aString="PREFIX";
} else if (newValue == intopost) {
qString="INFIX";
aString="POSTFIX";
} else if (newValue == pretoin) {
qString="PREFIX";
aString="INFIX";
} else if (newValue == pretopost) {
qString="PREFIX";
aString="POSTFIX";
} else if (newValue == posttoin) {
qString="POSTFIX";
aString="INFIX";
} else if (newValue == posttopre) {
qString="POSTFIX";
aString="PREFIX";
}
});
main_gp.getChildren().addAll(Question,intopre,intopost,pretoin,pretopost,posttoin,posttopre,ok,exit);
mainscene=new Scene(main_gp,350,350);
mainscene.getStylesheets().add(getClass().getResource("mainwindow.css").toExternalForm());
mainWindow.setScene(mainscene);
mainWindow.show();
}
void gotonxtscene(){
if((qString=="") & (aString=="")){
Alertbox.display("Error","Please select one option!");
mainWindow.setScene(mainscene);
}else{
//scene-1
Label label_input=new Label("Enter "+qString+" expression: ");
Label label_output=new Label("Converted "+aString+" expresssion: ");
field_input=new TextField();
field_input.setText("");
field_output=new TextField("");
field_output.setEditable(false);
field_input.setPromptText("input");
Button back=new Button("Back");
Button calculate=new Button("Calculate");
Button clearall=new Button("ClearAll");
clearall.setOnAction(e->clearall());
calculate.getStyleClass().add("button-green");
calculate.setOnAction(e->result());
back.setOnAction(e->back());
GridPane gp=new GridPane();
gp.setVgap(10);
gp.setHgap(10);
GridPane.setConstraints(label_input,0,0);
GridPane.setConstraints(label_output,0,1);
GridPane.setConstraints(field_input,1,0);
GridPane.setConstraints(field_output,1,1);
GridPane.setConstraints(back,0,4);
GridPane.setConstraints(calculate,0,2);
GridPane.setConstraints(clearall,1,2);
gp.setAlignment(Pos.CENTER);
gp.getChildren().addAll(label_input,label_output,field_input,field_output,back,calculate,clearall);
scene1=new Scene(gp,400,400);
scene1.getStylesheets().add(getClass().getResource("Converterinterfacestyle.css").toExternalForm());
mainWindow.setScene(scene1);
}
}
void back(){
mainWindow.setScene(mainscene);
}
void exit(){
mainWindow.close();
}
void clearall(){
field_input.setText("");
field_output.setText("");
}
void result(){
if(field_input.getText().equals("")){
Alertbox.display("Suggestion","Input is empty please enter expression");
mainWindow.setScene(scene1);
}
else{
String value="";
field_output.setText("");
Outputproviders O=new Outputproviders();
if(qString=="INFIX" & aString=="PREFIX"){
String alone=field_input.getText();
alone=alone.replace(" ","");
value=O.infixToPrefix(alone);
}
else if(qString=="INFIX" & aString=="POSTFIX"){
String alone=field_input.getText();
alone=alone.replace(" ","");
value=O.infixToPostfix(alone);
}
else if(qString=="PREFIX" & aString=="POSTFIX"){
String alone=field_input.getText();
alone=alone.replace(" ","");
value=O.prefixToPostfix(alone);
}
else if(qString=="PREFIX" & aString=="INFIX"){
String alone=field_input.getText();
alone=alone.replace(" ","");
value=O.prefixToInfix(alone);
}
else if(qString=="POSTFIX" & aString=="PREFIX"){
String alone=field_input.getText();
alone=alone.replace(" ","");
value=O.postfixToPrefix(alone);
}else if(qString=="POSTFIX" & aString=="INFIX"){
String alone=field_input.getText();
alone=alone.replace(" ","");
value=O.postfixToInfix(alone);
}
field_output.setText(value);
}
}
}