From 749024734f57ca7ffcf285252091a628483537b5 Mon Sep 17 00:00:00 2001 From: lov3b Date: Wed, 22 Jun 2022 11:28:36 +0200 Subject: [PATCH] Test --- src/schack/Schack.java | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/schack/Schack.java b/src/schack/Schack.java index 3b72b7e..34b2d6d 100644 --- a/src/schack/Schack.java +++ b/src/schack/Schack.java @@ -2,6 +2,8 @@ package schack; import java.awt.event.ActionEvent; import java.io.IOException; +import java.net.Inet4Address; +import java.net.NetworkInterface; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; @@ -37,8 +39,11 @@ public class Schack { // Create menu final JMenuBar menuBar = new JMenuBar(); final JMenu gameMenu = new JMenu("Game"); + final JMenu connectMenu = new JMenu("Connect"); final JMenuItem askForRemi = new JMenuItem("Ask for remi"); final JMenuItem surrender = new JMenuItem("Surrender"); + final JMenuItem showIP = new JMenuItem("Show IP"); + final JMenuItem connectToOpponent = new JMenuItem("Connect to opponent"); askForRemi.addActionListener((ActionEvent ae) -> { String whosWantingRemi = board.isWhitesTurn() ? "Vit" : "Svart"; @@ -63,16 +68,33 @@ public class Schack { } } }); + showIP.addActionListener((ActionEvent ae) -> { + try { + + String ip = Inet4Address.getLocalHost().toString(); + JOptionPane.showMessageDialog(null, "IP: " + ip); + + } catch (Exception e) { + } + }); + connectToOpponent.addActionListener((ActionEvent ae) -> { + String opponentIP = JOptionPane.showInputDialog(null, "What's your opponents IP?"); + System.out.println("opponents ip: "+opponentIP); + + + }); // Add the menu stuff frame.setJMenuBar(menuBar); menuBar.add(gameMenu); + menuBar.add(connectMenu); gameMenu.add(askForRemi); gameMenu.add(surrender); + connectMenu.add(showIP); + connectMenu.add(connectToOpponent); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); - } public static void main(String[] args) throws IOException {