diff --git a/src/main/java/fucoin/Main.java b/src/main/java/fucoin/Main.java index 0a37e3aedd7bf7d54f7a2382f9cc949059851421..4cdd54c3efbda61988d113411f1e1dad62a02859 100644 --- a/src/main/java/fucoin/Main.java +++ b/src/main/java/fucoin/Main.java @@ -11,6 +11,8 @@ import fucoin.supervisor.SuperVisorImpl; import fucoin.wallet.WalletImpl; import java.io.File; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; @@ -26,6 +28,13 @@ public class Main { private static List<ActorRef> cActiveActors = new ArrayList<>(); static { + String hostname = "127.0.0.1"; + try { + // Fetch IP address to enable network connection + hostname = InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException e) { + e.printStackTrace(); + } //Load configuration from current directory or from resources directory of jar File file = new File("application.conf"); Config config = ConfigFactory.parseFile(file); @@ -37,7 +46,7 @@ public class Main { } //Init System Actor System - cSystem = ActorSystem.create("Core", config); + cSystem = ActorSystem.create("Core", ConfigFactory.parseString("akka.remote.netty.tcp.hostname=" + hostname).withFallback(config)); cSuperVisorActor = cSystem.actorOf(SuperVisorImpl.props(), "SuperVisorImpl"); System.out.print("Supervisor address: "); System.out.println(cSuperVisorActor.path().toStringWithAddress(cSystem.provider().getDefaultAddress())); diff --git a/src/main/java/fucoin/MainRemote.java b/src/main/java/fucoin/MainRemote.java index 3d9006266376dfd81896c03d3dcc104c7bef31a8..02d8e9fa061a448a44e18296c1c79ece2f6e9487 100644 --- a/src/main/java/fucoin/MainRemote.java +++ b/src/main/java/fucoin/MainRemote.java @@ -6,7 +6,6 @@ import java.util.concurrent.TimeUnit; import akka.actor.ActorRef; import akka.actor.ActorSelection; import akka.actor.ActorSystem; -import akka.actor.Address; import akka.util.Timeout; import com.typesafe.config.Config; @@ -19,6 +18,9 @@ import javax.swing.*; public class MainRemote { public static ActorRef remoteSuperVisorActor; + private static JTextField walletNameField = new JTextField(5); + private static JTextField pathField = new JTextField(5); + public static void main(String[] args) throws InterruptedException { //Load configuration from current directory or from resources directory of jar @@ -34,14 +36,22 @@ public class MainRemote { //Init System Actor System ActorSystem system = ActorSystem.create("Remote", config); + JPanel dialogPanel = createDialogPanel(); Timeout timeout = new Timeout(5, TimeUnit.SECONDS); ActorRef preknownNeighbour = null; + String walletName = null; + String path = null; + while (preknownNeighbour == null) { - // get an address from a node which should be our preknown neighbour - String path = JOptionPane.showInputDialog(null, "Enter a neighbour node address: "); + int result = JOptionPane.showConfirmDialog(null, dialogPanel, "Connect to wallet network", JOptionPane.OK_CANCEL_OPTION); + + if (result == JOptionPane.OK_OPTION) { + walletName = walletNameField.getText(); + path = pathField.getText(); + } // terminate if user clicked abort if (path == null) { @@ -59,7 +69,17 @@ public class MainRemote { } // spawn wallet - system.actorOf(WalletImpl.props(preknownNeighbour, "Remote1"), "Remote1"); + system.actorOf(WalletImpl.props(preknownNeighbour, walletName), walletName); + + } + private static JPanel createDialogPanel() { + JPanel dialogPanel = new JPanel(); + dialogPanel.setLayout(new BoxLayout(dialogPanel, BoxLayout.PAGE_AXIS)); + dialogPanel.add(new JLabel("Pick your wallet name: ")); + dialogPanel.add(walletNameField); + dialogPanel.add(new JLabel("Enter a neighbour node address: ")); + dialogPanel.add(pathField); + return dialogPanel; } } diff --git a/src/main/java/fucoin/gui/WalletGuiControlImpl.java b/src/main/java/fucoin/gui/WalletGuiControlImpl.java index 518ee8094f1e1727875c09c3ee44097da8440cf4..dbc86516cfc8dbdbbc6e75f83996a02d8c6bcc0c 100644 --- a/src/main/java/fucoin/gui/WalletGuiControlImpl.java +++ b/src/main/java/fucoin/gui/WalletGuiControlImpl.java @@ -17,7 +17,7 @@ public class WalletGuiControlImpl implements WalletGuiControl { private JLabel lblMyAddress = new JLabel("My Address:"); private JTextField txtMyAddress = new JTextField("<MyAddress>"); private JLabel lblEmpty = new JLabel(""); - private JLabel lblMyAmount = new JLabel("My FUCs"); + private JLabel lblMyAmount = new JLabel("My FUCs:"); private JTextField txtMyAmount = new JTextField("<MyFUCs>"); private JPanel centerPanel = new JPanel(); private JLabel lblSendTo = new JLabel("Send to:"); @@ -37,14 +37,20 @@ public class WalletGuiControlImpl implements WalletGuiControl { window.setSize(400, 600); window.setLayout(new GridLayout(3, 1)); - topPanel.setLayout(new GridLayout(2, 3)); + topPanel.setLayout(new GridLayout(2, 1)); // Row 1 - topPanel.add(lblMyAddress); - topPanel.add(txtMyAddress); - topPanel.add(lblEmpty); + JPanel row1 = new JPanel(); + row1.setLayout(new BoxLayout(row1, BoxLayout.PAGE_AXIS)); + row1.add(lblMyAddress); + row1.add(txtMyAddress); + topPanel.add(row1); // Row 2 - topPanel.add(lblMyAmount); - topPanel.add(txtMyAmount); + JPanel row2 = new JPanel(); + row2.setLayout(new GridLayout(1, 3)); + row2.add(lblMyAmount); + row2.add(txtMyAmount); + row2.add(lblEmpty); + topPanel.add(row2); window.add(topPanel); //<hr> centerPanel.setLayout(new GridLayout(4, 1));