-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHelloApplication.java
More file actions
207 lines (173 loc) · 7.11 KB
/
HelloApplication.java
File metadata and controls
207 lines (173 loc) · 7.11 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
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
196
197
198
199
200
201
202
203
204
205
206
207
package com.example.cs2450projectshoppingcart;
import javafx.application.Application;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class HelloApplication extends Application {
private Button add;
private Button subtract;
private Label subtotalL;
private Label quantity;
private Label total;
private int quantityCounter;
private double subtotalEyelinerD;
private double totalTOTAL;
private TextField couponTF;
@Override
public void start(Stage stage) throws IOException {
// shopping cart: would need some sort of set on mouse action to lead to this page
// clicking the add to bag button for a product should lead to it being added to this page
// top cart
Image i = new Image("file:////Users/yintinglo/IdeaProjects/CS2450ProjectShoppingCart/src/main/java/com/example/cs2450projectshoppingcart/CS2450pic7.png");
ImageView iv = new ImageView(i);
//iv.setPreserveRatio(false);
HBox topHBOX = new HBox(iv);
topHBOX.setAlignment(Pos.CENTER);
HBox.setHgrow(iv, javafx.scene.layout.Priority.ALWAYS);
topHBOX.setPrefHeight(300);
topHBOX.setPrefWidth(1300);
// product picture vbox
Image productImage = new Image("file:////Users/yintinglo/IdeaProjects/CS2450ProjectShoppingCart/src/main/java/com/example/cs2450projectshoppingcart/CS2450pic8.png");
ImageView pv = new ImageView(productImage);
pv.setFitHeight(200);
pv.setFitWidth(200);
VBox productVBOX = new VBox(50, pv);
// product text
Label productL = new Label("COLOUR PLAY GEL EYELINER");
Label descriptionL = new Label("IN STOCK");
Label wishlistL = new Label("SAVE TO WISHLIST");
// label vbox
VBox descriptionVBOX = new VBox(50, productL, descriptionL, wishlistL);
// price & price vbox
Label priceL = new Label("$3.50");
VBox priceVBOX = new VBox(50, priceL);
// subtotal & vbox
subtotalL = new Label("3.50");
subtotalEyelinerD = 3.50;
VBox subtotalVBOX = new VBox(50, subtotalL);
// buttons: add & subtract, label: quantity
quantity = new Label("1");
quantityCounter = 1;
add = new Button("+");
add.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
subtotalEyelinerD = subtotalEyelinerD + 3.50;
quantityCounter++;
updateSubtotalAndQuantity();
}
});
subtract = new Button("-");
subtract.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
if (subtotalEyelinerD > 0) {
subtotalEyelinerD = subtotalEyelinerD - 3.50;
quantityCounter--;
updateSubtotalAndQuantity();
} else {
subtotalL.setText("$0.00");
quantityCounter = 0;
}
}
});
// button hbox
HBox buttonHBOX = new HBox(20, add, quantity, subtract);
// gridpane: product, label, price, quantity
GridPane productGP = new GridPane();
productGP.setHgap(50);
productGP.add(productVBOX, 0, 0);
productGP.add(descriptionVBOX, 1, 0);
productGP.add(priceVBOX, 6, 0);
productGP.add(buttonHBOX, 9, 0);
productGP.add(subtotalVBOX, 12, 0);
// product hbox: gridpane
HBox productHBOX = new HBox(50, productGP);
productHBOX.setPadding(new Insets(60));
// cart total
Label points = new Label("COMPLETE YOUR ORDER TO EARN POINTS");
Label cartTOTAL = new Label("CART SUBTOTAL");
total = new Label();
totalTOTAL = subtotalEyelinerD; // can add any other products later?
total.setText("$" + totalTOTAL);
// coupon textfield & hbox
couponTF = new TextField();
couponTF.setPromptText("COUPON CODE");
Button couponB = new Button("APPLY");
couponB.setOnAction(actionEvent -> {
String couponCODE = couponTF.getText();
if (couponCODE.equals("BEYONCE")) {
totalTOTAL = totalTOTAL / 2;
total.setText("$" + totalTOTAL);
couponTF.setPromptText("COUPON APPLIED");
}
});
// continue & checkout
Button continueB = new Button("CONTINUE SHOPPING");
Button checkoutB = new Button("SECURELY CHECKOUT NOW");
checkoutB.setOnAction(e -> checkoutStage());
// hbox & vbox containers: cart total & coupon
HBox totalHBOX = new HBox(50, points, cartTOTAL, total);
HBox couponHBOX = new HBox(50, couponTF, couponB);
HBox contcheckHBOX = new HBox(50, continueB, checkoutB);
VBox totalCouponVBOX = new VBox(50, totalHBOX, couponHBOX, contcheckHBOX);
BorderPane bp = new BorderPane();
bp.setTop(topHBOX);
bp.setCenter(productHBOX); // this holds the gridpane
bp.setBottom(totalCouponVBOX);
// container work
ScrollPane sp = new ScrollPane();
sp.setFitToWidth(true);
sp.setFitToHeight(true);
sp.setContent(bp);
Scene scene = new Scene(sp, 1300, 500);
stage.setTitle("CS2450 Project: Shopping Cart");
stage.setScene(scene);
stage.show();
}
private void checkoutStage() {
Stage popupStage = new Stage();
popupStage.initModality(Modality.APPLICATION_MODAL);
popupStage.setTitle("SECURE CHECKOUT");
// Content for the popup stage
Button closeButton = new Button("Close Popup");
closeButton.setOnAction(e -> popupStage.close());
VBox popupLayout = new VBox(10);
popupLayout.getChildren().addAll(closeButton);
// popup scene & stage
Scene popupScene = new Scene(popupLayout, 200, 100);
popupStage.setScene(popupScene);
popupStage.showAndWait();
}
private void updateSubtotalAndQuantity() {
String subtotalEyelinerS = String.format("%.2f", subtotalEyelinerD);
String quantityS = String.valueOf(quantityCounter);
subtotalL.setText("$" + subtotalEyelinerS);
quantity.setText(quantityS);
total.setText("$" + subtotalEyelinerS);
totalTOTAL = subtotalEyelinerD;
}
public static void main (String[] args) {
launch();
}
}