-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangePriceController.java
60 lines (53 loc) · 2.13 KB
/
ChangePriceController.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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.JOptionPane;
public class ChangePriceController {
private ChangePriceScreen screen;
public ChangePriceController() {
screen = new ChangePriceScreen();
screen.setVisible(true);
screen.setResizable(false);
screen.setSize(817,438);
screen.pack();
screen.setLocationRelativeTo(null);
screen.getSearchbtn().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
searchBtnAction();
}
});
screen.getSubmitbtn().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
submitBtnAction();
}
});
}
private void searchBtnAction(){
String symbol = screen.getSearchtxt().getText();
screen.getSymbolTxt().setText(symbol);
if(!StockDB.isExist(symbol)){
screen.getNameTxt().setText("This Stock Item is Unavailable");
screen.getNameTxt().setForeground(new java.awt.Color(255,204,204));
}else{
screen.getNameTxt().setText(StockDB.getStockItem(symbol).getSecurityName());
screen.getOldPriceTxt().setText(""+StockDB.getStockItem(symbol).getPrice());
screen.getNewPricetxt().setEnabled(true);
screen.getSubmitbtn().setEnabled(true);
}
}
private void submitBtnAction(){
try{
// get new price
double newPrice=Double.parseDouble(screen.getNewPricetxt().getText());
//set price of Map
StockDB.setPrice(screen.getSymbolTxt().getText(), newPrice);
Offer change =new Offer("By Server", screen.getSymbolTxt().getText(), new Date(), newPrice); //add new change as an offer
OfferDB.addOffer(change); //add the new change to offer list
screen.dispose();
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "Price entered is invalid"); //if error value given as input
}
}
}