diff --git a/src/main/java/pl/mikorosa/dziecoin/Main.java b/src/main/java/pl/mikorosa/dziecoin/Main.java
index 7b59f35..7ef2b1f 100644
--- a/src/main/java/pl/mikorosa/dziecoin/Main.java
+++ b/src/main/java/pl/mikorosa/dziecoin/Main.java
@@ -1,5 +1,7 @@
package pl.mikorosa.dziecoin;
+import pl.mikorosa.dziecoin.gui.MainFrame;
+
import java.util.ArrayList;
import java.util.List;
@@ -56,5 +58,8 @@ public class Main {
System.out.println("Wallet 1: " + blockchain.getAddressBalance(w1.getAddress()));
System.out.println("Wallet 2: " + blockchain.getAddressBalance(w2.getAddress()));
System.out.println("Wallet 3: " + blockchain.getAddressBalance(w3.getAddress()));
+
+ MainFrame mf = new MainFrame();
+ mf.setVisible(true);
}
}
\ No newline at end of file
diff --git a/src/main/java/pl/mikorosa/dziecoin/gui/MainFrame.form b/src/main/java/pl/mikorosa/dziecoin/gui/MainFrame.form
new file mode 100644
index 0000000..62f1860
--- /dev/null
+++ b/src/main/java/pl/mikorosa/dziecoin/gui/MainFrame.form
@@ -0,0 +1,326 @@
+
+
diff --git a/src/main/java/pl/mikorosa/dziecoin/gui/MainFrame.java b/src/main/java/pl/mikorosa/dziecoin/gui/MainFrame.java
new file mode 100644
index 0000000..51b80c7
--- /dev/null
+++ b/src/main/java/pl/mikorosa/dziecoin/gui/MainFrame.java
@@ -0,0 +1,174 @@
+package pl.mikorosa.dziecoin.gui;
+
+import pl.mikorosa.dziecoin.*;
+
+import javax.swing.*;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.IOException;
+import java.util.*;
+import java.util.List;
+
+public class MainFrame extends JFrame {
+
+ Blockchain bc;
+ String addr;
+
+ public JPanel panel;
+ private JTabbedPane menu;
+ private JLabel walletAddress;
+ private JLabel balance;
+ private JLabel height;
+ private JTree blockchainTree;
+ private JTree nftTree;
+ private JButton createMintNFTButton;
+ private JTextField amountToSend;
+ private JButton sendSubmit;
+ private JComboBox sendRecipient;
+ private JLabel sendAmount;
+ private JTree mineBlockTree;
+ private JButton mineBlockButton;
+ private JButton payForTuitionButton;
+ private JButton payForAdvanceButton;
+ private JButton validateChainButton;
+ private JTextField recipient;
+ private JButton exportButton;
+ private JCheckBox exportBlockDataCheckBox;
+ private JCheckBox exportTransactionDataCheckBox;
+ private JCheckBox exportNFTDataCheckBox;
+ private JButton clearButton;
+ private DefaultMutableTreeNode rootBlocks;
+ private DefaultMutableTreeNode rootNFT;
+ private DefaultMutableTreeNode rootMineBlock;
+ private List transactions;
+ private List nfts;
+ private int howMuchLeftToSpend;
+
+ public MainFrame() {
+ super("DzieCoin");
+ transactions = new ArrayList<>();
+ nfts = new ArrayList<>();
+
+ mineBlockButton.setEnabled(false);
+ clearButton.setEnabled(false);
+
+ this.bc = Main.blockchain;
+ addr = this.bc.getBlocks().get(0).getTransactions().get(0).getRecipient();
+ howMuchLeftToSpend = this.bc.getAddressBalance(addr);
+
+ this.walletAddress.setText(addr);
+
+ this.setContentPane(this.panel);
+ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ this.setPreferredSize(new Dimension(640, 360));
+ this.pack();
+
+ this.balance.setText(Integer.toString(this.bc.getAddressBalance(addr)));
+ this.height.setText(Integer.toString(this.bc.getBlocks().size()));
+
+ JTreeBlocks();
+ JTreeNFTs();
+
+ rootMineBlock = new DefaultMutableTreeNode("Objects to add to block");
+ rootMineBlock.removeAllChildren();
+ DefaultTreeModel model = new DefaultTreeModel(rootMineBlock);
+ mineBlockTree.setModel(model);
+
+ sendSubmit.addActionListener(e -> {
+
+ });
+
+ validateChainButton.addActionListener(e -> {
+
+ });
+
+ payForTuitionButton.addActionListener(e -> {
+
+ });
+ payForAdvanceButton.addActionListener(e -> {
+
+ });
+
+ mineBlockButton.addActionListener(e -> {
+
+ });
+
+ clearButton.addActionListener(e -> {
+
+ });
+
+ exportButton.addActionListener(e -> {
+
+ });
+
+ createMintNFTButton.addActionListener(e -> {
+
+ });
+ }
+
+ private void JTreeBlocks() {
+ rootBlocks = new DefaultMutableTreeNode("Blockchain");
+ for (Block block : this.bc.getBlocks()) {
+ DefaultMutableTreeNode b = new DefaultMutableTreeNode(block.getHeight() + " (" + block.getHash() + ")");
+ rootBlocks.add(b);
+ int i = 1;
+ for (Transaction transaction : block.getTransactions()) {
+ DefaultMutableTreeNode t = new DefaultMutableTreeNode("Transaction " + i++);
+ t.add(new DefaultMutableTreeNode("Sender: " + transaction.getSender()));
+ t.add(new DefaultMutableTreeNode("Recipient: " + transaction.getRecipient()));
+ t.add(new DefaultMutableTreeNode("Amount: " + transaction.getAmount()));
+ b.add(t);
+ }
+ };
+ DefaultTreeModel model = new DefaultTreeModel(rootBlocks);
+ blockchainTree.setModel(model);
+ }
+
+ private void JTreeNFTs() {
+ rootNFT = new DefaultMutableTreeNode("NFTs");
+ for (Block block : this.bc.getBlocks()) {
+ for (NFT nft : block.getNFTs()) {
+ DefaultMutableTreeNode n = new DefaultMutableTreeNode(nft.getData());
+ n.add(new DefaultMutableTreeNode("Contract: " + nft.getContract()));
+ n.add(new DefaultMutableTreeNode("Owner: " + nft.getOwner()));
+ n.add(new DefaultMutableTreeNode("In block: " + block.getHeight()));
+ rootNFT.add(n);
+ }
+ };
+ DefaultTreeModel model = new DefaultTreeModel(rootNFT);
+ nftTree.setModel(model);
+ }
+
+ public void onNewBlockUpdate() {
+ Block newestBlock = this.bc.getLatestBlock();
+
+ this.balance.setText(Integer.toString(this.bc.getAddressBalance(addr)));
+ this.height.setText(Integer.toString(this.bc.getBlocks().size()));
+
+ DefaultMutableTreeNode b = new DefaultMutableTreeNode(newestBlock.getHeight() + " (" + newestBlock.getHash() + ")");
+ rootBlocks.add(b);
+ int i = 1;
+ for (Transaction transaction : newestBlock.getTransactions()) {
+ DefaultMutableTreeNode t = new DefaultMutableTreeNode("Transaction " + i++);
+ t.add(new DefaultMutableTreeNode("Sender: " + transaction.getSender()));
+ t.add(new DefaultMutableTreeNode("Recipient: " + transaction.getRecipient()));
+ t.add(new DefaultMutableTreeNode("Amount: " + transaction.getAmount()));
+ b.add(t);
+ }
+ DefaultTreeModel model = new DefaultTreeModel(rootBlocks);
+ blockchainTree.setModel(model);
+
+ for (NFT nft : newestBlock.getNFTs()) {
+ DefaultMutableTreeNode n = new DefaultMutableTreeNode(nft.getData());
+ n.add(new DefaultMutableTreeNode("Contract: " + nft.getContract()));
+ n.add(new DefaultMutableTreeNode("Owner: " + nft.getOwner()));
+ n.add(new DefaultMutableTreeNode("In block: " + newestBlock.getHeight()));
+ rootNFT.add(n);
+ }
+ DefaultTreeModel model1 = new DefaultTreeModel(rootNFT);
+ nftTree.setModel(model1);
+ }
+}