diff --git a/src/main/java/fucoin/AbstractNode.java b/src/main/java/fucoin/AbstractNode.java index 7b7f943c10982101fddc28c673a24319fbc02d19..5b582932131d088bc1f52e379cb6662d30fe7f4d 100644 --- a/src/main/java/fucoin/AbstractNode.java +++ b/src/main/java/fucoin/AbstractNode.java @@ -181,10 +181,40 @@ public abstract class AbstractNode extends UntypedActor implements Serializable * @return Array[snapshot folder name, path to snapshot include filename] */ private String[] getSnapshotDirAndFilename(String name, LocalDateTime time) { - String folder = time.getYear() + "-" + time.getMonthValue() + "-" + time.getDayOfMonth() + " " + - time.getHour() + "." + time.getMinute() + "." + time.getSecond(); + String folder = getFolderName(time); return new String[]{folder, "snapshots/" + folder + "/" + name + ".json"}; } + + private String getFolderName(LocalDateTime time) { + String result = ""; + + String year = String.valueOf(time.getYear()); + String month = String.valueOf(time.getMonthValue()); + if(month.length()==1) { + month = "0" + month; + } + String day = String.valueOf(time.getDayOfMonth()); + if(day.length()==1) { + day = "0" + day; + } + String hour = String.valueOf(time.getHour()); + if(hour.length()==1) { + hour = "0" + day; + } + String minute = String.valueOf(time.getMinute()); + if(minute.length()==1) { + minute = "0" + minute; + } + String second = String.valueOf(time.getSecond()); + if(second.length()==1) { + second = "0" + second; + } + + result = year + "-" + month + "-" + day + "_" + + hour + "-" + minute + "-" + second; + + return result; + } private Statistics statistics = new Statistics(); diff --git a/src/main/java/fucoin/gui/WalletGuiControlImpl.java b/src/main/java/fucoin/gui/WalletGuiControlImpl.java index 7ceecb14f99b1a6f4095a8c71ae9911ba1970e18..fac84c0e4ebfe6672564b52c7413da50cabca3af 100644 --- a/src/main/java/fucoin/gui/WalletGuiControlImpl.java +++ b/src/main/java/fucoin/gui/WalletGuiControlImpl.java @@ -12,6 +12,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Enumeration; import java.util.Set; +import java.text.NumberFormat; public class WalletGuiControlImpl implements WalletGuiControl { @@ -27,7 +28,7 @@ public class WalletGuiControlImpl implements WalletGuiControl { private JLabel lblSendTo = new JLabel("Send to:"); private JComboBox<String> txtSendTo = new JComboBox<>(); private JLabel lblSendAmount = new JLabel("Amount:"); - private JTextField txtSendAmount = new JTextField(""); + private JTextField txtSendAmount = new JFormattedTextField(NumberFormat.getNumberInstance()); private JButton btnSend = new JButton("Send"); private JButton btnSearch = new JButton("Search"); private JButton btnStore = new JButton("Store"); @@ -146,8 +147,13 @@ public class WalletGuiControlImpl implements WalletGuiControl { window.setVisible(true); btnSend.addActionListener(e -> { - wallet.send(txtSendTo.getSelectedItem().toString(), - Integer.parseInt(txtSendAmount.getText())); + String sendAmount = txtSendAmount.getText(); + if(sendAmount.trim().equalsIgnoreCase("")) { + JOptionPane.showMessageDialog(new JFrame("Warning"), "You need to type a number of coins to send."); + } else { + wallet.send(txtSendTo.getSelectedItem().toString(), + Integer.parseInt(sendAmount)); + } }); btnStore.addActionListener(e -> {