-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElectronicStoreApp.java
More file actions
67 lines (61 loc) · 2.14 KB
/
ElectronicStoreApp.java
File metadata and controls
67 lines (61 loc) · 2.14 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
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
//CONTROLLER
public class ElectronicStoreApp extends Application {
//create the attributes for the model and the view
ElectronicStore model;
ElectronicStoreView view;
public ElectronicStoreApp() {
//instantiate the attributes
model = ElectronicStore.createStore();
view = new ElectronicStoreView();
}
public void start(Stage primaryStage) {
//create the pane and add the view
Pane aPane = new Pane();
aPane.getChildren().add(view);
//update the view
view.update(model);
//set the stage
primaryStage.setTitle("Electronic Store-"+ model.getName());
primaryStage.setResizable(false);
primaryStage.setScene(new Scene(aPane));
primaryStage.show();
//Create the event handlers for the buttons and mouse events
view.getAddButton().setOnAction(actionEvent -> handleAdd());
view.getRemoveButton().setOnAction(actionEvent -> handleRemove());
view.getCompleteSaleButton().setOnAction(actionEvent -> handleSale());
view.getResetButton().setOnAction(actionEvent -> handleReset());
//mouse events
view.getStockList().setOnMouseReleased(e -> view.update(model));
view.getCartList().setOnMouseReleased(e -> view.update(model));
}
public static void main(String[] args) {
launch(args);
}
//methods to handle events
public void handleAdd(){
Product cart = view.getStockList().getSelectionModel().getSelectedItem();
if(cart != null){
model.CartList(cart);
view.update(model);
}
}
public void handleRemove(){
String cart = view.getCartList().getSelectionModel().getSelectedItem();
if(cart != null){
model.RemoveItem(cart);
view.update(model);
}
}
public void handleSale(){
model.sellProducts();
view.update(model);
}
public void handleReset(){
model = ElectronicStore.createStore();
view.update(model);
}
}